當前位置: 首頁>>代碼示例>>Python>>正文


Python parse.urlparse方法代碼示例

本文整理匯總了Python中urllib.parse.urlparse方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.urlparse方法的具體用法?Python parse.urlparse怎麽用?Python parse.urlparse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib.parse的用法示例。


在下文中一共展示了parse.urlparse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_connection

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def get_connection(self, url, proxies=None):
        proxies = proxies or {}
        proxy = proxies.get(urlparse(url.lower()).scheme)

        if proxy:
            raise ValueError('%s does not support specifying proxies' %
                             self.__class__.__name__)

        with self.pools.lock:
            pool = self.pools.get(url)
            if pool:
                return pool

            pool = UsbmuxHTTPConnectionPool(url, self.timeout)
            self.pools[url] = pool

        return pool 
開發者ID:openatx,項目名稱:facebook-wda,代碼行數:19,代碼來源:requests_usbmux.py

示例2: get_plugin_config

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def get_plugin_config(config_uri):
    """
    Downloads/opens configuration yaml file, returns
    dict of Galaxy plugins
    """
    # Try to open the URI as a URL or fall back to opening local file
    try:
        config_uri_parsed = urlparse(config_uri)
        if config_uri_parsed.scheme in ['https', 'http']:
            url = urlopen(config_uri)
            yaml_data = url.read()
        else:
            with open(config_uri, 'r') as file_data:
                yaml_data = file_data.read()
    except URLError as e:
        print(e)

    # Parse the YAML configuration
    try:
        plugin_data = yaml.safe_load(yaml_data)

        return plugin_data['plugins']
    except yaml.YAMLError as e:
        print(e) 
開發者ID:Slashbunny,項目名稱:gog-galaxy-plugin-downloader,代碼行數:26,代碼來源:download.py

示例3: urlParser

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def urlParser(target):
    log = logging.getLogger('urlparser')

    ssl = False
    o = urlparse(target)
    if o[0] not in ['http', 'https', '']:
        log.error('scheme %s not supported' % o[0])
        return
    if o[0] == 'https':
        ssl = True
    if len(o[2]) > 0:
        path = o[2]
    else:
        path = '/'
    tmp = o[1].split(':')
    if len(tmp) > 1:
        port = tmp[1]
    else:
        port = None
    hostname = tmp[0]
    query = o[4]
    return (hostname, port, path, query, ssl) 
開發者ID:EnableSecurity,項目名稱:wafw00f,代碼行數:24,代碼來源:evillib.py

示例4: _get_prom_url

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def _get_prom_url(self):
        # Get promenade url from Keystone session object

        ks_session = self._get_ks_session()

        try:
            prom_endpoint = ks_session.get_endpoint(
                interface='internal', service_type='kubernetesprovisioner')
        except exc.EndpointNotFound:
            self.logger.error("Could not find an internal interface"
                              " defined in Keystone for Promenade")

            raise errors.DriverError("Could not find an internal interface"
                                     " defined in Keystone for Promenade")

        prom_url = urlparse(prom_endpoint)

        return prom_url 
開發者ID:airshipit,項目名稱:drydock,代碼行數:20,代碼來源:promenade_client.py

示例5: test_connection

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def test_connection(name, url, timeout=10):
    """Simple connection test"""
    urlinfo = urlparse(url)
    start = time.time()
    try:
        ip = socket.gethostbyname(urlinfo.netloc)
    except Exception as e:
        print('Error resolving DNS for {}: {}, {}'.format(name, url, e))
        return
    dns_elapsed = time.time() - start
    start = time.time()
    try:
        _ = urlopen(url, timeout=timeout)
    except Exception as e:
        print("Error open {}: {}, {}, DNS finished in {} sec.".format(name, url, e, dns_elapsed))
        return
    load_elapsed = time.time() - start
    print("Timing for {}: {}, DNS: {:.4f} sec, LOAD: {:.4f} sec.".format(name, url, dns_elapsed, load_elapsed)) 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:20,代碼來源:diagnose.py

