Ejemplo n.º 1
0
    def tree_action(self):
        """ copy a tree of resources (a collection)

        Here we return a multistatus xml element.

        """
        dc=self.__dataclass
        base=self.__src

        ### some basic tests
        # test if dest exists and overwrite is false
        if dc.exists(self.__dst) and not self.__overwrite: raise DAV_Error, 412
        # test if src and dst are the same
        # (we assume that both uris are on the same server!)
        ps=urlparse.urlparse(self.__src)[2]
        pd=urlparse.urlparse(self.__dst)[2]
        if ps==pd: raise DAV_Error, 403
        
        
        result=dc.copytree(self.__src,self.__dst,self.__overwrite)
        #result=copytree(dc,self.__src,self.__dst,self.__overwrite)

        if not result: return None

        ###
        ### create the multistatus XML element
        ### (this is also the same as in delete.py.
        ###  we might make a common method out of it)
        ###

        doc = Document(None)
        ms=doc.createElement("D:multistatus")
        ms.setAttribute("xmlns:D","DAV:")
        doc.appendChild(ms)

        for el,ec in result.items():
                re=doc.createElement("D:response")
                hr=doc.createElement("D:href")
                st=doc.createElement("D:status")
                huri=doc.createTextNode(quote_uri(el))
                t=doc.createTextNode(gen_estring(ec))
                st.appendChild(t)
                hr.appendChild(huri)
                re.appendChild(hr)
                re.appendChild(st)
                ms.appendChild(re)
 
        sfile=StringIO()
        ext.PrettyPrint(doc,stream=sfile)
        s=sfile.getvalue()
        sfile.close()
        return s
Ejemplo n.º 2
0
    def tree_action(self):
        """ copy a tree of resources (a collection)

        Here we return a multistatus xml element.

        """
        dc = self.__dataclass
        base = self.__src

        ### some basic tests
        # test if dest exists and overwrite is false
        if dc.exists(self.__dst) and not self.__overwrite: raise DAV_Error, 412
        # test if src and dst are the same
        # (we assume that both uris are on the same server!)
        ps = urlparse.urlparse(self.__src)[2]
        pd = urlparse.urlparse(self.__dst)[2]
        if ps == pd: raise DAV_Error, 403

        result = dc.copytree(self.__src, self.__dst, self.__overwrite)
        #result=copytree(dc,self.__src,self.__dst,self.__overwrite)

        if not result: return None

        ###
        ### create the multistatus XML element
        ### (this is also the same as in delete.py.
        ###  we might make a common method out of it)
        ###

        doc = Document(None)
        ms = doc.createElement("D:multistatus")
        ms.setAttribute("xmlns:D", "DAV:")
        doc.appendChild(ms)

        for el, ec in result.items():
            re = doc.createElement("D:response")
            hr = doc.createElement("D:href")
            st = doc.createElement("D:status")
            huri = doc.createTextNode(quote_uri(el))
            t = doc.createTextNode(gen_estring(ec))
            st.appendChild(t)
            hr.appendChild(huri)
            re.appendChild(hr)
            re.appendChild(st)
            ms.appendChild(re)

        sfile = StringIO()
        ext.PrettyPrint(doc, stream=sfile)
        s = sfile.getvalue()
        sfile.close()
        return s
