[CalendarServer-changes] [12129] twext/trunk/twext/who/opendirectory

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:21:21 PDT 2014


Revision: 12129
          http://trac.calendarserver.org//changeset/12129
Author:   wsanchez at apple.com
Date:     2013-12-18 11:29:44 -0800 (Wed, 18 Dec 2013)
Log Message:
-----------
cleanup

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/__init__.py
    twext/trunk/twext/who/opendirectory/odframework.py
    twext/trunk/twext/who/opendirectory/service.py
    twext/trunk/twext/who/opendirectory/test/test_service.py

Modified: twext/trunk/twext/who/opendirectory/__init__.py
===================================================================
--- twext/trunk/twext/who/opendirectory/__init__.py	2013-12-18 19:02:46 UTC (rev 12128)
+++ twext/trunk/twext/who/opendirectory/__init__.py	2013-12-18 19:29:44 UTC (rev 12129)
@@ -14,10 +14,19 @@
 # limitations under the License.
 ##
 
+"""
+OpenDirectory directory service.
+"""
+
 __all__ = [
+    "OpenDirectoryError",
+    "OpenDirectoryConnectionError",
+    "OpenDirectoryQueryError",
     "DirectoryService",
     "DirectoryRecord",
 ]
 
 
+from .service import OpenDirectoryError
+from .service import OpenDirectoryConnectionError, OpenDirectoryQueryError
 from .service import DirectoryService, DirectoryRecord

Modified: twext/trunk/twext/who/opendirectory/odframework.py
===================================================================
--- twext/trunk/twext/who/opendirectory/odframework.py	2013-12-18 19:02:46 UTC (rev 12128)
+++ twext/trunk/twext/who/opendirectory/odframework.py	2013-12-18 19:29:44 UTC (rev 12129)
@@ -1,3 +1,23 @@
+##
+# Copyright (c) 2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+OpenDirectory.framework
+"""
+
 import objc as _objc
 
 __bundle__ = _objc.initFrameworkWrapper(

Modified: twext/trunk/twext/who/opendirectory/service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/service.py	2013-12-18 19:02:46 UTC (rev 12128)
+++ twext/trunk/twext/who/opendirectory/service.py	2013-12-18 19:29:44 UTC (rev 12129)
@@ -21,12 +21,6 @@
 OpenDirectory directory service implementation.
 """
 
-__all__ = [
-    "OpenDirectoryError",
-    "DirectoryService",
-    "DirectoryRecord",
-]
-
 from itertools import chain
 
 from odframework import ODSession, ODNode, ODQuery
@@ -350,13 +344,16 @@
                 )
             odAttr = ODAttribute.fromFieldName(expression.fieldName).value
             queryString = {
-                ODMatchType.equals.value      : u"(%s=%s)",
-                ODMatchType.startsWith.value  : u"(%s=%s*)",
-                ODMatchType.endsWith.value    : u"(%s=*%s)",
-                ODMatchType.contains.value    : u"(%s=*%s*)",
-                ODMatchType.lessThan.value    : u"(%s<%s)",
-                ODMatchType.greaterThan.value : u"(%s>%s)",
-            }.get(matchType.value, u"(%s=*%s*)") % (odAttr, expression.fieldValue,)
+                ODMatchType.equals.value: u"({attr}={value})",
+                ODMatchType.startsWith.value: u"({attr}={value}*)",
+                ODMatchType.endsWith.value: u"({attr}=*{value})",
+                ODMatchType.contains.value: u"({attr}=*{value}*)",
+                ODMatchType.lessThan.value: u"({attr}<{value})",
+                ODMatchType.greaterThan.value: u"({attr}>{value})",
+            }.get(matchType.value, u"({attr}=*{value}*)").format(
+                attr=odAttr,
+                value=expression.fieldValue
+            )
 
         elif isinstance(expression, CompoundExpression):
             queryString = u""
@@ -615,22 +612,25 @@
         # "Local node = {service.localNode}\n"
         .format(service=service)
     )
+    print("-" * 80)
 
