Esempio n. 1
0
 def test_name(self):
     """
     The C{name} attribute of a L{NamedConstant} refers to the value passed
     for the C{name} parameter to C{_realize}.
     """
     name = NamedConstant()
     name._realize(self.container, "bar", None)
     self.assertEqual("bar", name.name)
Esempio n. 2
0
 def test_representation(self):
     """
     The string representation of an instance of L{NamedConstant} includes
     the container the instances belongs to as well as the instance's name.
     """
     name = NamedConstant()
     name._realize(self.container, "bar", None)
     self.assertEqual("<foo=bar>", repr(name))
Esempio n. 3
0
 def test_equality(self):
     """
     A L{NamedConstant} instance compares equal to itself.
     """
     name = NamedConstant()
     name._realize(self.container, "bar", None)
     self.assertTrue(name == name)
     self.assertFalse(name != name)
            def matchExpression(fieldName, matchString, matchType, matchFlags):
                # special case recordType field
                if fieldName == FieldName.recordType:
                    # change kind to record type
                    matchValue = vCardKindToRecordTypeMap.get(matchString.lower())
                    if matchValue is None:
                        matchValue = NamedConstant()
                        matchValue.description = u""

                    # change types and flags
                    matchFlags &= ~MatchFlags.caseInsensitive
                    matchType = MatchType.equals
                else:
                    matchValue = matchString.decode("utf-8")

                return MatchExpression(fieldName, matchValue, matchType, matchFlags)
Esempio n. 5
0
 def test_hash(self):
     """
     Because two different L{NamedConstant} instances do not compare as
     equal to each other, they also have different hashes to avoid
     collisions when added to a C{dict} or C{set}.
     """
     first = NamedConstant()
     first._realize(self.container, "bar", None)
     second = NamedConstant()
     second._realize(self.container, "bar", None)
     self.assertNotEqual(hash(first), hash(second))
Esempio n. 6
0
 def test_nonequality(self):
     """
     Two different L{NamedConstant} instances do not compare equal to each
     other.
     """
     first = NamedConstant()
     first._realize(self.container, "bar", None)
     second = NamedConstant()
     second._realize(self.container, "bar", None)
     self.assertFalse(first == second)
     self.assertTrue(first != second)
Esempio n. 7
0
class Environments(Names):
    """
    The environments that documentation can be published to.
    """
    PRODUCTION = NamedConstant()
    STAGING = NamedConstant()
Esempio n. 8
0
class BranchType(Names):
    master = NamedConstant()
    release = NamedConstant()
    maintenance = NamedConstant()
    development = NamedConstant()
Esempio n. 9
0
class ThreadWorkerState(Names):
    STOPPED = NamedConstant()
    RUNNING = NamedConstant()
Esempio n. 10
0
class UnknownConstant(Names):
    unknown = NamedConstant()
Esempio n. 11
0
class Input(Names):
    apple = NamedConstant()
Esempio n. 12
0
class DatasetBackend(Names):
    loopback = NamedConstant()
    zfs = NamedConstant()
    aws = NamedConstant()
    openstack = NamedConstant()
Esempio n. 13
0
class RecordType(Names):
    macOSXServerWiki = NamedConstant()
    macOSXServerWiki.description = u"Mac OS X Server Wiki"
Esempio n. 14
0
class STATE(Names):
    FOLLOWER = NamedConstant()
    CANDIDATE = NamedConstant()
    LEADER = NamedConstant()
Esempio n. 15
0
class LDAPMatchType(Names):
    """
    LDAP match types.

    For each constant defined, if there is an equivalent L{MatchType} constant,
    the attribute C{matchType} reference that constant.  It is otherwise unset.

    For each constant defined, the attribute C{queryString} will be a
    L{unicode} format string that, when formatted, is an LDAP query string
    (eg. C{(attribute=value)}).  The format string may reference the following
    names:

      - C{notOp} for the "not" operator, which may be C{u"!"} or C{u""}.
      - C{attribute} for the name of the LDAP attribute to match.
      - C{value} for the value to match against.

    @cvar any: Attribute has any value.
    @cvar equals: Attribute equals value.
    @cvar startsWith: Attribute starts with value.
    @cvar endsWith: Attribute ends with value.
    @cvar contains: Attribute contains value.
    @cvar lessThan: Attribute is less than value.
    @cvar greaterThan: Attribute is greater than value.
    @cvar lessThanOrEqualTo: Attribute is less than or equal to value.
    @cvar greaterThanOrEqualTo: Attribute is greater than or equal to value.
    """

    any = NamedConstant()
    any.queryString = u"({notOp}{attribute}=*)"

    equals = NamedConstant()
    equals.matchType = MatchType.equals
    equals.queryString = u"({notOp}{attribute}={value})"

    startsWith = NamedConstant()
    startsWith.matchType = MatchType.startsWith
    startsWith.queryString = u"({notOp}{attribute}={value}*)"

    endsWith = NamedConstant()
    endsWith.matchType = MatchType.endsWith
    endsWith.queryString = u"({notOp}{attribute}=*{value})"

    contains = NamedConstant()
    contains.matchType = MatchType.contains
    contains.queryString = u"({notOp}{attribute}=*{value}*)"

    lessThan = NamedConstant()
    lessThan.matchType = MatchType.lessThan
    lessThan.queryString = u"({notOp}{attribute}<{value})"

    greaterThan = NamedConstant()
    greaterThan.matchType = MatchType.greaterThan
    greaterThan.queryString = u"({notOp}{attribute}>{value})"

    lessThanOrEqualTo = NamedConstant()
    lessThanOrEqualTo.matchType = MatchType.lessThanOrEqualTo
    lessThanOrEqualTo.queryString = u"({notOp}{attribute}<={value})"

    greaterThanOrEqualTo = NamedConstant()
    greaterThanOrEqualTo.matchType = MatchType.greaterThanOrEqualTo
    greaterThanOrEqualTo.queryString = u"({notOp}{attribute}>={value})"

    @classmethod
    def fromMatchType(cls, matchType):
        """
        Look up an L{LDAPMatchType} from a L{MatchType}.

        @param matchType: A match type.
        @type matchType: L{MatchType}

        @return: The cooresponding LDAP match type.
        @rtype: L{LDAPMatchType}
        """
        if not hasattr(cls, "_matchTypeByMatchType"):
            cls._matchTypeByMatchType = dict(
                ((matchType.matchType, matchType)
                 for matchType in cls.iterconstants()
                 if hasattr(matchType, "matchType")))

        return cls._matchTypeByMatchType.get(matchType, None)
Esempio n. 16
0
class MoreNamedLetters(Names):
    """
    Some more letters, named.
    """
    digamma = NamedConstant()
    zeta = NamedConstant()
Esempio n. 17
0
class NamedLetters(Names):
    """
    Some letters, named.
    """
    alpha = NamedConstant()
    beta = NamedConstant()
Esempio n. 18
0
class WikiAccessLevel(Names):
    none = NamedConstant()
    read = NamedConstant()
    write = NamedConstant()
Esempio n. 19
0
class FieldName(Names):
    memberUIDs = NamedConstant()
    memberUIDs.description = u"member UIDs"
    memberUIDs.multiValue = True