示例6: extract_domains

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def extract_domains(self, resp):
        link_regx = re.compile('<cite.*?>(.*?)<\/cite>')
        try:
            links_list = link_regx.findall(resp)
            for link in links_list:
                link = re.sub('<span.*>', '', link)
                if not link.startswith('http'):
                    link = "http://" + link
                subdomain = urlparse.urlparse(link).netloc
                if subdomain and subdomain not in self.subdomains and subdomain != self.domain:
                    if self.verbose:
                        self.print_("%s%s: %s%s" % (R, self.engine_name, W, subdomain))
                    self.subdomains.append(subdomain.strip())
        except Exception:
            pass
        return links_list 
開發者ID:kp625544,項目名稱:subtake,代碼行數:18,代碼來源:sublist3r.py

示例7: _create_request_from_scope

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def _create_request_from_scope(self, send: Callable) -> Request:
        headers = Headers()
        headers["Remote-Addr"] = (self.scope.get("client") or ["<local>"])[0]
        for name, value in self.scope["headers"]:
            headers.add(name.decode("latin1").title(), value.decode("latin1"))
        if self.scope["http_version"] < "1.1":
            headers.setdefault("Host", self.app.config["SERVER_NAME"] or "")

        path = self.scope["path"]
        path = path if path[0] == "/" else urlparse(path).path

        return self.app.request_class(
            self.scope["method"],
            self.scope["scheme"],
            path,
            self.scope["query_string"],
            headers,
            self.scope.get("root_path", ""),
            self.scope["http_version"],
            max_content_length=self.app.config["MAX_CONTENT_LENGTH"],
            body_timeout=self.app.config["BODY_TIMEOUT"],
            send_push_promise=partial(self._send_push_promise, send),
            scope=self.scope,
        ) 
開發者ID:pgjones,項目名稱:quart,代碼行數:26,代碼來源:asgi.py

示例8: _create_websocket_from_scope

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def _create_websocket_from_scope(self, send: Callable) -> Websocket:
        headers = Headers()
        headers["Remote-Addr"] = (self.scope.get("client") or ["<local>"])[0]
        for name, value in self.scope["headers"]:
            headers.add(name.decode("latin1").title(), value.decode("latin1"))

        path = self.scope["path"]
        path = path if path[0] == "/" else urlparse(path).path

        return self.app.websocket_class(
            path,
            self.scope["query_string"],
            self.scope["scheme"],
            headers,
            self.scope.get("root_path", ""),
            self.scope.get("http_version", "1.1"),
            self.scope.get("subprotocols", []),
            self.queue.get,
            partial(self.send_data, send),
            partial(self.accept_connection, send),
        ) 
開發者ID:pgjones,項目名稱:quart,代碼行數:23,代碼來源:asgi.py

示例9: test_url_attributes_with_ssl_dict

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def test_url_attributes_with_ssl_dict(app, path, query, expected_url):

    current_dir = os.path.dirname(os.path.realpath(__file__))
    ssl_cert = os.path.join(current_dir, "certs/selfsigned.cert")
    ssl_key = os.path.join(current_dir, "certs/selfsigned.key")

    ssl_dict = {"cert": ssl_cert, "key": ssl_key}

    async def handler(request):
        return text("OK")

    app.add_route(handler, path)

    request, response = app.test_client.get(
        f"https://{HOST}:{PORT}" + path + f"?{query}",
        server_kwargs={"ssl": ssl_dict},
    )
    assert request.url == expected_url.format(HOST, request.server_port)

    parsed = urlparse(request.url)

    assert parsed.scheme == request.scheme
    assert parsed.path == request.path
    assert parsed.query == request.query_string
    assert parsed.netloc == request.host 
開發者ID:huge-success,項目名稱:sanic,代碼行數:27,代碼來源:test_requests.py

示例10: read

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def read(self):
        try:
            from PIL import Image
            from pyzbar.pyzbar import decode
            decoded_data = decode(Image.open(self.filename))
            if path.isfile(self.filename):
                remove(self.filename)
            try:
                url = urlparse(decoded_data[0].data.decode())
                query_params = parse_qsl(url.query)
                self._codes = dict(query_params)
                return self._codes.get("secret")
            except (KeyError, IndexError):
                Logger.error("Invalid QR image")
                return None
        except ImportError:
            from ..application import Application
            Application.USE_QRSCANNER = False
            QRReader.ZBAR_FOUND = False 
開發者ID:bilelmoussaoui,項目名稱:Authenticator,代碼行數:21,代碼來源:qr_reader.py

示例11: dedup_link

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def dedup_link(urls):
    host = []
    _ = []
    furls = []
    for i in set(urls):
        # 隻保留有參數的url其餘的略過
        if '=' in i and not re.search(r"'|@|\+", i):
            #  判斷url是不是偽靜態,偽靜態與普通的去重方法不一樣
            if re.search(r'/\?\d+=', i):
                furls.append(i)
            else:
                # 通過urlparse 對url進行去參去重,相同的丟棄
                url = parse.urlparse(i)
                if url.netloc + url.path not in host:
                    host.append(url.netloc + url.path)
                    _.append(i)
    _.extend(diff(furls))
    return _ 
開發者ID:al0ne,項目名稱:Vxscan,代碼行數:20,代碼來源:url.py

示例12: __init__

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def __init__(self,session,**kwargs):
        tools.Options.__init__(self,**kwargs)

        self._session = session

        url = urlparse(self._session.conn_url)

        self._secure = False

        if url[0] == "https":
            self._secure = True

        s = url[1].split(":")

        self._host = s[0]
        self._port = s[1]

        self._websocket = None
        self._handshakeComplete = False
        self._headers = None
        self._authorization = None 
開發者ID:sassoftware,項目名稱:python-esppy,代碼行數:23,代碼來源:connections.py

示例13: validate_link

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def validate_link(self, link, bookmark=False):
        """Checks if the given link can get correct data."""
        # removes the scheme and net location parts of the link
        url_parts = list(urlparse.urlparse(link))
        url_parts[0] = url_parts[1] = ''

        # bookmark link should not have the version in the URL
        if bookmark and url_parts[2].startswith(PATH_PREFIX):
            return False

        full_path = urlparse.urlunparse(url_parts)
        try:
            self.get_json(full_path, path_prefix='')
            return True
        except Exception:
            return False 
開發者ID:openstack,項目名稱:zun,代碼行數:18,代碼來源:base.py

示例14: do_GET

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def do_GET(self):
        (scm, netloc, path, params, query, fragment) = urlparse(self.path, "http")
        if scm != "http" or fragment or not netloc:
            self.send_error(400, "bad url %s" % self.path)
            return
        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            if self._connect_to(netloc, soc):
                self.log_request()
                soc.send(
                    "%s %s %s\r\n" % (self.command, urlunparse(("", "", path, params, query, "")), self.request_version)
                )
                self.headers["Connection"] = "close"
                del self.headers["Proxy-Connection"]
                for key_val in self.headers.items():
                    soc.send("%s: %s\r\n" % key_val)
                soc.send("\r\n")
                self._read_write(soc)
        finally:
            logging.warning("Finished do_GET()")
            soc.close()
            self.connection.close() 
開發者ID:nabla-c0d3,項目名稱:sslyze,代碼行數:24,代碼來源:tiny_proxy.py

示例15: extract_http_scheme_host_port

# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import urlparse [as 別名]
def extract_http_scheme_host_port(http_url):
    '''Extract scheme, host and port from a HTTP URL.

    :param http_url: HTTP URL to extract.
    :type http_url: ``string``
    :returns: A tuple of scheme, host and port
    :rtype: ``tuple``

    :raises ValueError: If `http_url` is not in http(s)://hostname:port format.
    '''

    try:
        http_info = urlparse.urlparse(http_url)
    except Exception:
        raise ValueError(
            str(http_url) + " is not in http(s)://hostname:port format")

    if not http_info.scheme or not http_info.hostname or not http_info.port:
        raise ValueError(
            http_url + " is not in http(s)://hostname:port format")

    return (http_info.scheme, http_info.hostname, http_info.port) 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:24,代碼來源:utils.py


注:本文中的urllib.parse.urlparse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。