[CalendarServer-changes] [11795] CalendarServer/trunk/twext

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 7 17:03:58 PDT 2013


Revision: 11795
          http://trac.calendarserver.org//changeset/11795
Author:   wsanchez at apple.com
Date:     2013-10-07 17:03:58 -0700 (Mon, 07 Oct 2013)
Log Message:
-----------
cosmetic/lint

Modified Paths:
--------------
    CalendarServer/trunk/twext/patches.py
    CalendarServer/trunk/twext/who/aggregate.py
    CalendarServer/trunk/twext/who/directory.py
    CalendarServer/trunk/twext/who/expression.py
    CalendarServer/trunk/twext/who/idirectory.py
    CalendarServer/trunk/twext/who/index.py
    CalendarServer/trunk/twext/who/util.py
    CalendarServer/trunk/twext/who/xml.py

Modified: CalendarServer/trunk/twext/patches.py
===================================================================
--- CalendarServer/trunk/twext/patches.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/patches.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -26,6 +26,8 @@
 from twisted.python.versions import Version
 from twisted.python.modules import getModule
 
+
+
 def _hasIPv6ClientSupport():
     """
     Does the loaded version of Twisted have IPv6 client support?
@@ -34,8 +36,9 @@
     if version > lastVersionWithoutIPv6Clients:
         return True
     elif version == lastVersionWithoutIPv6Clients:
-        # It could be a snapshot of trunk or a branch with this bug fixed. Don't
-        # load the module, though, as that would be a bunch of unnecessary work.
+        # It could be a snapshot of trunk or a branch with this bug fixed.
+        # Don't load the module, though, as that would be a bunch of
+        # unnecessary work.
         return "_resolveIPv6" in (getModule("twisted.internet.tcp")
                                   .filePath.getContent())
     else:
@@ -45,8 +48,8 @@
 
 def _addBackports():
     """
