def OR(self, *operands): """OR(test, ...) --> logical OR test""" return testclause.Equals(self, True).OR(*operands)
def eq(self, val): """eq(anything) --> equals test""" return testclause.Equals(self, val)
def AND(self, *operands): """AND(test, ...) --> logical AND test""" return testclause.Equals(self, True).AND(*operands)
class _PositionSpecifier(Specifier): """All property and element reference forms inherit from this class. Note that comparison and logic 'operator' methods are implemented on this class - these are only for use in constructing its-based references and shouldn't be used on app- and con-based references. Aem doesn't enforce this rule itself so as to minimise runtime overhead (the target application will raise an error if the user does something foolish). """ _kBeginning = base.packEnum(kAE.kAEBeginning) _kEnd = base.packEnum(kAE.kAEEnd) _kBefore = base.packEnum(kAE.kAEBefore) _kAfter = base.packEnum(kAE.kAEAfter) _kPrevious = base.packEnum(kAE.kAEPrevious) _kNext = base.packEnum(kAE.kAENext) def __init__(self, wantcode, container, key): self.AEM_want = wantcode Specifier.__init__(self, container, key) def __repr__(self): return '%r.%s(%r)' % (self._container, self._by, self._key) def __eq__(self, v): return Specifier.__eq__(self, v) and (self.AEM_want == v.AEM_want) def _packSelf(self, codecs): return base.packListAs(kAE.typeObjectSpecifier, [ (kAE.keyAEDesiredClass, base.packType(self.AEM_want)), (kAE.keyAEKeyForm, self._keyForm), (kAE.keyAEKeyData, self._packKey(codecs)), (kAE.keyAEContainer, self._container.AEM_packSelf(codecs)), ]) # Comparison tests; these should only be used on its-based references: def gt(self, val): """gt(anything) --> is greater than test""" return testclause.GreaterThan(self, val) def ge(self, val): """ge(anything) --> is greater than or equals test""" return testclause.GreaterOrEquals(self, val) def eq(self, val): """eq(anything) --> equals test""" return testclause.Equals(self, val) def ne(self, val): """ne(anything) --> does not equal test""" return testclause.NotEquals(self, val) def lt(self, val): """lt(anything) --> is less than test""" return testclause.LessThan(self, val) def le(self, val): """le(anything) --> is less than or equals test""" return testclause.LessOrEquals(self, val) def startswith(self, val): """startswith(anything) --> starts with test""" return testclause.StartsWith(self, val) def endswith(self, val): """endswith(anything) --> ends with test""" return testclause.EndsWith(self, val) def contains(self, val): """contains(anything) --> contains test""" return testclause.Contains(self, val) def isin(self, val): """isin(anything) --> isin test""" return testclause.IsIn(self, val) # Logic tests; these should only be used on its-based references: # Note: these three methods allow boolean tests to be written in shorthand form; # e.g. 'its.foo.AND(...)' will automatically expand to 'its.foo.eq(True).AND(...)' def AND(self, *operands): """AND(test, ...) --> logical AND test""" return testclause.Equals(self, True).AND(*operands) def OR(self, *operands): """OR(test, ...) --> logical OR test""" return testclause.Equals(self, True).OR(*operands) NOT = property(lambda self: testclause.Equals(self, True).NOT, doc="NOT --> logical NOT test") # Insertion references can be used on any kind of element reference, and also on property references where the property represents a one-to-one relationship, e.g. textedit.documents[1].text.end is valid: start = property( lambda self: InsertionSpecifier(self, self._kBeginning, 'start'), doc="start --> insertion location") end = property(lambda self: InsertionSpecifier(self, self._kEnd, 'end'), doc="end --> insertion location") before = property( lambda self: InsertionSpecifier(self, self._kBefore, 'before'), doc="before --> insertion location") after = property( lambda self: InsertionSpecifier(self, self._kAfter, 'after'), doc="after --> insertion location") # Property and element references can be used on any type of object reference: def property(self, propertycode): """property(propertycode) --> property""" return Property(kAE.cProperty, self, propertycode) def userproperty(self, name): """property(name) --> property""" return UserProperty(kAE.cProperty, self, name) def elements(self, elementcode): """elements(elementcode) --> all elements""" return AllElements(elementcode, self) # Relative position references are unlikely to work on one-to-one relationships - but what the hey, it simplifies the class structure a bit. def previous(self, elementcode): """previous(elementcode) --> element""" return ElementByRelativePosition(elementcode, self, self._kPrevious, 'previous') def next(self, elementcode): """next(elementcode) --> element""" return ElementByRelativePosition(elementcode, self, self._kNext, 'next')