[CalendarServer-changes] [8885] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 16 01:40:47 PDT 2012


Revision: 8885
          http://trac.macosforge.org/projects/calendarserver/changeset/8885
Author:   wsanchez at apple.com
Date:     2012-03-16 01:40:47 -0700 (Fri, 16 Mar 2012)
Log Message:
-----------
revert 8884

Modified Paths:
--------------
    CalendarServer/trunk/twext/web2/dav/davxml.py
    CalendarServer/trunk/txdav/xml/util.py

Modified: CalendarServer/trunk/twext/web2/dav/davxml.py
===================================================================
--- CalendarServer/trunk/twext/web2/dav/davxml.py	2012-03-16 08:28:12 UTC (rev 8884)
+++ CalendarServer/trunk/twext/web2/dav/davxml.py	2012-03-16 08:40:47 UTC (rev 8885)
@@ -1,5 +1,6 @@
+
 ##
-# Copyright (c) 2005-2012 Apple Computer, Inc. All rights reserved.
+# 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
@@ -90,20 +91,30 @@
     @raise ValueError is input is not valid. Note, however, that this
     function does not attempt to fully validate C{sname}.
     """
-    return decodeXMLName(sname)
+    def raiseIf(condition):
+        if condition:
+            raise ValueError("Invalid sname: %s" % (sname,))
 
-def qname2sname(qname):
-    """
-    Convert a qname into an sname.
-    """
-    return encodeXMLName(*qname)
+    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,))
 
-
-
-
-

Modified: CalendarServer/trunk/txdav/xml/util.py
===================================================================
--- CalendarServer/trunk/txdav/xml/util.py	2012-03-16 08:28:12 UTC (rev 8884)
+++ CalendarServer/trunk/txdav/xml/util.py	2012-03-16 08:40:47 UTC (rev 8885)
@@ -35,7 +35,10 @@
 
 
 def PrintXML(document, stream):
-    import xml.dom.ext as ext
+    try:
+        import xml.dom.ext as ext
+    except ImportError:
+        import txdav.xml.xmlext as ext
 
     document.normalize()
     ext.Print(document, stream)
@@ -49,25 +52,20 @@
     If namespace is None, returns "name", otherwise, returns
     "{namespace}name".
     """
-    if namespace is None:
-        return name.encode("utf-8")
-
+    if namespace is None: return name.encode("utf-8")
     return (u"{%s}%s" % (namespace, name)).encode("utf-8")
 
 
 def decodeXMLName(name):
     """
-    Decodes an XML (namespace, name) pair from a UTF-8 string as
+    Decodes an XML (namespace, name) pair from an ASCII string as
     encoded by encodeXMLName().
     """
-    name = name.decode("utf-8")
+    if name[0] is not "{": return (None, name.decode("utf-8"))
 
-    if name[0] is not "{":
-        return (None, name)
-
     index = name.find("}")
 
     if (index is -1 or not len(name) > index):
         raise ValueError("Invalid encoded name: %r" % (name,))
 
-    return (name[1:index], name[index+1:])
+    return (name[1:index].decode("utf-8"), name[index+1:].decode("utf-8"))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120316/0155d8bc/attachment-0001.html>


More information about the calendarserver-changes mailing list