[CalendarServer-changes] [8899] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 16 14:45:09 PDT 2012


Revision: 8899
          http://trac.macosforge.org/projects/calendarserver/changeset/8899
Author:   wsanchez at apple.com
Date:     2012-03-16 14:45:09 -0700 (Fri, 16 Mar 2012)
Log Message:
-----------
Remove duplicate functionality

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/principals.py
    CalendarServer/trunk/twext/web2/dav/davxml.py

Removed Paths:
-------------
    CalendarServer/trunk/twext/web2/dav/test/test_davxml.py

Modified: CalendarServer/trunk/calendarserver/tools/principals.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/principals.py	2012-03-16 21:30:00 UTC (rev 8898)
+++ CalendarServer/trunk/calendarserver/tools/principals.py	2012-03-16 21:45:09 UTC (rev 8899)
@@ -31,8 +31,9 @@
 
 from twext.python.log import clearLogLevels
 from twext.python.log import StandardIOObserver
-from twext.web2.dav.davxml import sname2qname, qname2sname
 
+from txdav.xml.base import decodeXMLName, encodeXMLName
+
 from twistedcaldav.config import config, ConfigurationError
 from twistedcaldav.directory.directory import UnknownRecordTypeError, DirectoryError
 
@@ -160,7 +161,7 @@
 
         elif opt in ("", "--read-property"):
             try:
-                qname = sname2qname(arg)
+                qname = decodeXMLName(arg)
             except ValueError, e:
                 abort(e)
             principalActions.append((action_readProperty, qname))
@@ -511,7 +512,7 @@
 @inlineCallbacks
 def action_readProperty(resource, qname):
     property = (yield resource.readProperty(qname, None))
-    print "%r on %s:" % (qname2sname(qname), resource)
+    print "%r on %s:" % (encodeXMLName(*qname), resource)
     print ""
     print property.toxml()
 

Modified: CalendarServer/trunk/twext/web2/dav/davxml.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/davxml.py	2012-03-16 21:30:00 UTC (rev 8898)
+++ CalendarServer/trunk/twext/web2/dav/davxml.py	2012-03-16 21:45:09 UTC (rev 8899)
@@ -1,6 +1,5 @@
-
 ##
-# Copyright (c) 2005-2010 Apple Computer, Inc. All rights reserved.
+# Copyright (c) 2005-2012 Apple Computer, Inc. All rights reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -19,8 +18,6 @@
 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
-#
-# DRI: Wilfredo Sanchez, wsanchez at apple.com
 ##
 
 """
@@ -70,48 +67,5 @@
     registerElements(r3) +
     registerElements(r4) +
     registerElements(r5) +
-    registerElements(e) +
-    [
-        "sname2qname",
-        "qname2sname",
-    ]
+    registerElements(e)
 )
-
-
-def sname2qname(sname):
-    """
-    Convert an sname into a qname.
-
-    That is, parse a property name string (eg: C{"{DAV:}displayname"})
-    into a tuple (eg: C{("DAV:", "displayname")}).
-
-    @raise ValueError is input is not valid. Note, however, that this
-    function does not attempt to fully validate C{sname}.
-    """
-    def raiseIf(condition):
-        if condition:
-            raise ValueError("Invalid sname: %s" % (sname,))
-
-    raiseIf(not sname.startswith("{"))
-
-    try:
-        i = sname.index("}")
-    except ValueError:
-        raiseIf(True)
-
-    namespace = sname[1:i]
-    name = sname [i+1:]
-
-    raiseIf("{" in namespace or not name)
-
-    return namespace, name
-
-def qname2sname(qname):
-    """
-    Convert a qname into an sname.
-    """
-    try:
-        return "{%s}%s" % qname
-    except TypeError:
-        raise ValueError("Invalid qname: %r" % (qname,))
-

Deleted: CalendarServer/trunk/twext/web2/dav/test/test_davxml.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/test/test_davxml.py	2012-03-16 21:30:00 UTC (rev 8898)
+++ CalendarServer/trunk/twext/web2/dav/test/test_davxml.py	2012-03-16 21:45:09 UTC (rev 8899)
@@ -1,55 +0,0 @@
-
-##
-# Copyright (c) 2005-2010 Apple Computer, Inc. All rights reserved.
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-# 
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-#
-# DRI: Wilfredo Sanchez, wsanchez at apple.com
-##
-
-from twext.web2.dav.davxml import *
-
-from twistedcaldav.test.util import TestCase
-
-class XML(TestCase):
-    def test_sname2qname(self):
-        # Empty name
-        self.assertRaises(ValueError, sname2qname, "") 
-        self.assertRaises(ValueError, sname2qname, "{}")
-        self.assertRaises(ValueError, sname2qname, "{x}")
-
-        # Weird bracket cases
-        self.assertRaises(ValueError, sname2qname, "{")
-        self.assertRaises(ValueError, sname2qname, "x{")
-        self.assertRaises(ValueError, sname2qname, "{x")
-        self.assertRaises(ValueError, sname2qname, "}")
-        self.assertRaises(ValueError, sname2qname, "x}")
-        self.assertRaises(ValueError, sname2qname, "}x")  
-        self.assertRaises(ValueError, sname2qname, "{{}")
-        self.assertRaises(ValueError, sname2qname, "{{}}")
-        self.assertRaises(ValueError, sname2qname, "x{}")
-
-        # Empty namespace is OK
-        self.assertEquals(sname2qname("{}x"), ("", "x"))
-
-        # Normal case
-        self.assertEquals(sname2qname("{namespace}name"), ("namespace", "name"))
-
-    def test_qname2sname(self):
-        self.assertEquals(qname2sname(("namespace", "name")), "{namespace}name")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120316/7e92d61f/attachment.html>


More information about the calendarserver-changes mailing list