File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ import urllib
2+
3+ from upath .core import UniversalPath , _FSSpecAccessor
4+
5+
6+ class _HTTPAccessor (_FSSpecAccessor ):
7+ def __init__ (self , parsed_url , * args , ** kwargs ):
8+ super ().__init__ (parsed_url , * args , ** kwargs )
9+
10+ def argument_upath_self_to_filepath (self , func ):
11+ """if arguments are passed to the wrapped function, and if the first
12+ argument is a UniversalPath instance, that argument is replaced with
13+ the UniversalPath's path attribute
14+ """
15+ def wrapper (* args , ** kwargs ):
16+ if args :
17+ args = list (args )
18+ first_arg = args .pop (0 )
19+ if not kwargs .get ("path" ):
20+ if isinstance (first_arg , UniversalPath ):
21+ first_arg = str (first_arg )
22+ args .insert (0 , first_arg )
23+ args = tuple (args )
24+ else :
25+ new_url = self ._url .replace (path = kwargs ["path" ])
26+ unparsed = urllib .urlunparse (new_url )
27+ kwargs ["path" ] = unparsed
28+ return func (* args , ** kwargs )
29+ return wrapper
30+
31+
32+ class HTTPPath (UniversalPath ):
33+ _default_accessor = _HTTPAccessor
You can’t perform that action at this time.
0 commit comments