Skip to content
Permalink
Browse files

Use encodeXMLName()

  • Loading branch information...
wsanchez committed Jul 20, 2012
1 parent 88185b0 commit e9d8c0856dc06b95c5abb22368247bf79551c493
@@ -44,6 +44,7 @@
from twext.web2.dav.util import davXMLFromStream
from txdav.xml import element as davxml
from txdav.xml.element import lookupElement
from txdav.xml.base import encodeXMLName

log = Logger()

@@ -115,7 +116,7 @@ def to_method(s):
if namespace == davxml.dav_namespace:
request.submethod = "DAV:" + name
else:
request.submethod = "{%s}%s" % (namespace, name)
request.submethod = encodeXMLName(namespace, name)
else:
method_name = to_method(name)

@@ -136,8 +137,8 @@ def to_method(s):
#
# Requested report is not supported.
#
log.err("Unsupported REPORT {%s}%s for resource %s (no method %s)"
% (namespace, name, self, method_name))
log.err("Unsupported REPORT %s for resource %s (no method %s)"
% (encodeXMLName(namespace, name), self, method_name))

raise HTTPError(ErrorResponse(
responsecode.FORBIDDEN,
@@ -33,6 +33,8 @@

from twext.web2 import responsecode
from twext.web2.http import HTTPError, StatusResponse
from txdav.xml.base import encodeXMLName


class NonePropertyStore (object):
"""
@@ -50,10 +52,16 @@ def __init__(self, resource):
pass

def get(self, qname, uid=None):
raise HTTPError(StatusResponse(responsecode.NOT_FOUND, "No such property: {%s}%s" % qname))
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: %s" % (encodeXMLName(*qname),)
))

def set(self, property, uid=None):
raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Permission denied for setting property: %s" % (property,)))
raise HTTPError(StatusResponse(
responsecode.FORBIDDEN,
"Permission denied for setting property: %s" % (property,)
))

def delete(self, qname, uid=None):
# RFC 2518 Section 12.13.1 says that removal of
@@ -57,6 +57,12 @@
from twisted.internet import reactor

from twext.python.log import Logger
from txdav.xml import element
from txdav.xml.base import encodeXMLName
from txdav.xml.element import WebDAVElement, WebDAVEmptyElement, WebDAVTextElement
from txdav.xml.element import dav_namespace
from txdav.xml.element import twisted_dav_namespace, twisted_private_namespace
from txdav.xml.element import registerElement, lookupElement
from twext.web2 import responsecode
from twext.web2.http import HTTPError, RedirectResponse, StatusResponse
from twext.web2.http_headers import generateContentType
@@ -70,11 +76,6 @@
from twext.web2.dav.noneprops import NonePropertyStore
from twext.web2.dav.util import unimplemented, parentForURL, joinURL
from twext.web2.dav.auth import PrincipalCredentials
from txdav.xml import element
from txdav.xml.element import WebDAVElement, WebDAVEmptyElement, WebDAVTextElement
from txdav.xml.element import dav_namespace
from txdav.xml.element import twisted_dav_namespace, twisted_private_namespace
from txdav.xml.element import registerElement, lookupElement


log = Logger()
@@ -217,7 +218,7 @@ def readProperty(self, property, request):
def defer():
if type(property) is tuple:
qname = property
sname = "{%s}%s" % property
sname = encodeXMLName(*property)
else:
qname = property.qname()
sname = property.sname()
@@ -416,7 +417,7 @@ def removeProperty(self, property, request):
def defer():
if type(property) is tuple:
qname = property
sname = "{%s}%s" % property
sname = encodeXMLName(*property)
else:
qname = property.qname()
sname = property.sname()
@@ -1873,9 +1874,9 @@ def gotPrincipal(principal):
return None

if not isinstance(principal, element.Principal):
log.err("Non-principal value in property {%s}%s "
log.err("Non-principal value in property %s "
"referenced by property principal."
% (namespace, name))
% (encodeXMLName(namespace, name),))
return None

if len(principal.children) != 1:
@@ -132,7 +132,7 @@ def _setValue(self, originalDocument, value, uid=None):
attribute = (
self.propertyStore.deadPropertyXattrPrefix +
(uid if uid is not None else "") +
"{%s}%s" % element.qname())
element.sname())
self.attrs[attribute] = value


@@ -141,7 +141,7 @@ def _getValue(self, originalDocument, uid=None):
attribute = (
self.propertyStore.deadPropertyXattrPrefix +
(uid if uid is not None else "") +
"{%s}%s" % element.qname())
element.sname())
return self.attrs[attribute]


@@ -38,6 +38,7 @@
from twext.web2.dav.static import DAVFile
from twext.web2.dav.util import joinURL
from txdav.xml import element
from txdav.xml.base import encodeXMLName

log = Logger()

@@ -57,7 +58,7 @@ def get(self, qname):
except KeyError:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: {%s}%s" % qname
"No such property: %s" % (encodeXMLName(*qname),)
))

doc = element.WebDAVDocument.fromString(property)
@@ -50,10 +50,11 @@
from twisted.python.util import untilConcludes
from twisted.python.failure import Failure
from twisted.python.log import err
from txdav.xml.base import encodeXMLName
from txdav.xml.parser import WebDAVDocument
from twext.web2 import responsecode
from twext.web2.http import HTTPError, StatusResponse
from twext.web2.dav.http import statusForFailure
from txdav.xml.parser import WebDAVDocument

# RFC 2518 Section 12.13.1 says that removal of non-existing property
# is not an error. python-xattr on Linux fails with ENODATA in this
@@ -86,7 +87,7 @@ class xattrPropertyStore (object):
deadPropertyXattrPrefix = "user."

def _encode(clazz, name, uid=None):
result = urllib.quote("{%s}%s" % name, safe='{}:')
result = urllib.quote(encodeXMLName(*name), safe='{}:')
if uid:
result = uid + result
r = clazz.deadPropertyXattrPrefix + result
@@ -138,17 +139,20 @@ def get(self, qname, uid=None):
data = self.attrs.get(self._encode(qname, uid))
except KeyError:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: {%s}%s" % qname))
responsecode.NOT_FOUND,
"No such property: %s" % (encodeXMLName(*qname),)
))
except IOError, e:
if e.errno in _ATTR_MISSING or e.errno == errno.ENOENT:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: {%s}%s" % qname))
responsecode.NOT_FOUND,
"No such property: %s" % (encodeXMLName(*qname),)
))
else:
raise HTTPError(StatusResponse(
statusForFailure(Failure()),
"Unable to read property: {%s}%s" % qname))
statusForFailure(Failure()),
"Unable to read property: %s" % (encodeXMLName(*qname),)
))

#
# Unserialize XML data from an xattr. The storage format has changed
@@ -175,8 +179,8 @@ def get(self, qname, uid=None):
try:
doc = unpickle(data)
except UnpicklingError:
format = "Invalid property value stored on server: {%s}%s %s"
msg = format % (qname[0], qname[1], data)
format = "Invalid property value stored on server: %s %s"
msg = format % (encodeXMLName(*qname), data)
err(None, msg)
raise HTTPError(
StatusResponse(responsecode.INTERNAL_SERVER_ERROR, msg))
@@ -225,10 +229,10 @@ def delete(self, qname, uid=None):
if e.errno not in _ATTR_MISSING:
raise
except:
raise HTTPError(
StatusResponse(
statusForFailure(Failure()),
"Unable to delete property: " + key))
raise HTTPError(StatusResponse(
statusForFailure(Failure()),
"Unable to delete property: %s", (key,)
))


def contains(self, qname, uid=None):
@@ -252,10 +256,10 @@ def contains(self, qname, uid=None):
except IOError, e:
if e.errno in _ATTR_MISSING or e.errno == errno.ENOENT:
return False
raise HTTPError(
StatusResponse(
statusForFailure(Failure()),
"Unable to read property: " + key))
raise HTTPError(StatusResponse(
statusForFailure(Failure()),
"Unable to read property: %s" % (key,)
))
else:
return True

@@ -277,10 +281,10 @@ def list(self, uid=None, filterByUID=True):
except IOError, e:
if e.errno == errno.ENOENT:
return []
raise HTTPError(
StatusResponse(
statusForFailure(Failure()),
"Unable to list properties: " + self.resource.fp.path))
raise HTTPError(StatusResponse(
statusForFailure(Failure()),
"Unable to list properties: %s", (self.resource.fp.path,)
))
else:
results = [
self._decode(name)
@@ -46,6 +46,7 @@
from twext.web2.stream import FileStream
from twext.web2.static import MetaDataMixin, StaticRenderMixin
from txdav.xml import element
from txdav.xml.base import encodeXMLName
from txdav.xml.element import dav_namespace
from twext.web2.dav.http import MultiStatusResponse
from twext.web2.dav.static import DAVFile as SuperDAVFile
@@ -339,8 +340,8 @@ def gotError(f, name):
whenAllProperties = gatherResults([
maybeDeferred(self.resource.readProperty, qn, request)
.addCallback(lambda p, iqn=qn: (p.sname(), p.toxml())
if p is not None else ("{%s}%s" % iqn, None) )
.addErrback(gotError, "{%s}%s" % qn)
if p is not None else (encodeXMLName(*iqn), None) )
.addErrback(gotError, encodeXMLName(*qn))
for qn in sorted(qnames)
])

@@ -771,7 +772,7 @@ def __init__(self, qname):
HTTPError.__init__(self,
StatusResponse(
responsecode.NOT_FOUND,
"No such property: {%s}%s" % qname
"No such property: %s" % encodeXMLName(*qname)
)
)

@@ -36,6 +36,7 @@
from twext.python.memcacheclient import ClientFactory
from twext.python.memcacheclient import MemcacheError, TokenMismatchError
from twext.python.filepath import CachingFilePath as FilePath
from txdav.xml.base import encodeXMLName
from twext.web2 import responsecode
from twext.web2.http import HTTPError, StatusResponse

@@ -293,11 +294,10 @@ def setProperty(self, child, property, uid, delete=False):
else:
log.error("memcacheprops setProperty had too many failures")
delattr(self, "_propertyCache")
raise MemcacheError("Unable to %s property %s{%s}%s on %s" % (
raise MemcacheError("Unable to %s property %s%s on %s" % (
"delete" if delete else "set",
uid if uid else "",
qname[0],
qname[1],
encodeXMLName(*qname),
child
))

@@ -345,7 +345,7 @@ def get(self, qname, uid=None, cache=True):
else:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: %s{%s}%s" % (uid if uid else "", qname[0], qname[1],)
"No such property: %s%s" % (uid if uid else "", encodeXMLName(*qname))
))

self.log_debug("Read for %s%s on %s" % (
@@ -33,6 +33,7 @@
from twext.web2.http import HTTPError, StatusResponse
from twext.web2.dav.util import davXMLFromStream
from txdav.xml import element as davxml
from txdav.xml.base import encodeXMLName
from txdav.xml.element import lookupElement

from twext.python.log import Logger
@@ -78,7 +79,7 @@ def http_REPORT(self, request):
elif namespace == caldavxml.caldav_namespace:
request.submethod = "CalDAV:" + name
else:
request.submethod = "{%s}%s" % (namespace, name)
request.submethod = encodeXMLName(namespace, name)
else:
request.submethod = name

@@ -114,8 +115,8 @@ def to_method(namespace, name):
#
# Requested report is not supported.
#
log.err("Unsupported REPORT {%s}%s for resource %s (no method %s)"
% (namespace, name, self, method_name))
log.err("Unsupported REPORT %s for resource %s (no method %s)"
% (encodeXMLName(namespace, name), self, method_name))

raise HTTPError(ErrorResponse(
responsecode.FORBIDDEN,

0 comments on commit e9d8c08

Please sign in to comment.
You can’t perform that action at this time.