-    for shortName in sys.argv:
-        print("=" * 80)
+    for shortName in sys.argv[1:]:
+        print("Looking up short name: {0}".format(shortName))
+
         matchExpression = MatchExpression(
             service.fieldName.shortNames, shortName,
             matchType=MatchType.equals,
         )
         queryString = service._queryStringFromExpression(matchExpression)
-        print("{name} via MatchExpression using query {query}".format(
-            name=shortName, query=queryString))
+        print(
+            "\n...via MatchExpression, query={query!r}"
+            .format(query=queryString)
+        )
+        print()
+
         for record in service.recordsFromExpression(matchExpression):
-            print("*" * 80)
             print(record.description())
 
-        print("=" * 80)
-
         compoundExpression = CompoundExpression(
             [
                 MatchExpression(
@@ -643,10 +643,14 @@
                 ),
             ],
             Operand.OR
-        ) 
+        )
         queryString = service._queryStringFromExpression(compoundExpression)
-        print("{name} via CompoundExpression using query {query}".format(
-            name=shortName, query=queryString))
+        print(
+            "\n...via CompoundExpression, query={query!r}"
+            .format(query=queryString)
+        )
+        print()
+
         for record in service.recordsFromExpression(compoundExpression):
-            print("*" * 80)
             print(record.description())
+            print()

Modified: twext/trunk/twext/who/opendirectory/test/test_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/test/test_service.py	2013-12-18 19:02:46 UTC (rev 12128)
+++ twext/trunk/twext/who/opendirectory/test/test_service.py	2013-12-18 19:29:44 UTC (rev 12129)
@@ -26,8 +26,6 @@
 
 
 
-
-
 class OpenDirectoryServiceTestCase(unittest.TestCase):
     """
     Tests for L{DirectoryService}.
@@ -49,8 +47,10 @@
                 matchType=matchType
             )
             queryString = service._queryStringFromExpression(expression)
-            self.assertEquals(queryString,
-                u"(dsAttrTypeStandard:RecordName{exp})".format(exp=expected))
+            self.assertEquals(
+                queryString,
+                u"(dsAttrTypeStandard:RecordName{exp})".format(exp=expected)
+            )
 
         # CompoundExpressions
 
@@ -78,14 +78,17 @@
                 ),
             ],
             Operand.AND
-        ) 
+        )
         queryString = service._queryStringFromExpression(expression)
-        self.assertEquals(queryString,
-            u"(&(dsAttrTypeStandard:GeneratedUID=*a*)"
-             "(dsAttrTypeStandard:GeneratedUID=*b*)"
-             "(dsAttrTypeStandard:RecordName=*c*)"
-             "(dsAttrTypeStandard:EMailAddress=d*)"
-             "(dsAttrTypeStandard:RealName=e))"
+        self.assertEquals(
+            queryString,
+            (
+                u"(&(dsAttrTypeStandard:GeneratedUID=*a*)"
+                u"(dsAttrTypeStandard:GeneratedUID=*b*)"
+                u"(dsAttrTypeStandard:RecordName=*c*)"
+                u"(dsAttrTypeStandard:EMailAddress=d*)"
+                u"(dsAttrTypeStandard:RealName=e))"
+            )
         )
 
         expression = CompoundExpression(
@@ -104,10 +107,13 @@
                 ),
             ],
             Operand.OR
-        ) 
+        )
         queryString = service._queryStringFromExpression(expression)
-        self.assertEquals(queryString,
-            u"(|(dsAttrTypeStandard:RecordName=*a*)"
-             "(dsAttrTypeStandard:EMailAddress=b*)"
-             "(dsAttrTypeStandard:RealName=c))"
+        self.assertEquals(
+            queryString,
+            (
+                u"(|(dsAttrTypeStandard:RecordName=*a*)"
+                u"(dsAttrTypeStandard:EMailAddress=b*)"
+                u"(dsAttrTypeStandard:RealName=c))"
+            )
         )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/80be9d93/attachment.html>


More information about the calendarserver-changes mailing list