Ejemplo n.º 3
0
    def mk_prop_response(self,uri,good_props,bad_props,doc):
        """ make a new <prop> result element 

        We differ between the good props and the bad ones for
        each generating an extra <propstat>-Node (for each error
        one, that means).

        """
        re=doc.createElement("D:response")
        # append namespaces to response
        nsnum=0
        for nsname in self.namespaces:
            if nsname != 'DAV:':
                re.setAttribute("xmlns:ns"+str(nsnum),nsname)
            nsnum=nsnum+1

        if self._dataclass.baseurl:
            uri = self._dataclass.baseurl + '/' + '/'.join(uri.split('/')[3:])

        # write href information
        uparts=urlparse.urlparse(uri)
        fileloc=uparts[2]
        href=doc.createElement("D:href")

        huri=doc.createTextNode(uparts[0]+'://'+'/'.join(uparts[1:2]) + urllib.quote(fileloc))
        href.appendChild(huri)
        re.appendChild(href)

        # write good properties
        ps=doc.createElement("D:propstat")
        if good_props:
            re.appendChild(ps)

        gp=doc.createElement("D:prop")
        for ns in good_props.keys():
            if ns != 'DAV:':
                ns_prefix="ns"+str(self.namespaces.index(ns))+":"
            else:
                ns_prefix = 'D:'
            for p,v in good_props[ns].items():

                pe=doc.createElement(ns_prefix+str(p))
                if hasattr(v, '__class__') and v.__class__.__name__ == 'Element':
                    pe.appendChild(v)
                elif isinstance(v, list):
                    for val in v:
                        pe.appendChild(val)
                else:
                    if p=="resourcetype":
                        if v==1:
                            ve=doc.createElement("D:collection")
                            pe.appendChild(ve)
                    else:
                        ve=doc.createTextNode(v)
                        pe.appendChild(ve)

                gp.appendChild(pe)

        ps.appendChild(gp)
        s=doc.createElement("D:status")
        t=doc.createTextNode("HTTP/1.1 200 OK")
        s.appendChild(t)
        ps.appendChild(s)
        re.appendChild(ps)

        # now write the errors!
        if len(bad_props.items()):

            # write a propstat for each error code
            for ecode in bad_props.keys():
                ps=doc.createElement("D:propstat")
                re.appendChild(ps)
                bp=doc.createElement("D:prop")
                ps.appendChild(bp)

                for ns in bad_props[ecode].keys():
                    if ns != 'DAV:':
                        ns_prefix="ns"+str(self.namespaces.index(ns))+":"
                    else:
                        ns_prefix = 'D:'

                    for p in bad_props[ecode][ns]:
                        pe=doc.createElement(ns_prefix+str(p))
                        bp.appendChild(pe)

                s=doc.createElement("D:status")
                t=doc.createTextNode(utils.gen_estring(ecode))
                s.appendChild(t)
                ps.appendChild(s)
                re.appendChild(ps)

        # return the new response element
        return re
Ejemplo n.º 4
0
    def mk_prop_response(self, uri, good_props, bad_props, doc):
        """ make a new <prop> result element

        We differ between the good props and the bad ones for
        each generating an extra <propstat>-Node (for each error
        one, that means).

        """
        re = doc.createElement("D:response")
        # append namespaces to response
        nsnum = 0
        for nsname in self.namespaces:
            if nsname != 'DAV:':
                re.setAttribute("xmlns:ns" + str(nsnum), nsname)
            nsnum += 1

        print 'URI BEFORE',uri
        if self._dataclass.baseurl:
            uri = self._dataclass.baseurl + '/' + '/'.join(uri.split('/')[3:])
        print 'URI AFTER',uri

        # write href information
        uparts = urlparse.urlparse(uri)
        fileloc = uparts[2]
        href = doc.createElement("D:href")

        huri_text=uparts[0] + '://' + '/'.join(uparts[1:2]) + urllib.quote(fileloc)
        huri = doc.createTextNode(huri_text)

        print '#### huri',huri_text

        href.appendChild(huri)
        re.appendChild(href)

        # write good properties
        ps = doc.createElement("D:propstat")
        if good_props:
            re.appendChild(ps)

        gp = doc.createElement("D:prop")
        for ns in good_props.keys():
            if ns != 'DAV:':
                ns_prefix = "ns" + str(self.namespaces.index(ns)) + ":"
            else:
                ns_prefix = 'D:'
            for p, v in good_props[ns].items():

                pe = doc.createElement(ns_prefix + str(p))
                if isinstance(v, xml.dom.minidom.Element):
                    pe.appendChild(v)
                elif isinstance(v, list):
                    for val in v:
                        pe.appendChild(val)
                else:
                    if p == "resourcetype":
                        if v == 1:
                            ve = doc.createElement("D:collection")
                            pe.appendChild(ve)
                    else:
                        ve = doc.createTextNode(v)
                        pe.appendChild(ve)

                gp.appendChild(pe)

        ps.appendChild(gp)
        s = doc.createElement("D:status")
        t = doc.createTextNode("HTTP/1.1 200 OK")
        s.appendChild(t)
        ps.appendChild(s)
        re.appendChild(ps)

        # SKIP BAD PROPS ALTOGETHER...
        #return re

        # now write the errors!
        if len(bad_props.items()):

            # write a propstat for each error code
            for ecode in bad_props.keys():
                ps = doc.createElement("D:propstat")
                re.appendChild(ps)
                bp = doc.createElement("D:prop")
                ps.appendChild(bp)

                for ns in bad_props[ecode].keys():
                    if ns != 'DAV:':
                        ns_prefix = "ns" + str(self.namespaces.index(ns)) + ":"
                    else:
                        ns_prefix = 'D:'

                    for p in bad_props[ecode][ns]:
                        pe = doc.createElement(ns_prefix + str(p))
                        bp.appendChild(pe)

                s = doc.createElement("D:status")
                t = doc.createTextNode(utils.gen_estring(ecode))
                s.appendChild(t)
                ps.appendChild(s)
                re.appendChild(ps)

        # return the new response element
        return re
