Exemplo n.º 1
0
    def gen_prop_tree(self, props, only_names=False):
        XMLroot = ET.Element("{DAV:}multistatus")
        XMLresp = ET.SubElement(XMLroot, "{DAV:}response")

        # depth==0: only this resource
        resources = [self.path]
        # depth==1: add resources of the collection
        if self.depth == "1":
            ##FIXME: fix unicode (most errors here!)
            resources.extend([path_join(self.path, res) for res in vfs.listdir(self.path)])

        for res in resources:
            XMLres_href = ET.SubElement(XMLresp, "{DAV:}href")
            XMLres_href.text = res
            XMLres_propstat = ET.SubElement(XMLresp, "{DAV:}propstat")
            XMLres_propstat_prop = ET.SubElement(XMLres_propstat, "{DAV:}prop")

            res_info = vfs.getinfo(res)
            if "{DAV:}creationdate" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}creationdate")
                if not only_names:
                    prop.text = res_info["created_time"].strftime("%Y-%m-%dT%H:%M:%SZ")
            if "{DAV:}getcontentlength" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}getcontentlength")
                if not only_names:
                    prop.text = str(res_info["size"])
            if "{DAV:}getlastmodified" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}getlastmodified")
                if not only_names:
                    prop.text = res_info["modified_time"].strftime("%Y-%m-%dT%H:%M:%SZ")
            if "{DAV:}resourcetype" in props:
                restype = ET.SubElement(XMLres_propstat_prop, "{DAV:}resourcetype")
                if not only_names and vfs.isdir(res):
                    ET.SubElement(restype, "{DAV:}collection")
            ##FIXME: add DAV:supportedlock and DAV:lockdiscovery

            XMLres_propstat_status = ET.SubElement(XMLres_propstat, "{DAV:}status")
            XMLres_propstat_status.text = "HTTP/1.1 200 OK"
            # XMLres_propstat_status = ET.SubElement(XMLres_propstat, '{DAV:}status')
            # XMLres_propstat_status.text = 'HTTP/1.1 403 Forbidden'
            # XMLres_propstat_responsedescription = ET.SubElement(XMLres_propstat, '{DAV:}responsedescription')
            # XMLres_propstat_responsedescription.text = 'There has been an access violation error.'
        return XMLroot