本文整理汇总了Python中txdav.xml.base.encodeXMLName函数的典型用法代码示例。如果您正苦于以下问题:Python encodeXMLName函数的具体用法?Python encodeXMLName怎么用?Python encodeXMLName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encodeXMLName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encodeXMLName
def test_encodeXMLName(self):
# No namespace
self.assertEquals(encodeXMLName(None, "name"), "name")
self.assertEquals(encodeXMLName("", "name"), "name")
# Normal case
self.assertEquals(encodeXMLName("namespace", "name"), "{namespace}name")
示例2: gotProperties
def gotProperties(qnames):
accessDeniedValue = object()
def gotError(f, name):
f.trap(HTTPError)
code = f.value.response.code
if code == responsecode.NOT_FOUND:
log.error("Property %s was returned by listProperties() "
"but does not exist for resource %s."
% (name, self.resource))
return (name, None)
if code == responsecode.UNAUTHORIZED:
return (name, accessDeniedValue)
return f
whenAllProperties = gatherResults([
maybeDeferred(self.resource.readProperty, qn, request)
.addCallback(lambda p, iqn=qn: (p.sname(), p.toxml())
if p is not None else (encodeXMLName(*iqn), None))
.addErrback(gotError, encodeXMLName(*qn))
for qn in sorted(qnames)
])
@whenAllProperties.addCallback
def gotValues(items):
for even, [name, value] in zip(cycle(["odd", "even"]), items):
if value is None:
value = tags.i("(no value)")
elif value is accessDeniedValue:
value = tags.i("(access forbidden)")
yield tag.clone().fillSlots(
even=even, name=name, value=value,
)
return whenAllProperties
示例3: get
def get(self, qname, uid=None):
"""
Retrieve the value of a property stored as an extended attribute on the
wrapped path.
@param qname: The property to retrieve as a two-tuple of namespace URI
and local name.
@param uid: The per-user identifier for per user properties.
@raise HTTPError: If there is no value associated with the given
property.
@return: A L{WebDAVDocument} representing the value associated with the
given property.
"""
try:
data = self.attrs.get(self._encode(qname, uid))
except KeyError:
raise HTTPError(StatusResponse(
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" % (encodeXMLName(*qname),)
))
else:
raise HTTPError(StatusResponse(
statusForFailure(Failure()),
"Unable to read property: %s" % (encodeXMLName(*qname),)
))
示例4: __init__
def __init__(self, qname):
HTTPError.__init__(self,
StatusResponse(
responsecode.NOT_FOUND,
"No such property: %s" % encodeXMLName(*qname)
)
)
示例5: setProperty
def setProperty(self, child, property, uid, delete=False):
propertyCache, key, childCache, token = self.childCache(child)
if delete:
qname = property
qnameuid = qname + (uid,)
if qnameuid in childCache:
del childCache[qnameuid]
else:
qname = property.qname()
qnameuid = qname + (uid,)
childCache[qnameuid] = property
client = self.memcacheClient()
if client is not None:
retries = 10
while retries:
try:
if client.set(
key, childCache, time=self.cacheTimeout,
token=token
):
# Success
break
except TokenMismatchError:
# The value in memcache has changed since we last
# fetched it
self.log.debug("memcacheprops setProperty TokenMismatchError; retrying...")
finally:
# Re-fetch the properties for this child
loaded = self._loadCache(childNames=(child.fp.basename(),))
propertyCache.update(loaded.iteritems())
retries -= 1
propertyCache, key, childCache, token = self.childCache(child)
if delete:
if qnameuid in childCache:
del childCache[qnameuid]
else:
childCache[qnameuid] = property
else:
self.log.error("memcacheprops setProperty had too many failures")
delattr(self, "_propertyCache")
raise MemcacheError("Unable to %s property %s%s on %s" % (
"delete" if delete else "set",
uid if uid else "",
encodeXMLName(*qname),
child
))
示例6: get
def get(self, qname):
try:
property = self._dict[qname]
except KeyError:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: %s" % (encodeXMLName(*qname),)
))
doc = element.WebDAVDocument.fromString(property)
return doc.root_element
示例7: _encodeKey
def _encodeKey(self, effective, compressNamespace=True):
qname, uid = effective
if compressNamespace:
namespace = self._namespaceCompress.get(qname.namespace,
qname.namespace)
else:
namespace = qname.namespace
result = urllib.quote(encodeXMLName(namespace, qname.name), safe="{}:")
if uid and uid != self._defaultUser:
result = uid + result
r = self.deadPropertyXattrPrefix + result
return r
示例8: get
def get(self, qname, uid=None, cache=True):
if cache:
propertyCache = self.propertyCache()
qnameuid = qname + (uid,)
if qnameuid in propertyCache:
return propertyCache[qnameuid]
else:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
"No such property: %s%s" % (uid if uid else "", encodeXMLName(*qname))
))
self.log_debug("Read for %s%s on %s" % (
("{%s}:" % (uid,)) if uid else "",
qname,
self.childPropertyStore.resource.fp.path
))
return self.childPropertyStore.get(qname, uid=uid)
示例9: toString
def toString(self):
return encodeXMLName(self.namespace, self.name)
示例10: HTTPError
if doc is None:
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, "REPORT request body may not be empty"))
#
# Parse request
#
namespace = doc.root_element.namespace
name = doc.root_element.name
if namespace:
if namespace == davxml.dav_namespace:
request.submethod = "DAV:" + name
elif namespace == caldavxml.caldav_namespace:
request.submethod = "CalDAV:" + name
else:
request.submethod = encodeXMLName(namespace, name)
else:
request.submethod = name
def to_method(namespace, name):
if namespace:
s = "_".join((namespace, name))
else:
s = name
ok = string.ascii_letters + string.digits + "_"
out = []
for c in s:
if c in ok:
out.append(c)
else:
示例11: to_method
def to_method(s):
out = []
for c in s:
if c in ok:
out.append(c)
else:
out.append("_")
return "report_" + "".join(out)
if namespace:
method_name = to_method("_".join((namespace, name)))
if namespace == davxml.dav_namespace:
request.submethod = "DAV:" + name
else:
request.submethod = encodeXMLName(namespace, name)
else:
method_name = to_method(name)
request.submethod = name
try:
method = getattr(self, method_name)
# Also double-check via supported-reports property
reports = self.supportedReports()
test = lookupElement((namespace, name))
if not test:
raise AttributeError()
test = davxml.Report(test())
if test not in reports:
示例12: action_readProperty
def action_readProperty(rootResource, directory, store, resource, qname):
property = (yield resource.readProperty(qname, None))
print("%r on %s:" % (encodeXMLName(*qname), resource))
print("")
print(property.toxml())
示例13: __repr__
def __repr__(self):
return "%s = %s" % (encodeXMLName(self.ns, self.name), self.value)
示例14: action_readProperty
def action_readProperty(resource, qname):
property = (yield resource.readProperty(qname, None))
print "%r on %s:" % (encodeXMLName(*qname), resource)
print ""
print property.toxml()
示例15: encodeXMLName
"REPORT request body may not be empty"
))
#
# Parse request
#
namespace = doc.root_element.namespace
name = doc.root_element.name
if namespace:
if namespace == davxml.dav_namespace:
request.submethod = "DAV:" + name
elif namespace == caldavxml.caldav_namespace:
request.submethod = "CalDAV:" + name
else:
request.submethod = encodeXMLName(namespace, name)
else:
request.submethod = name
def to_method(namespace, name):
if namespace:
s = "_".join((namespace, name))
else:
s = name
ok = string.ascii_letters + string.digits + "_"
out = []
for c in s:
if c in ok:
out.append(c)