Ejemplo n.º 5
0
	def mk_prop_response(self,uri,good_props,bad_props,doc):
	    """ make a new <prop> result element 

	    We differ between the good props and the bad ones for
	    each generating an extra <propstat>-Node (for each error
	    one, that means).
	    
	    """
	    re=doc.createElement("D:response")
	    # append namespaces to response
	    nsnum=0
	    for nsname in self.namespaces:
		re.setAttribute("xmlns:ns"+str(nsnum),nsname)
		nsnum=nsnum+1
	    
	    # write href information
	    uparts=urlparse.urlparse(uri)
	    fileloc=uparts[2]
	    href=doc.createElement("D:href")
	    huri=doc.createTextNode(urllib.quote(fileloc))
	    href.appendChild(huri)
	    re.appendChild(href)

	    # write good properties
	    if good_props:
		ps=doc.createElement("D:propstat")
		re.appendChild(ps)
		gp=doc.createElement("D:prop")
		for ns in good_props.keys():
		    ns_prefix="ns"+str(self.namespaces.index(ns))+":"
		    for p,v in good_props[ns].items():
			pe=doc.createElement(ns_prefix+str(p))
			if p=="resourcetype":
			    if v=="1":
				ve=doc.createElement("D:collection")
				pe.appendChild(ve)
			else:
			    ve=doc.createTextNode(str(v))
			    pe.appendChild(ve)
			gp.appendChild(pe)
		ps.appendChild(gp)
		s=doc.createElement("D:status")
		t=doc.createTextNode("HTTP/1.1 200 OK")
		s.appendChild(t)
		ps.appendChild(s)
		re.appendChild(ps)

	    # now write the errors!
	    if len(bad_props.items()):
		# write a propstat for each error code
		for ecode in bad_props.keys():
		    ps=doc.createElement("D:propstat")
		    re.appendChild(ps)
		    bp=doc.createElement("D:prop")
		    ps.appendChild(bp)
		    for ns in bad_props[ecode].keys():
			ns_prefix="ns"+str(self.namespaces.index(ns))+":"
			for p in bad_props[ecode][ns]:
			    pe=doc.createElement(ns_prefix+str(p))
			    bp.appendChild(pe)
		    s=doc.createElement("D:status")
		    t=doc.createTextNode(utils.gen_estring(ecode))
		    s.appendChild(t)
		    ps.appendChild(s)
		    re.appendChild(ps)

	    # return the new response element
	    return re
