def test_url_replace_path(): url = "https://[email protected]/original/path;p=par?q=quer#frag" u = HTTPURLInfo(url) new_u = u.replace("/new/path") assert u.path == "/original/path" assert new_u.path == "/new/path" assert u.scheme == new_u.scheme assert u.host == new_u.host assert u.user == new_u.user assert u.params == new_u.params assert u.query == new_u.query assert u.fragment == new_u.fragment
def test_https_url_info_str(): url = "https://[email protected]/test1;p=par?q=quer#frag" u = HTTPURLInfo(url) assert u.url == url assert str(u) == u.url assert u.params == "p=par" assert u.query == "q=quer" assert u.fragment == "frag"
def __init__(self, repo, config): # Call BaseFileSystem constructor super().__init__(repo, config) # Get username from configuration self.user = config.get("user", None) # Get password from configuration (might be None ~ not set) self.password = config.get("password", None) # Whether to ask for password if it is not set self.ask_password = config.get("ask_password", False) # Use token for webdav auth self.token = config.get("token", None) # Path to certificate self.cert_path = config.get("cert_path", None) # Path to private key self.key_path = config.get("key_path", None) # Connection timeout self.timeout = config.get("timeout", 30) # Get URL from configuration self.url = config.get("url", None) # If URL in config parse path_info if self.url: self.path_info = self.PATH_CLS(self.url) # If username not specified try to use from URL if self.user is None and self.path_info.user is not None: self.user = self.path_info.user # Construct hostname from path_info by stripping path http_info = HTTPURLInfo(self.path_info.url) self.hostname = http_info.replace(path="").url
def _client(self): from webdav3.client import Client # Construct hostname from path_info by stripping path http_info = HTTPURLInfo(self.path_info.url) hostname = http_info.replace(path="").url # Set password or ask for it if self.ask_password and self.password is None and self.token is None: host, user = self.path_info.host, self.path_info.user self.password = ask_password(host, user) # Setup webdav client options dictionary options = { "webdav_hostname": hostname, "webdav_login": self.user, "webdav_password": self.password, "webdav_token": self.token, "webdav_cert_path": self.cert_path, "webdav_key_path": self.key_path, "webdav_timeout": self.timeout, "webdav_chunk_size": self.CHUNK_SIZE, } client = Client(options) # Check whether client options are valid if not client.valid(): raise ConfigError( f"Configuration for WebDAV {hostname} is invalid." ) # Check whether connection is valid (root should always exist) if not client.check(self.path_info.path): raise WebDAVConnectionError(hostname) return client