(self, remote_path)
| 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) |
no test coverage detected