-    We currently require 2 backported bugfixes from a future release of Twisted,
-    for IPv6 support:
+    We currently require 2 backported bugfixes from a future release of
+    Twisted, for IPv6 support:
 
         - U{IPv6 client support <http://tm.tl/5085>}
 

Modified: CalendarServer/trunk/twext/who/aggregate.py
===================================================================
--- CalendarServer/trunk/twext/who/aggregate.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/aggregate.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -50,7 +50,8 @@
             for recordType in service.recordTypes():
                 if recordType in recordTypes:
                     raise DirectoryConfigurationError(
-                        "Aggregated services may not vend the same record type: %s"
+                        "Aggregated services may not vend "
+                        "the same record type: %s"
                         % (recordType,)
                     )
                 recordTypes.add(recordType)

Modified: CalendarServer/trunk/twext/who/directory.py
===================================================================
--- CalendarServer/trunk/twext/who/directory.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/directory.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -47,7 +47,7 @@
     fieldName  = FieldName
 
     normalizedFields = {
-        FieldName.guid:           lambda g: UUID(g).hex,
+        FieldName.guid: lambda g: UUID(g).hex,
         FieldName.emailAddresses: lambda e: e.lower(),
     }
 
@@ -76,7 +76,9 @@
             the whole directory should be searched.
         @type records: L{set} or L{frozenset}
         """
-        return fail(QueryNotSupportedError("Unknown expression: %s" % (expression,)))
+        return fail(QueryNotSupportedError(
+            "Unknown expression: %s" % (expression,)
+        ))
 
 
     @inlineCallbacks
@@ -109,7 +111,9 @@
             elif operand == Operand.OR:
                 results |= recordsMatchingExpression
             else:
-                raise QueryNotSupportedError("Unknown operand: %s" % (operand,))
+                raise QueryNotSupportedError(
+                    "Unknown operand: %s" % (operand,)
+                )
 
         returnValue(results)
 
@@ -120,12 +124,16 @@
 
     @inlineCallbacks
     def recordWithUID(self, uid):
-        returnValue(uniqueResult((yield self.recordsWithFieldValue(FieldName.uid, uid))))
-               
+        returnValue(uniqueResult(
+            (yield self.recordsWithFieldValue(FieldName.uid, uid))
+        ))
 
+
     @inlineCallbacks
     def recordWithGUID(self, guid):
-        returnValue(uniqueResult((yield self.recordsWithFieldValue(FieldName.guid, guid))))
+        returnValue(uniqueResult(
+            (yield self.recordsWithFieldValue(FieldName.guid, guid))
+        ))
 
 
     def recordsWithRecordType(self, recordType):
@@ -136,12 +144,15 @@
     def recordWithShortName(self, recordType, shortName):
         returnValue(uniqueResult((yield self.recordsFromQuery((
             MatchExpression(FieldName.recordType, recordType),
-            MatchExpression(FieldName.shortNames, shortName ),
+            MatchExpression(FieldName.shortNames, shortName),
         )))))
 
 
     def recordsWithEmailAddress(self, emailAddress):
-        return self.recordsWithFieldValue(FieldName.emailAddresses, emailAddress)
+        return self.recordsWithFieldValue(
+            FieldName.emailAddresses,
+            emailAddress,
+        )
 
 
     def updateRecords(self, records, create=False):
@@ -173,12 +184,19 @@
             if FieldName.isMultiValue(fieldName):
                 values = fields[fieldName]
                 if len(values) == 0:
-                    raise ValueError("%s field must have at least one value." % (fieldName,))
+                    raise ValueError(
+                        "%s field must have at least one value." % (fieldName,)
+                    )
                 for value in values:
                     if not value:
-                        raise ValueError("%s field must not be empty." % (fieldName,))
+                        raise ValueError(
+                            "%s field must not be empty." % (fieldName,)
+                        )
 
-        if fields[FieldName.recordType] not in service.recordType.iterconstants():
+        if (
+            fields[FieldName.recordType] not in
+            service.recordType.iterconstants()
+        ):
             raise ValueError("Record type must be one of %r, not %r." % (
                 tuple(service.recordType.iterconstants()),
                 fields[FieldName.recordType]
@@ -197,7 +215,7 @@
                 normalizedFields[name] = tuple((normalize(v) for v in value))
             else:
                 normalizedFields[name] = normalize(value)
-        
+
         self.service = service
         self.fields  = normalizedFields
 

Modified: CalendarServer/trunk/twext/who/expression.py
===================================================================
--- CalendarServer/trunk/twext/who/expression.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/expression.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -72,7 +72,11 @@
     @ivar flags: L{NamedConstant} specifying additional options
     """
 
-    def __init__(self, fieldName, fieldValue, matchType=MatchType.equals, flags=None):
+    def __init__(
+        self,
+        fieldName, fieldValue,
+        matchType=MatchType.equals, flags=None
+    ):
         self.fieldName  = fieldName
         self.fieldValue = fieldValue
         self.matchType  = matchType

Modified: CalendarServer/trunk/twext/who/idirectory.py
===================================================================
--- CalendarServer/trunk/twext/who/idirectory.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/idirectory.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -51,16 +51,22 @@
     Directory service generic error.
     """
 
+
+
 class DirectoryConfigurationError(DirectoryServiceError):
     """
     Directory configurtion error.
     """
 
+
+
 class DirectoryAvailabilityError(DirectoryServiceError):
     """
     Directory not available.
     """
 
+
+
 class UnknownRecordTypeError(DirectoryServiceError):
     """
     Unknown record type.
@@ -69,16 +75,22 @@
         DirectoryServiceError.__init__(self, token)
         self.token = token
 
+
+
 class QueryNotSupportedError(DirectoryServiceError):
     """
     Query not supported.
     """
 
+
+
 class NoSuchRecordError(DirectoryServiceError):
     """
     Record does not exist.
     """
 
+
+
 class NotAllowedError(DirectoryServiceError):
     """
     Apparently, you can't do that.
@@ -123,6 +135,7 @@
     fullNames.multiValue      = True
     emailAddresses.multiValue = True
 
+
     @staticmethod
     def isMultiValue(name):
         return getattr(name, "multiValue", False)
@@ -157,14 +170,18 @@
     A directory service may allow support the editing, removal and
     addition of records.
     """
-    realmName = Attribute("The name of the authentication realm this service represents.")
+    realmName = Attribute(
+        "The name of the authentication realm this service represents."
+    )
 
+
     def recordTypes():
         """
         @return: an iterable of L{NamedConstant}s denoting the record
             types that are kept in this directory.
         """
 
+
     def recordsFromExpression(self, expression):
         """
         Find records matching an expression.
@@ -175,6 +192,7 @@
             supported by this directory service.
         """
 
+
     def recordsFromQuery(expressions, operand=Operand.AND):
         """
         Find records by composing a query consisting of an iterable of
@@ -188,6 +206,7 @@
             supported by this directory service.
         """
 
+
     def recordsWithFieldValue(fieldName, value):
         """
         Find records that have the given field name with the given
@@ -199,6 +218,7 @@
         @return: a deferred iterable of L{IDirectoryRecord}s.
         """
 
+
     def recordWithUID(uid):
         """
         Find the record that has the given UID.
@@ -207,7 +227,8 @@
         @return: a deferred iterable of L{IDirectoryRecord}s, or
             C{None} if there is no such record.
         """
-               
+
+
     def recordWithGUID(guid):
         """
         Find the record that has the given GUID.
@@ -217,6 +238,7 @@
             C{None} if there is no such record.
         """
 
+
     def recordsWithRecordType(recordType):
         """
         Find the records that have the given record type.
@@ -225,6 +247,7 @@
         @return: a deferred iterable of L{IDirectoryRecord}s.
         """
 
+
     def recordWithShortName(recordType, shortName):
         """
         Find the record that has the given record type and short name.
@@ -236,6 +259,7 @@
             C{None} if there is no such record.
         """
 
+
     def recordsWithEmailAddress(emailAddress):
         """
         Find the records that have the given email address.
@@ -245,6 +269,7 @@
             C{None} if there is no such record.
         """
 
+
     def updateRecords(records, create=False):
         """
         Updates existing directory records.
@@ -254,6 +279,7 @@
         @type create: boolean
         """
 
+
     def removeRecords(uids):
         """
         Removes the records with the given UIDs.
@@ -294,6 +320,7 @@
     service = Attribute("The L{IDirectoryService} this record exists in.")
     fields  = Attribute("A mapping with L{NamedConstant} keys.")
 
+
     def members():
         """
         Find the records that are members of this group.  Only direct
@@ -302,6 +329,7 @@
             direct members of this group.
         """
 
+
     def groups():
         """
         Find the group records that this record is a member of.  Only

Modified: CalendarServer/trunk/twext/who/index.py
===================================================================
--- CalendarServer/trunk/twext/who/index.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/index.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -29,7 +29,8 @@
 from twisted.python.constants import Names, NamedConstant
 from twisted.internet.defer import succeed, inlineCallbacks, returnValue
 
-from twext.who.util import ConstantsContainer, describe, uniqueResult, iterFlags
+from twext.who.util import ConstantsContainer
+from twext.who.util import describe, uniqueResult, iterFlags
 from twext.who.idirectory import FieldName as BaseFieldName
 from twext.who.expression import MatchExpression, MatchType, MatchFlags
 from twext.who.directory import DirectoryService as BaseDirectoryService
@@ -57,7 +58,10 @@
     XML directory service.
     """
 
-    fieldName = ConstantsContainer(chain(BaseDirectoryService.fieldName.iterconstants(), FieldName.iterconstants()))
+    fieldName = ConstantsContainer(chain(
+        BaseDirectoryService.fieldName.iterconstants(),
+        FieldName.iterconstants()
+    ))
 
     indexedFields = (
         BaseFieldName.recordType,
@@ -112,7 +116,9 @@
                 elif flag == MatchFlags.caseInsensitive:
                     normalize = lambda x: x.lower()
                 else:
-                    raise NotImplementedError("Unknown query flag: %s" % (describe(flag),))
+                    raise NotImplementedError(
+                        "Unknown query flag: %s" % (describe(flag),)
+                    )
 
         return predicate, normalize
 
@@ -131,16 +137,27 @@
         matchType  = expression.matchType
 
         if matchType == MatchType.startsWith:
-            indexKeys = (key for key in fieldIndex if predicate(normalize(key).startswith(matchValue)))
+            indexKeys = (
+                key for key in fieldIndex
+                if predicate(normalize(key).startswith(matchValue))
+            )
         elif matchType == MatchType.contains:
-            indexKeys = (key for key in fieldIndex if predicate(matchValue in normalize(key)))
+            indexKeys = (
+                key for key in fieldIndex
+                if predicate(matchValue in normalize(key))
+            )
         elif matchType == MatchType.equals:
             if predicate(True):
                 indexKeys = (matchValue,)
             else:
-                indexKeys = (key for key in fieldIndex if normalize(key) != matchValue)
+                indexKeys = (
+                    key for key in fieldIndex
+                    if normalize(key) != matchValue
+                )
         else:
-            raise NotImplementedError("Unknown match type: %s" % (describe(matchType),))
+            raise NotImplementedError(
+                "Unknown match type: %s" % (describe(matchType),)
+            )
 
         matchingRecords = set()
         for key in indexKeys:
@@ -165,18 +182,25 @@
         matchType  = expression.matchType
 
         if matchType == MatchType.startsWith:
-            match = lambda fieldValue: predicate(fieldValue.startswith(matchValue))
+            match = lambda fieldValue: predicate(
+                fieldValue.startswith(matchValue)
+            )
         elif matchType == MatchType.contains:
             match = lambda fieldValue: predicate(matchValue in fieldValue)
         elif matchType == MatchType.equals:
             match = lambda fieldValue: predicate(fieldValue == matchValue)
         else:
-            raise NotImplementedError("Unknown match type: %s" % (describe(matchType),))
+            raise NotImplementedError(
+                "Unknown match type: %s" % (describe(matchType),)
+            )
 
         result = set()
 
         if records is None:
-            records = (uniqueResult(values) for values in self.index[self.fieldName.uid].itervalues())
+            records = (
+                uniqueResult(values) for values
+                in self.index[self.fieldName.uid].itervalues()
+            )
 
         for record in records:
             fieldValues = record.fields.get(expression.fieldName, None)
@@ -194,11 +218,17 @@
     def recordsFromExpression(self, expression, records=None):
         if isinstance(expression, MatchExpression):
             if expression.fieldName in self.indexedFields:
-                return self.indexedRecordsFromMatchExpression(expression, records=records)
+                return self.indexedRecordsFromMatchExpression(
+                    expression, records=records
+                )
             else:
-                return self.unIndexedRecordsFromMatchExpression(expression, records=records)
+                return self.unIndexedRecordsFromMatchExpression(
+                    expression, records=records
+                )
         else:
-            return BaseDirectoryService.recordsFromExpression(self, expression, records=records)
+            return BaseDirectoryService.recordsFromExpression(
+                self, expression, records=records
+            )
 
 
 
@@ -206,6 +236,7 @@
     """
     XML directory record
     """
+
     @inlineCallbacks
     def members(self):
         members = set()
@@ -215,4 +246,6 @@
 
 
     def groups(self):
-        return self.service.recordsWithFieldValue(FieldName.memberUIDs, self.uid)
+        return self.service.recordsWithFieldValue(
+            FieldName.memberUIDs, self.uid
+        )

Modified: CalendarServer/trunk/twext/who/util.py
===================================================================
--- CalendarServer/trunk/twext/who/util.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/util.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -67,7 +67,9 @@
         if result is None:
             result = value
         else:
-            raise DirectoryServiceError("Multiple values found where one expected.")
+            raise DirectoryServiceError(
+                "Multiple values found where one expected."
+            )
     return result
 
 

Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py	2013-10-07 01:45:20 UTC (rev 11794)
+++ CalendarServer/trunk/twext/who/xml.py	2013-10-08 00:03:58 UTC (rev 11795)
@@ -201,7 +201,10 @@
         #
         if stat:
             self.filePath.restat()
-            cacheTag = (self.filePath.getModificationTime(), self.filePath.getsize())
+            cacheTag = (
+                self.filePath.getModificationTime(),
+                self.filePath.getsize()
+            )
             if cacheTag == self._cacheTag:
                 return
         else:
@@ -225,9 +228,13 @@
         #
         directoryNode = etree.getroot()
         if directoryNode.tag != self.element.directory.value:
-            raise ParseError("Incorrect root element: %s" % (directoryNode.tag,))
+            raise ParseError(
+                "Incorrect root element: %s" % (directoryNode.tag,)
+            )
 
-        realmName = directoryNode.get(self.attribute.realm.value, "").encode("utf-8")
+        realmName = directoryNode.get(
+            self.attribute.realm.value, ""
+        ).encode("utf-8")
 
         if not realmName:
             raise ParseError("No realm name.")
@@ -239,7 +246,9 @@
 
         for recordNode in directoryNode:
             try:
-                records.add(self.parseRecordNode(recordNode, unknownFieldElements))
+                records.add(
+                    self.parseRecordNode(recordNode, unknownFieldElements)
+                )
             except UnknownRecordTypeError as e:
                 unknownRecordTypes.add(e.token)
 
@@ -277,10 +286,14 @@
 
 
     def parseRecordNode(self, recordNode, unknownFieldElements=None):
-        recordTypeAttribute = recordNode.get(self.attribute.recordType.value, "").encode("utf-8")
+        recordTypeAttribute = recordNode.get(
+            self.attribute.recordType.value, ""
+        ).encode("utf-8")
         if recordTypeAttribute:
             try:
-                recordType = self.value.lookupByValue(recordTypeAttribute).recordType
+                recordType = (
+                    self.value.lookupByValue(recordTypeAttribute).recordType
+                )
             except (ValueError, AttributeError):
                 raise UnknownRecordTypeError(recordTypeAttribute)
         else:
@@ -357,9 +370,14 @@
             for (name, value) in record.fields.items():
                 if name == self.fieldName.recordType:
                     if value in recordTypes:
-                        recordNode.set(self.attribute.recordType.value, recordTypes[value])
+                        recordNode.set(
+                            self.attribute.recordType.value,
+                            recordTypes[value]
+                        )
                     else:
-                        raise AssertionError("Unknown record type: %r" % (value,))
+                        raise AssertionError(
+                            "Unknown record type: %r" % (value,)
+                        )
 
                 else:
                     if name in fieldNames:
@@ -376,7 +394,9 @@
                             recordNode.append(subNode)
 
                     else:
-                        raise AssertionError("Unknown field name: %r" % (name,))
+                        raise AssertionError(
+                            "Unknown field name: %r" % (name,)
+                        )
 
         # Walk through the record nodes in the XML tree and apply
         # updates.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20131007/4c0c6f3b/attachment-0001.html>


More information about the calendarserver-changes mailing list