@@ -81,23 +81,81 @@ def __init__(
8181 def __repr__ (self ):
8282 return f"<ServerContext [ { self ._domain } | { self ._context_path } | { self ._container_path } ]>"
8383
84- def build_url (self , controller : str , action : str , container_path : str = None ) -> str :
85- sep = "/"
84+ @property
85+ def hostname (self ) -> str :
86+ return self ._scheme + self ._domain
8687
87- url = self ._scheme + self ._domain
88+ @property
89+ def base_url (self ) -> str :
90+ base_url = self .hostname
8891
8992 if self ._context_path is not None :
90- url += sep + self ._context_path
93+ base_url += "/" + self ._context_path
94+
95+ return base_url
96+
97+ def build_url (self , controller : str , action : str , container_path : str = None ) -> str :
98+ url = self .base_url
9199
92100 if container_path is not None :
93- url += sep + container_path
101+ url += "/" + container_path
94102 elif self ._container_path is not None :
95- url += sep + self ._container_path
103+ url += "/" + self ._container_path
96104
97- url += sep + controller + "-" + action
105+ url += "/" + controller + "-" + action
98106
99107 return url
100108
109+ def webdav_path (self , container_path : str = None , file_name : str = None ):
110+ path = "/_webdav"
111+ container_path = container_path or self ._container_path
112+
113+ if container_path is not None :
114+ if container_path .endswith ("/" ):
115+ # trim the slash
116+ container_path = container_path [0 :- 1 ]
117+
118+ if not container_path .startswith ("/" ):
119+ path += "/"
120+
121+ path += container_path
122+
123+ path += "/@files"
124+
125+ if file_name is not None :
126+ if not file_name .startswith ("/" ):
127+ path += "/"
128+
129+ path += file_name
130+
131+ return path
132+
133+ def webdav_client (self , webdav_options : dict = None ):
134+ # We localize the import of webdav3 here so it is an optional dependency. Only users who want to use webdav will
135+ # need to pip install webdavclient3
136+ from webdav3 .client import Client
137+
138+ options = {
139+ "webdav_hostname" : self .base_url ,
140+ }
141+
142+ if self ._api_key is not None :
143+ options ["webdav_login" ] = "apikey"
144+ options ["webdav_password" ] = f"apikey|{ self ._api_key } "
145+
146+ if webdav_options is not None :
147+ options = {
148+ ** options ,
149+ ** webdav_options ,
150+ }
151+
152+ client = Client (options )
153+
154+ if self ._verify_ssl is False :
155+ client .verify = False # Set verify to false if using localhost without HTTPS
156+
157+ return client
158+
101159 def handle_request_exception (self , exception ):
102160 if type (exception ) in [RequestAuthorizationError , QueryNotFoundError , ServerNotFoundError ]:
103161 raise exception
0 commit comments