MCPcopy Create free account
hub / github.com/CloudPolis/webdav-client-python / is_dir

Method is_dir

webdav/client.py:808–868  ·  view source on GitHub ↗
(self, remote_path)

Source from the content-addressed store, hash-verified

806 raise NotConnection(self.webdav.hostname)
807
808 def is_dir(self, remote_path):
809
810 def parse(response, path):
811
812 try:
813 response_str = response.getvalue()
814 tree = etree.fromstring(response_str)
815
816 resps = tree.findall("{DAV:}response")
817
818 for resp in resps:
819 href = resp.findtext("{DAV:}href")
820 urn = unquote(href)
821
822 if path[-1] == Urn.separate:
823 if not path == urn:
824 continue
825 else:
826 path_with_sep = "{path}{sep}".format(path=path, sep=Urn.separate)
827 if not path == urn and not path_with_sep == urn:
828 continue
829 type = resp.find(".//{DAV:}resourcetype")
830 if type is None:
831 raise MethodNotSupported(name="is_dir", server=self.webdav.hostname)
832 dir_type = type.find("{DAV:}collection")
833
834 return True if dir_type is not None else False
835
836 raise RemoteResourceNotFound(path)
837
838 except etree.XMLSyntaxError:
839 raise MethodNotSupported(name="is_dir", server=self.webdav.hostname)
840
841 try:
842 urn = Urn(remote_path)
843 parent_urn = Urn(urn.parent())
844 if not self.check(urn.path()) and not self.check(Urn(remote_path, directory=True).path()):
845 raise RemoteResourceNotFound(remote_path)
846
847 response = BytesIO()
848
849 url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': parent_urn.quote()}
850 options = {
851 'URL': "{hostname}{root}{path}".format(**url),
852 'CUSTOMREQUEST': Client.requests['info'],
853 'HTTPHEADER': self.get_header('info'),
854 'WRITEDATA': response,
855 'NOBODY': 0
856 }
857
858 request = self.Request(options=options)
859
860 request.perform()
861 request.close()
862
863 path = "{root}{path}".format(root=self.webdav.root, path=urn.path())
864
865 return parse(response, path)

Callers 7

download_toMethod · 0.95
downloadMethod · 0.95
download_directoryMethod · 0.95
download_fileMethod · 0.95
pushMethod · 0.95
pullMethod · 0.95
is_dirMethod · 0.45

Calls 9

parentMethod · 0.95
checkMethod · 0.95
pathMethod · 0.95
quoteMethod · 0.95
get_headerMethod · 0.95
RequestMethod · 0.95
UrnClass · 0.90
NotConnectionClass · 0.85

Tested by

no test coverage detected