def __init__(self, value): try: self.scheme = None self.host = None self.port = None self.path = "" self.query = "" self.fragment = "" if value == None: return if value.startswith("file://") or value.startswith("//"): # urlparse DOES NOT WORK IN THESE CASES scheme, suffix = value.split("//", 1) self.scheme = scheme.rstrip(":") parse(self, suffix, 0, 1) self.query = wrap(url_param2value(self.query)) else: output = urlparse(value) self.scheme = output.scheme self.port = output.port self.host = output.netloc.split(":")[0] self.path = output.path self.query = wrap(url_param2value(output.query)) self.fragment = output.fragment except Exception as e: if not _Log: _late_import() _Log.error(u"problem parsing {{value}} to URL", value=value, cause=e)
def __init__(self, value, port=None, path=None, query=None, fragment=None): if isinstance(value, URL): return try: self.scheme = None self.host = None self.port = port self.path = path self.query = query self.fragment = fragment if value == None: return if value.startswith("file://") or value.startswith("//"): # urlparse DOES NOT WORK IN THESE CASES scheme, suffix = value.split("//", 2) self.scheme = scheme.rstrip(":") parse(self, suffix, 0, 1) self.query = wrap(url_param2value(self.query)) else: output = urlparse(value) self.scheme = output.scheme self.port = coalesce(port, output.port) self.host = output.netloc.split(":")[0] self.path = coalesce(path, output.path) self.query = coalesce(query, wrap(url_param2value(output.query))) self.fragment = coalesce(fragment, output.fragment) except Exception as e: Log.error(u"problem parsing {{value}} to URL", value=value, cause=e)
def __init__(self, value, port=None, path=None, query=None, fragment=None): try: self.scheme = None self.host = None self.port = port self.path = path self.query = query self.fragment = fragment if value == None: return if value.startswith("file://") or value.startswith("//"): # urlparse DOES NOT WORK IN THESE CASES scheme, suffix = value.split("//", 2) self.scheme = scheme.rstrip(":") parse(self, suffix, 0, 1) self.query = wrap(url_param2value(self.query)) else: output = urlparse(value) self.scheme = output.scheme self.port = coalesce(port, output.port) self.host = output.netloc.split(":")[0] self.path = coalesce(path, output.path) self.query = coalesce(query, wrap(url_param2value(output.query))) self.fragment = coalesce(fragment, output.fragment) except Exception as e: Log.error(u"problem parsing {{value}} to URL", value=value, cause=e)