prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def test_init(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def test_save(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def test_load(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def test_dumps(): doc = Document() assert doc.dumps() def test_core_props(): <|fim_middle|> <|fim▁end|>
doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6])
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def <|fim_middle|>(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def test_save(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def test_load(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def test_dumps(): doc = Document() assert doc.dumps() def test_core_props(): doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6]) <|fim▁end|>
test_init
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def test_init(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def <|fim_middle|>(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def test_load(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def test_dumps(): doc = Document() assert doc.dumps() def test_core_props(): doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6]) <|fim▁end|>
test_save
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def test_init(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def test_save(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def <|fim_middle|>(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def test_dumps(): doc = Document() assert doc.dumps() def test_core_props(): doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6]) <|fim▁end|>
test_load
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def test_init(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def test_save(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def test_load(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def <|fim_middle|>(): doc = Document() assert doc.dumps() def test_core_props(): doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6]) <|fim▁end|>
test_dumps
<|file_name|>test_docx.py<|end_file_name|><|fim▁begin|>from datetime import datetime from zipfile import ZipFile from io import BytesIO from lxml import etree from docxgen import * from docxgen import nsmap from . import check_tag def test_init(): doc = Document() check_tag(doc.doc, ['document', 'body']) check_tag(doc.body, ['body']) def test_save(): doc = Document() tmp = BytesIO() doc.save(tmp) with ZipFile(tmp) as zippy: assert(zippy.testzip() is None) assert(set(zippy.namelist()) == set([ '[Content_Types].xml', '_rels/.rels', 'docProps/app.xml', 'word/fontTable.xml', 'word/numbering.xml', 'word/settings.xml', 'word/styles.xml', 'word/stylesWithEffects.xml', 'word/webSettings.xml', 'word/theme/theme1.xml', 'word/_rels/document.xml.rels', 'word/document.xml', 'docProps/core.xml' ])) zxf = zippy.open('word/document.xml') root = etree.parse(zxf) check_tag(root, 'document body'.split()) def test_load(): # assume save works d = Document() tmp = BytesIO() d.save(tmp) doc = Document.load(tmp) check_tag(doc.doc, 'document body'.split()) check_tag(doc.body, 'body'.split()) def test_dumps(): doc = Document() assert doc.dumps() def <|fim_middle|>(): doc = Document() attrs = dict(lastModifiedBy='Joe Smith', keywords=['egg', 'spam'], title='Testing Doc', subject='A boilerplate document', creator='Jill Smith', description='Core properties test.', created=datetime.now() ) doc.update(attrs) core = doc.get_core_props() for key in ('title', 'subject', 'creator', 'description'): attr = core.find('.//dc:%s' % key, namespaces=nsmap) assert attr is not None assert attr.text == attrs[key] attr = core.find('.//cp:keywords', namespaces=nsmap) assert attr is not None assert attr.text == ','.join(attrs['keywords']) attr = core.find('.//dcterms:created', namespaces=nsmap) assert attr is not None assert datetime.strptime(attr.text, '%Y-%m-%dT%H:%M:%SZ') == datetime(*attrs['created'].timetuple()[:6]) <|fim▁end|>
test_core_props
<|file_name|>account.py<|end_file_name|><|fim▁begin|>from django.contrib.auth.models import AnonymousUser from core.models import Identity from api.v2.serializers.post import AccountSerializer from api.v2.views.base import AdminAuthViewSet class AccountViewSet(AdminAuthViewSet): """ API endpoint that allows providers to be viewed or edited. """ lookup_fields = ("id", "uuid") queryset = Identity.objects.all() serializer_class = AccountSerializer http_method_names = ['post', 'head', 'options', 'trace'] def get_queryset(self): """<|fim▁hole|> if (type(user) == AnonymousUser): return Identity.objects.none() identities = user.current_identities() return identities<|fim▁end|>
Filter providers by current user """ user = self.request.user
<|file_name|>account.py<|end_file_name|><|fim▁begin|>from django.contrib.auth.models import AnonymousUser from core.models import Identity from api.v2.serializers.post import AccountSerializer from api.v2.views.base import AdminAuthViewSet class AccountViewSet(AdminAuthViewSet): <|fim_middle|> <|fim▁end|>
""" API endpoint that allows providers to be viewed or edited. """ lookup_fields = ("id", "uuid") queryset = Identity.objects.all() serializer_class = AccountSerializer http_method_names = ['post', 'head', 'options', 'trace'] def get_queryset(self): """ Filter providers by current user """ user = self.request.user if (type(user) == AnonymousUser): return Identity.objects.none() identities = user.current_identities() return identities
<|file_name|>account.py<|end_file_name|><|fim▁begin|>from django.contrib.auth.models import AnonymousUser from core.models import Identity from api.v2.serializers.post import AccountSerializer from api.v2.views.base import AdminAuthViewSet class AccountViewSet(AdminAuthViewSet): """ API endpoint that allows providers to be viewed or edited. """ lookup_fields = ("id", "uuid") queryset = Identity.objects.all() serializer_class = AccountSerializer http_method_names = ['post', 'head', 'options', 'trace'] def get_queryset(self): <|fim_middle|> <|fim▁end|>
""" Filter providers by current user """ user = self.request.user if (type(user) == AnonymousUser): return Identity.objects.none() identities = user.current_identities() return identities
<|file_name|>account.py<|end_file_name|><|fim▁begin|>from django.contrib.auth.models import AnonymousUser from core.models import Identity from api.v2.serializers.post import AccountSerializer from api.v2.views.base import AdminAuthViewSet class AccountViewSet(AdminAuthViewSet): """ API endpoint that allows providers to be viewed or edited. """ lookup_fields = ("id", "uuid") queryset = Identity.objects.all() serializer_class = AccountSerializer http_method_names = ['post', 'head', 'options', 'trace'] def get_queryset(self): """ Filter providers by current user """ user = self.request.user if (type(user) == AnonymousUser): <|fim_middle|> identities = user.current_identities() return identities <|fim▁end|>
return Identity.objects.none()
<|file_name|>account.py<|end_file_name|><|fim▁begin|>from django.contrib.auth.models import AnonymousUser from core.models import Identity from api.v2.serializers.post import AccountSerializer from api.v2.views.base import AdminAuthViewSet class AccountViewSet(AdminAuthViewSet): """ API endpoint that allows providers to be viewed or edited. """ lookup_fields = ("id", "uuid") queryset = Identity.objects.all() serializer_class = AccountSerializer http_method_names = ['post', 'head', 'options', 'trace'] def <|fim_middle|>(self): """ Filter providers by current user """ user = self.request.user if (type(user) == AnonymousUser): return Identity.objects.none() identities = user.current_identities() return identities <|fim▁end|>
get_queryset
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """<|fim▁hole|> Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop()<|fim▁end|>
Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order.
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): <|fim_middle|> def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
""" Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1]
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): <|fim_middle|> class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
@wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): <|fim_middle|> return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
if not isinstance(other, Additional): return NotImplemented return f(self, other)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): <|fim_middle|> class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
""" Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): <|fim_middle|> def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
self._requirements = set(requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): <|fim_middle|> def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
self._requirements.update((requirement,) + requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): <|fim_middle|> @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
self._requirements.difference_update((requirement,) + requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): <|fim_middle|> @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
requirements = self._requirements | other._requirements return Additional(*requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): <|fim_middle|> @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): <|fim_middle|> @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
requirements = self._requirements - other._requirements return Additional(*requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): <|fim_middle|> @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
if len(other._requirements) > 0: self.remove(*other._requirements) return self
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): <|fim_middle|> @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return self._requirements == other._requirements
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): <|fim_middle|> def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return not self == other
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): <|fim_middle|> def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return iter(self._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): <|fim_middle|> def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return requirement in self._requirements
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): <|fim_middle|> def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return self.is_added(requirement)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): <|fim_middle|> def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return len(self._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): <|fim_middle|> __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return len(self) != 0
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): <|fim_middle|> class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return "Additional({!r})".format(self._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): <|fim_middle|> <|fim▁end|>
""" Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop()
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): <|fim_middle|> def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
""" Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional))
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): <|fim_middle|> @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
""" Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) )
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): <|fim_middle|> @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
""" Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): <|fim_middle|> <|fim▁end|>
""" Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop()
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: <|fim_middle|> return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return None
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): <|fim_middle|> return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
return NotImplemented
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: <|fim_middle|> return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
self._requirements.add(*other._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: <|fim_middle|> return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
self.remove(*other._requirements)
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: <|fim_middle|> _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
additional = current + additional
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: <|fim_middle|> @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) )
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def <|fim_middle|>(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
current_additions
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def <|fim_middle|>(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
_isinstance
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def <|fim_middle|>(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
check
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def <|fim_middle|>(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__init__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def <|fim_middle|>(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
add
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def <|fim_middle|>(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
remove
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def <|fim_middle|>(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__add__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def <|fim_middle|>(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__iadd__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def <|fim_middle|>(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__sub__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def <|fim_middle|>(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__isub__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def <|fim_middle|>(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__eq__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def <|fim_middle|>(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__ne__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def <|fim_middle|>(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__iter__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def <|fim_middle|>(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
is_added
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def <|fim_middle|>(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__contains__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def <|fim_middle|>(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__len__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def <|fim_middle|>(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__bool__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def <|fim_middle|>(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
__repr__
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def <|fim_middle|>(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
push
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def <|fim_middle|>(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
pop
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def <|fim_middle|>(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def additional(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
current
<|file_name|>additional.py<|end_file_name|><|fim▁begin|>from contextlib import contextmanager from functools import wraps from werkzeug.local import LocalProxy, LocalStack _additional_ctx_stack = LocalStack() __all__ = ("current_additions", "Additional", "AdditionalManager") @LocalProxy def current_additions(): """ Proxy to the currently added requirements """ rv = _additional_ctx_stack.top if rv is None: return None return rv[1] def _isinstance(f): @wraps(f) def check(self, other): if not isinstance(other, Additional): return NotImplemented return f(self, other) return check class Additional(object): """ Container object that allows to run extra requirements on checks. These additional requirements will be run at most once per check and will occur in no guarenteed order. Requirements can be added by passing them into the constructor or by calling the ``add`` method. They can be removed from this object by calling the ``remove`` method. To check if a requirement has been added to the current conext, you may call ``is_added`` or use ``in``:: some_req in additional additional.is_added(some)req) Additional objects can be iterated and length checked:: additional = Additional(some_req) assert len(additional) == 1 assert list(additional) == [some_req] Additional objects may be combined and compared to each other with the following operators: ``+`` creates a new additional object by combining two others, the new additional supplies all requirements that both parents did. ``+=`` similar to ``+`` except it is an inplace update. ``-`` creates a new additional instance by removing any requirements from the first instance that are contained in the second instance. ``-=`` similar to ``-`` except it is an inplace update. ``==`` compares two additional instances and returns true if both have the same added requirements. ``!=`` similar to ``!=`` except returns true if both have different requirements contained in them. """ def __init__(self, *requirements): self._requirements = set(requirements) def add(self, requirement, *requirements): self._requirements.update((requirement,) + requirements) def remove(self, requirement, *requirements): self._requirements.difference_update((requirement,) + requirements) @_isinstance def __add__(self, other): requirements = self._requirements | other._requirements return Additional(*requirements) @_isinstance def __iadd__(self, other): if len(other._requirements) > 0: self._requirements.add(*other._requirements) return self @_isinstance def __sub__(self, other): requirements = self._requirements - other._requirements return Additional(*requirements) @_isinstance def __isub__(self, other): if len(other._requirements) > 0: self.remove(*other._requirements) return self @_isinstance def __eq__(self, other): return self._requirements == other._requirements @_isinstance def __ne__(self, other): return not self == other def __iter__(self): return iter(self._requirements) def is_added(self, requirement): return requirement in self._requirements def __contains__(self, requirement): return self.is_added(requirement) def __len__(self): return len(self._requirements) def __bool__(self): return len(self) != 0 __nonzero__ = __bool__ def __repr__(self): return "Additional({!r})".format(self._requirements) class AdditionalManager(object): """ Used to manage the process of adding and removing additional requirements to be run. This class shouldn't be used directly, instead use ``allows.additional`` to access these controls. """ def push(self, additional, use_parent=False): """ Binds an additional to the current context, optionally use the current additionals in conjunction with this additional If ``use_parent`` is true, a new additional is created from the parent and child additionals rather than manipulating either directly. """ current = self.current if use_parent and current: additional = current + additional _additional_ctx_stack.push((self, additional)) def pop(self): """ Pops the latest additional context. If the additional context was pushed by a different additional manager, a ``RuntimeError`` is raised. """ rv = _additional_ctx_stack.pop() if rv is None or rv[0] is not self: raise RuntimeError( "popped wrong additional context ({} instead of {})".format(rv, self) ) @property def current(self): """ Returns the current additional context if set otherwise None """ try: return _additional_ctx_stack.top[1] except TypeError: return None @contextmanager def <|fim_middle|>(self, additional, use_parent=False): """ Allows temporarily pushing an additional context, yields the new context into the following block. """ self.push(additional, use_parent) yield self.current self.pop() <|fim▁end|>
additional
<|file_name|>partner.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ############################################################################## # # Author: OpenDrive Ltda # Copyright (c) 2013 Opendrive Ltda # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsibility of assessing all potential # consequences resulting from its eventual inadequacies and bugs # End users who are looking for a ready-to-use solution with commercial # guarantees and support are strongly advised to contract a Free Software # Service Company # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## from openerp.osv import osv, fields from openerp.tools.translate import _ class Partner(osv.osv): _inherit = 'res.partner' _columns = { 'legal_representative': fields.char( 'Legal Representative',<|fim▁hole|><|fim▁end|>
), }
<|file_name|>partner.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ############################################################################## # # Author: OpenDrive Ltda # Copyright (c) 2013 Opendrive Ltda # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsibility of assessing all potential # consequences resulting from its eventual inadequacies and bugs # End users who are looking for a ready-to-use solution with commercial # guarantees and support are strongly advised to contract a Free Software # Service Company # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## from openerp.osv import osv, fields from openerp.tools.translate import _ class Partner(osv.osv): <|fim_middle|> <|fim▁end|>
_inherit = 'res.partner' _columns = { 'legal_representative': fields.char( 'Legal Representative', ), }
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio.<|fim▁hole|>## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def test_union_dicts(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def test_split_ranges(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000")) TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE)<|fim▁end|>
## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ##
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): <|fim_middle|> TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE) <|fim▁end|>
"""Test list set operations.""" def test_union_dicts(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def test_split_ranges(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000"))
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def test_union_dicts(self): <|fim_middle|> def test_split_ranges(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000")) TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE) <|fim▁end|>
"""bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1}))
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def test_union_dicts(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def test_split_ranges(self): <|fim_middle|> TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE) <|fim▁end|>
"""bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000"))
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def test_union_dicts(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def test_split_ranges(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000")) TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": <|fim_middle|> <|fim▁end|>
run_test_suite(TEST_SUITE)
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def <|fim_middle|>(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def test_split_ranges(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000")) TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE) <|fim▁end|>
test_union_dicts
<|file_name|>bibrank_tag_based_indexer_unit_tests.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- ## This file is part of Invenio. ## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN. ## ## Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Unit tests for the ranking engine.""" __revision__ = "$Id$" from invenio.importutils import lazy_import from invenio.testutils import make_test_suite, run_test_suite, InvenioTestCase bibrank_tag_based_indexer = lazy_import('invenio.bibrank_tag_based_indexer') split_ranges = lazy_import('invenio.bibrank:split_ranges') class TestListSetOperations(InvenioTestCase): """Test list set operations.""" def test_union_dicts(self): """bibrank tag based indexer - union dicts""" self.assertEqual({1: 5, 2: 6, 3: 9, 4: 10, 10: 1}, bibrank_tag_based_indexer.union_dicts({1: 5, 2: 6, 3: 9}, {3:9, 4:10, 10: 1})) def <|fim_middle|>(self): """bibrank tag based indexer - split ranges""" self.assertEqual([[0, 500], [600, 1000]], split_ranges("0-500,600-1000")) TEST_SUITE = make_test_suite(TestListSetOperations,) if __name__ == "__main__": run_test_suite(TEST_SUITE) <|fim▁end|>
test_split_ranges
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args:<|fim▁hole|> task(*webhook_args)<|fim▁end|>
if settings.CELERY_ENABLED: task.delay(*webhook_args) else:
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): <|fim_middle|> def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): <|fim_middle|> def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args))
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): <|fim_middle|> <|fim▁end|>
for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args)
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: <|fim_middle|> if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
return None
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: <|fim_middle|> model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
return None
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: <|fim_middle|> elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
task = tasks.create_webhook extra_args = []
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: <|fim_middle|> elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
task = tasks.change_webhook extra_args = [instance]
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: <|fim_middle|> by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
task = tasks.delete_webhook extra_args = []
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: <|fim_middle|> else: task(*webhook_args) <|fim▁end|>
task.delay(*webhook_args)
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: <|fim_middle|> <|fim▁end|>
task(*webhook_args)
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def <|fim_middle|>(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
_get_project_webhooks
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def <|fim_middle|>(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def _execute_task(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
on_new_history_entry
<|file_name|>signal_handlers.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright (C) 2014-present Taiga Agile LLC # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from django.db import connection from django.conf import settings from django.utils import timezone from taiga.projects.history import services as history_service from taiga.projects.history.choices import HistoryType from . import tasks def _get_project_webhooks(project): webhooks = [] for webhook in project.webhooks.all(): webhooks.append({ "id": webhook.pk, "url": webhook.url, "key": webhook.key, }) return webhooks def on_new_history_entry(sender, instance, created, **kwargs): if not settings.WEBHOOKS_ENABLED: return None if instance.is_hidden: return None model = history_service.get_model_from_key(instance.key) pk = history_service.get_pk_from_key(instance.key) try: obj = model.objects.get(pk=pk) except model.DoesNotExist: # Catch simultaneous DELETE request return None webhooks = _get_project_webhooks(obj.project) if instance.type == HistoryType.create: task = tasks.create_webhook extra_args = [] elif instance.type == HistoryType.change: task = tasks.change_webhook extra_args = [instance] elif instance.type == HistoryType.delete: task = tasks.delete_webhook extra_args = [] by = instance.owner date = timezone.now() webhooks_args = [] for webhook in webhooks: args = [webhook["id"], webhook["url"], webhook["key"], by, date, obj] + extra_args webhooks_args.append(args) connection.on_commit(lambda: _execute_task(task, webhooks_args)) def <|fim_middle|>(task, webhooks_args): for webhook_args in webhooks_args: if settings.CELERY_ENABLED: task.delay(*webhook_args) else: task(*webhook_args) <|fim▁end|>
_execute_task
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self):<|fim▁hole|> error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new)<|fim▁end|>
chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None:
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): <|fim_middle|> <|fim▁end|>
""" This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new)
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. <|fim_middle|> ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state)
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): <|fim_middle|> ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
"""Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): <|fim_middle|> def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): <|fim_middle|> def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): <|fim_middle|> <|fim▁end|>
self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new)
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): <|fim_middle|> ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: <|fim_middle|> obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname)
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: <|fim_middle|> return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
error('Invalid filter chosen! Try again!')
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: <|fim_middle|> if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
return False
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def __set_pure_state__(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: <|fim_middle|> return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
return True
<|file_name|>user_defined.py<|end_file_name|><|fim▁begin|># Author: Prabhu Ramachandran <prabhu [at] aero . iitb . ac . in> # Copyright (c) 2008, Enthought, Inc. # License: BSD Style. # Enthought library imports. from tvtk.tools.tvtk_doc import TVTKFilterChooser, TVTK_FILTERS # Local imports. from mayavi.filters.filter_base import FilterBase from mayavi.core.common import handle_children_state, error from mayavi.core.pipeline_info import PipelineInfo ################################################################################ # `UserDefined` class. ################################################################################ class UserDefined(FilterBase): """ This filter lets the user define their own filter dynamically/interactively. It is like `FilterBase` but allows a user to specify the class without writing any code. """ # The version of this class. Used for persistence. __version__ = 0 input_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) output_info = PipelineInfo(datasets=['any'], attribute_types=['any'], attributes=['any']) ###################################################################### # `object` interface. ###################################################################### def <|fim_middle|>(self, state): # Create and set the filter. children = [f for f in [self.filter] if f is not None] handle_children_state(children, [state.filter]) self.filter = children[0] self.update_pipeline() # Restore our state. super(UserDefined, self).__set_pure_state__(state) ###################################################################### # `UserDefined` interface. ###################################################################### def setup_filter(self): """Setup the filter if none has been set or check it if it already has been.""" obj = self.filter if not self._check_object(obj): if obj is not None: cname = obj.__class__.__name__ error('Invalid filter %s chosen! Try again!'%cname) obj = self._choose_filter() self.filter = obj ###################################################################### # Non-public interface. ###################################################################### def _choose_filter(self): chooser = TVTKFilterChooser() chooser.edit_traits(kind='livemodal') obj = chooser.object if obj is None: error('Invalid filter chosen! Try again!') return obj def _check_object(self, obj): if obj is None: return False if obj.__class__.__name__ in TVTK_FILTERS: return True return False def _filter_changed(self, old, new): self.name = 'UserDefined:%s'%new.__class__.__name__ super(UserDefined, self)._filter_changed(old, new) <|fim▁end|>
__set_pure_state__