def parse(self, data, dav='DAV:'): root = XmlParser().parse(data) info = root.elements('lockinfo', ns=dav)[0] ls = info.elements('lockscope', ns=dav)[0] self.scope = ls.elements()[0].name() lt = info.elements('locktype', ns=dav)[0] self.type = lt.elements()[0].name() lockowner = info.elements('owner', ns=dav) if lockowner: # Since the Owner element may contain children in different # namespaces (or none at all), we have to find them for potential # remapping. Note that Cadaver doesn't use namespaces in the # XML it sends. lockowner = lockowner[0] for el in lockowner.elements(): name, elns = el.name(), el.namespace() if not elns: # There's no namespace, so we have to add one lockowner.remap({dav:'ot'}) el.__nskey__ = 'ot' for subel in el.elements(): if not subel.namespace(): el.__nskey__ = 'ot' else: el.remap({dav:'o'}) self.owner = lockowner.strval()
def parse(self, request, dav='DAV:'): self.depth=request.get_header('Depth', 'infinity') if not (self.depth in ('0','1','infinity')): raise 'Bad Request', 'Invalid Depth header.' body=request.get('BODY', '') self.allprop=(not len(body)) if not body: return try: root=XmlParser().parse(body) except: raise 'Bad Request', sys.exc_info()[1] e=root.elements('propfind', ns=dav) if not e: raise 'Bad Request', 'Invalid xml request.' e=e[0] if e.elements('allprop', ns=dav): self.allprop=1 return if e.elements('propname', ns=dav): self.propname=1 return prop=e.elements('prop', ns=dav) if not prop: raise 'Bad Request', 'Invalid xml request.' prop=prop[0] for val in prop.elements(): self.propnames.append((val.name(), val.namespace())) if (not self.allprop) and (not self.propname) and \ (not self.propnames): raise 'Bad Request', 'Invalid xml request.' return
def parse(self, request, dav='DAV:'): body=request.get('BODY', '') try: root=XmlParser().parse(body) except: raise BadRequest, sys.exc_info()[1] vals=self.values e=root.elements('propertyupdate', ns=dav) if not e: raise BadRequest, 'Invalid xml request.' e=e[0] for ob in e.elements(): if ob.name()=='set' and ob.namespace()==dav: proptag=ob.elements('prop', ns=dav) if not proptag: raise BadRequest, 'Invalid xml request.' proptag=proptag[0] for prop in proptag.elements(): # We have to ensure that all tag attrs (including # an xmlns attr for all xml namespaces used by the # element and its children) are saved, per rfc2518. name, ns=prop.name(), prop.namespace() e, attrs=prop.elements(), prop.attrs() if (not e) and (not attrs): # simple property item=(name, ns, prop.strval(), {}) vals.append(item) else: # xml property attrs={} prop.remap({ns:'n'}) prop.del_attr('xmlns:n') for attr in prop.attrs(): attrs[attr.qname()]=attr.value() md={'__xml_attrs__':attrs} item=(name, ns, prop.strval(), md) vals.append(item) if ob.name()=='remove' and ob.namespace()==dav: proptag=ob.elements('prop', ns=dav) if not proptag: raise BadRequest, 'Invalid xml request.' proptag=proptag[0] for prop in proptag.elements(): item=(prop.name(), prop.namespace()) vals.append(item)