webdav3/client.py: WebDavXmlUtils.extract_response_for_path method now is able to parse an absolute links
This commit is contained in:
		
							parent
							
								
									c5e0511178
								
							
						
					
					
						commit
						d1f17f6fb0
					
				
					 1 changed files with 13 additions and 12 deletions
				
			
		|  | @ -16,9 +16,10 @@ from webdav3.exceptions import * | ||||||
| from webdav3.urn import Urn | from webdav3.urn import Urn | ||||||
| 
 | 
 | ||||||
| try: | try: | ||||||
|     from urllib.parse import unquote |     from urllib.parse import unquote, urlsplit | ||||||
| except ImportError: | except ImportError: | ||||||
|     from urllib import unquote |     from urllib import unquote | ||||||
|  |     from urlparse import urlsplit | ||||||
| 
 | 
 | ||||||
| __version__ = "0.2" | __version__ = "0.2" | ||||||
| log = logging.getLogger(__name__) | log = logging.getLogger(__name__) | ||||||
|  | @ -961,20 +962,20 @@ class WebDavXmlUtils: | ||||||
|         try: |         try: | ||||||
|             tree = etree.fromstring(content) |             tree = etree.fromstring(content) | ||||||
|             responses = tree.findall("{DAV:}response") |             responses = tree.findall("{DAV:}response") | ||||||
|  | 
 | ||||||
|  |             def normalization_fn(p): | ||||||
|  |                 result = (sub, '/{2,}', '/') | ||||||
|  |                 return result if result[-1] != Urn.separate else result[:-1] | ||||||
|  | 
 | ||||||
|  |             normalized_path = normalization_fn(path) | ||||||
|  | 
 | ||||||
|             for resp in responses: |             for resp in responses: | ||||||
|                 href = resp.findtext("{DAV:}href") |                 href = resp.findtext("{DAV:}href") | ||||||
|                 urn = unquote(href) |  | ||||||
| 
 | 
 | ||||||
|                 if path[-1] == Urn.separate: |                 urn = unquote(urlsplit(href).path) | ||||||
|                     # remove / from path to compare with urn | 
 | ||||||
|                     # e.g. /path = /path |                 if normalized_path == normalization_fn(urn): | ||||||
|                     if not path[:-1] == urn: |                     return resp | ||||||
|                         continue |  | ||||||
|                 else: |  | ||||||
|                     path_with_sep = "{path}{sep}".format(path=path, sep=Urn.separate) |  | ||||||
|                     if not path == urn and not path_with_sep == urn: |  | ||||||
|                         continue |  | ||||||
|                 return resp |  | ||||||
|             raise RemoteResourceNotFound(path) |             raise RemoteResourceNotFound(path) | ||||||
|         except etree.XMLSyntaxError: |         except etree.XMLSyntaxError: | ||||||
|             raise MethodNotSupported(name="is_dir", server=hostname) |             raise MethodNotSupported(name="is_dir", server=hostname) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue