[CalendarServer-changes] [8884] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 16 01:28:12 PDT 2012
Revision: 8884
http://trac.macosforge.org/projects/calendarserver/changeset/8884
Author: wsanchez at apple.com
Date: 2012-03-16 01:28:12 -0700 (Fri, 16 Mar 2012)
Log Message:
-----------
Cleanup
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:27:49 UTC (rev 8883)
+++ CalendarServer/trunk/twext/web2/dav/davxml.py 2012-03-16 08:28:12 UTC (rev 8884)
@@ -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
@@ -91,30 +90,20 @@
@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,))
+ return decodeXMLName(sname)
- raiseIf(not sname.startswith("{"))
+def qname2sname(qname):
+ """
+ Convert a qname into an sname.
+ """
+ return encodeXMLName(*qname)
- 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:27:49 UTC (rev 8883)
+++ CalendarServer/trunk/txdav/xml/util.py 2012-03-16 08:28:12 UTC (rev 8884)
@@ -35,10 +35,7 @@
def PrintXML(document, stream):
- try:
- import xml.dom.ext as ext
- except ImportError:
- import txdav.xml.xmlext as ext
+ import xml.dom.ext as ext
document.normalize()
ext.Print(document, stream)
@@ -52,20 +49,25 @@
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 an ASCII string as
+ Decodes an XML (namespace, name) pair from a UTF-8 string as
encoded by encodeXMLName().
"""
- if name[0] is not "{": return (None, name.decode("utf-8"))
+ name = 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].decode("utf-8"), name[index+1:].decode("utf-8"))
+ return (name[1:index], name[index+1:])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120316/acf61fbb/attachment.html>
More information about the calendarserver-changes
mailing list