Ejemplo n.º 6
0
    def mk_prop_response(self,uri,good_props,bad_props,doc):
        """ make a new <prop> result element 

        We differ between the good props and the bad ones for
        each generating an extra <propstat>-Node (for each error
        one, that means).
        
        """
        re=doc.createElement("D:response")
        # append namespaces to response
        nsnum=0
        for nsname in self.namespaces:
            re.setAttribute("xmlns:ns"+str(nsnum),nsname)
            nsnum=nsnum+1
        
        # write href information
        uparts=urlparse.urlparse(uri)
        fileloc=uparts[2]
        href=doc.createElement("D:href")
        huri=doc.createTextNode(uparts[0]+'://'+'/'.join(uparts[1:2]) + urllib.quote(fileloc))
        href.appendChild(huri)
        re.appendChild(href)

        # write good properties
        ps=doc.createElement("D:propstat")
        if good_props:
            re.appendChild(ps)

        gp=doc.createElement("D:prop")
        for ns in good_props.keys():
            ns_prefix="ns"+str(self.namespaces.index(ns))+":"
            for p,v in good_props[ns].items():
                pe=doc.createElement(ns_prefix+str(p))
                if p=="resourcetype":
                    self._log(v)
                    if v=="1":
                        ve=doc.createElement("D:collection")
                        pe.appendChild(ve)
                    elif v=="2":
                        # Calendar collection (XXX: do something smart instead)
                        pe.setAttribute("xmlns:C", "urn:ietf:params:xml:ns:caldav")
                        ve=doc.createElement("D:collection")
                        pe.appendChild(ve)
                        ve=doc.createElement("C:calendar")
                        pe.appendChild(ve)
                else:
                    if isinstance(v, xml.dom.minidom.Element):
                        # Allow xml data in properties
                        ve = v
                    else:
                        ve=doc.createTextNode(str(v))

                    pe.appendChild(ve)

                gp.appendChild(pe)
        
        ps.appendChild(gp)
        s=doc.createElement("D:status")
        t=doc.createTextNode("HTTP/1.1 200 OK")
        s.appendChild(t)
        ps.appendChild(s)
        re.appendChild(ps)

        # now write the errors!
        if len(bad_props.items()):

            # write a propstat for each error code
            for ecode in bad_props.keys():
                ps=doc.createElement("D:propstat")
                re.appendChild(ps)
                bp=doc.createElement("D:prop")
                ps.appendChild(bp)

                for ns in bad_props[ecode].keys():
                    ns_prefix="ns"+str(self.namespaces.index(ns))+":"
                
                for p in bad_props[ecode][ns]:
                    pe=doc.createElement(ns_prefix+str(p))
                    bp.appendChild(pe)
                
                s=doc.createElement("D:status")
                t=doc.createTextNode(utils.gen_estring(ecode))
                s.appendChild(t)
                ps.appendChild(s)
                re.appendChild(ps)

        # return the new response element
        return re
Ejemplo n.º 7
0
    def mk_prop_response(self, uri, good_props, bad_props, doc):
        """ make a new <prop> result element 

	    We differ between the good props and the bad ones for
	    each generating an extra <propstat>-Node (for each error
	    one, that means).
	    
	    """
        re = doc.createElement("D:response")
        # append namespaces to response
        nsnum = 0
        for nsname in self.namespaces:
            re.setAttribute("xmlns:ns" + str(nsnum), nsname)
            nsnum = nsnum + 1

        # write href information
        uparts = urlparse.urlparse(uri)
        fileloc = uparts[2]
        href = doc.createElement("D:href")
        huri = doc.createTextNode(urllib.quote(fileloc))
        href.appendChild(huri)
        re.appendChild(href)

        # write good properties
        if good_props:
            ps = doc.createElement("D:propstat")
            re.appendChild(ps)
            gp = doc.createElement("D:prop")
            for ns in good_props.keys():
                ns_prefix = "ns" + str(self.namespaces.index(ns)) + ":"
                for p, v in good_props[ns].items():
                    pe = doc.createElement(ns_prefix + str(p))
                    if p == "resourcetype":
                        if v == "1":
                            ve = doc.createElement("D:collection")
                            pe.appendChild(ve)
                    else:
                        ve = doc.createTextNode(str(v))
                        pe.appendChild(ve)
                    gp.appendChild(pe)
            ps.appendChild(gp)
            s = doc.createElement("D:status")
            t = doc.createTextNode("HTTP/1.1 200 OK")
            s.appendChild(t)
            ps.appendChild(s)
            re.appendChild(ps)

        # now write the errors!
        if len(bad_props.items()):
            # write a propstat for each error code
            for ecode in bad_props.keys():
                ps = doc.createElement("D:propstat")
                re.appendChild(ps)
                bp = doc.createElement("D:prop")
                ps.appendChild(bp)
                for ns in bad_props[ecode].keys():
                    ns_prefix = "ns" + str(self.namespaces.index(ns)) + ":"
                    for p in bad_props[ecode][ns]:
                        pe = doc.createElement(ns_prefix + str(p))
                        bp.appendChild(pe)
                s = doc.createElement("D:status")
                t = doc.createTextNode(utils.gen_estring(ecode))
                s.appendChild(t)
                ps.appendChild(s)
                re.appendChild(ps)

        # return the new response element
        return re