当前位置: 首页>>代码示例>>Python>>正文


Python request.host方法代码示例

本文整理汇总了Python中urllib.request.host方法的典型用法代码示例。如果您正苦于以下问题:Python request.host方法的具体用法?Python request.host怎么用?Python request.host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request的用法示例。


在下文中一共展示了request.host方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def __init__(self, url, data=None, headers={},
                 origin_req_host=None, unverifiable=False,
                 method=None):
        # unwrap('<URL:type://host/path>') --> 'type://host/path'
        self.full_url = unwrap(url)
        self.full_url, self.fragment = splittag(self.full_url)
        self.data = data
        self.headers = {}
        self._tunnel_host = None
        for key, value in headers.items():
            self.add_header(key, value)
        self.unredirected_hdrs = {}
        if origin_req_host is None:
            origin_req_host = request_host(self)
        self.origin_req_host = origin_req_host
        self.unverifiable = unverifiable
        self.method = method
        self._parse() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:20,代码来源:request.py

示例2: http_error_auth_reqed

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def http_error_auth_reqed(self, auth_header, host, req, headers):
        authreq = headers.get(auth_header, None)
        if self.retried > 5:
            # Don't fail endlessly - if we failed once, we'll probably
            # fail a second time. Hm. Unless the Password Manager is
            # prompting for the information. Crap. This isn't great
            # but it's better than the current 'repeat until recursion
            # depth exceeded' approach <wink>
            raise HTTPError(req.full_url, 401, "digest auth failed",
                            headers, None)
        else:
            self.retried += 1
        if authreq:
            scheme = authreq.split()[0]
            if scheme.lower() == 'digest':
                return self.retry_http_digest_auth(req, authreq)
            elif scheme.lower() != 'basic':
                raise ValueError("AbstractDigestAuthHandler does not support"
                                 " the following scheme: '%s'" % scheme) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:21,代码来源:request.py

示例3: retry_proxy_http_basic_auth

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def retry_proxy_http_basic_auth(self, url, realm, data=None):
        host, selector = splithost(url)
        newurl = 'http://' + host + selector
        proxy = self.proxies['http']
        urltype, proxyhost = splittype(proxy)
        proxyhost, proxyselector = splithost(proxyhost)
        i = proxyhost.find('@') + 1
        proxyhost = proxyhost[i:]
        user, passwd = self.get_user_passwd(proxyhost, realm, i)
        if not (user or passwd): return None
        proxyhost = "%s:%s@%s" % (quote(user, safe=''),
                                  quote(passwd, safe=''), proxyhost)
        self.proxies['http'] = 'http://' + proxyhost + proxyselector
        if data is None:
            return self.open(newurl)
        else:
            return self.open(newurl, data) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:request.py

示例4: retry_proxy_https_basic_auth

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def retry_proxy_https_basic_auth(self, url, realm, data=None):
        host, selector = splithost(url)
        newurl = 'https://' + host + selector
        proxy = self.proxies['https']
        urltype, proxyhost = splittype(proxy)
        proxyhost, proxyselector = splithost(proxyhost)
        i = proxyhost.find('@') + 1
        proxyhost = proxyhost[i:]
        user, passwd = self.get_user_passwd(proxyhost, realm, i)
        if not (user or passwd): return None
        proxyhost = "%s:%s@%s" % (quote(user, safe=''),
                                  quote(passwd, safe=''), proxyhost)
        self.proxies['https'] = 'https://' + proxyhost + proxyselector
        if data is None:
            return self.open(newurl)
        else:
            return self.open(newurl, data) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:19,代码来源:request.py

示例5: proxy_bypass_environment

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def proxy_bypass_environment(host):
    """Test if proxies should not be used for a particular host.

    Checks the environment for a variable named no_proxy, which should
    be a list of DNS suffixes separated by commas, or '*' for all hosts.
    """
    no_proxy = os.environ.get('no_proxy', '') or os.environ.get('NO_PROXY', '')
    # '*' is special case for always bypass
    if no_proxy == '*':
        return 1
    # strip port off host
    hostonly, port = splitport(host)
    # check if the host ends with any of the DNS suffixes
    no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')]
    for name in no_proxy_list:
        if name and (hostonly.endswith(name) or host.endswith(name)):
            return 1
    # otherwise, don't bypass
    return 0


# This code tests an OSX specific data structure but is testable on all
# platforms 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:25,代码来源:request.py

示例6: reduce_uri

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def reduce_uri(self, uri, default_port=True):
        """Accept authority or URI and extract only the authority and path."""
        # note HTTP URLs do not have a userinfo component
        parts = urlsplit(uri)
        if parts[1]:
            # URI
            scheme = parts[0]
            authority = parts[1]
            path = parts[2] or '/'
        else:
            # host or host:port
            scheme = None
            authority = uri
            path = '/'
        host, port = splitport(authority)
        if default_port and port is None and scheme is not None:
            dport = {"http": 80,
                     "https": 443,
                     }.get(scheme)
            if dport is not None:
                authority = "%s:%d" % (host, dport)
        return authority, path 
开发者ID:remg427,项目名称:misp42splunk,代码行数:24,代码来源:request.py

示例7: request_host

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def request_host(request):

    """Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    """
    url = request.full_url
    host = urlparse(url)[1]
    if host == "":
        host = request.get_header("Host", "")

    # remove port, if present
    host = _cut_port_re.sub("", host, 1)
    return host.lower() 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:request.py

示例8: _parse

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def _parse(self):
        self.type, rest = splittype(self.full_url)
        if self.type is None:
            raise ValueError("unknown url type: %r" % self.full_url)
        self.host, self.selector = splithost(rest)
        if self.host:
            self.host = unquote(self.host) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:9,代码来源:request.py

示例9: set_proxy

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def set_proxy(self, host, type):
        if self.type == 'https' and not self._tunnel_host:
            self._tunnel_host = self.host
        else:
            self.type= type
            self.selector = self.full_url
        self.host = host 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:9,代码来源:request.py

示例10: proxy_open

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def proxy_open(self, req, proxy, type):
        orig_type = req.type
        proxy_type, user, password, hostport = _parse_proxy(proxy)
        if proxy_type is None:
            proxy_type = orig_type

        if req.host and proxy_bypass(req.host):
            return None

        if user and password:
            user_pass = '%s:%s' % (unquote(user),
                                   unquote(password))
            creds = base64.b64encode(user_pass.encode()).decode("ascii")
            req.add_header('Proxy-authorization', 'Basic ' + creds)
        hostport = unquote(hostport)
        req.set_proxy(hostport, proxy_type)
        if orig_type == proxy_type or orig_type == 'https':
            # let other handlers take care of it
            return None
        else:
            # need to start over, because the other handlers don't
            # grok the proxy's URL type
            # e.g. if we have a constructor arg proxies like so:
            # {'http': 'ftp://proxy.example.com'}, we may end up turning
            # a request for http://acme.example.com/a into one for
            # ftp://proxy.example.com/a
            return self.parent.open(req, timeout=req.timeout) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:29,代码来源:request.py

示例11: retry_http_basic_auth

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def retry_http_basic_auth(self, host, req, realm):
        user, pw = self.passwd.find_user_password(realm, host)
        if pw is not None:
            raw = "%s:%s" % (user, pw)
            auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii")
            if req.headers.get(self.auth_header, None) == auth:
                return None
            req.add_unredirected_header(self.auth_header, auth)
            return self.parent.open(req, timeout=req.timeout)
        else:
            return None 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:13,代码来源:request.py

示例12: http_error_407

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def http_error_407(self, req, fp, code, msg, headers):
        # http_error_auth_reqed requires that there is no userinfo component in
        # authority.  Assume there isn't one, since urllib.request does not (and
        # should not, RFC 3986 s. 3.2.1) support requests for URLs containing
        # userinfo.
        authority = req.host
        response = self.http_error_auth_reqed('proxy-authenticate',
                                          authority, req, headers)
        self.reset_retry_count()
        return response


# Return n random bytes. 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:15,代码来源:request.py

示例13: http_error_401

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def http_error_401(self, req, fp, code, msg, headers):
        host = urlparse(req.full_url)[1]
        retry = self.http_error_auth_reqed('www-authenticate',
                                           host, req, headers)
        self.reset_retry_count()
        return retry 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:request.py

示例14: file_open

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def file_open(self, req):
        url = req.selector
        if url[:2] == '//' and url[2:3] != '/' and (req.host and
                req.host != 'localhost'):
            if not req.host is self.get_names():
                raise URLError("file:// scheme is supported only on localhost")
        else:
            return self.open_local_file(req)

    # names for the localhost 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:12,代码来源:request.py

示例15: open_local_file

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import host [as 别名]
def open_local_file(self, req):
        import future.backports.email.utils as email_utils
        import mimetypes
        host = req.host
        filename = req.selector
        localfile = url2pathname(filename)
        try:
            stats = os.stat(localfile)
            size = stats.st_size
            modified = email_utils.formatdate(stats.st_mtime, usegmt=True)
            mtype = mimetypes.guess_type(filename)[0]
            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
                (mtype or 'text/plain', size, modified))
            if host:
                host, port = splitport(host)
            if not host or \
                (not port and _safe_gethostbyname(host) in self.get_names()):
                if host:
                    origurl = 'file://' + host + filename
                else:
                    origurl = 'file://' + filename
                return addinfourl(open(localfile, 'rb'), headers, origurl)
        except OSError as exp:
            # users shouldn't expect OSErrors coming from urlopen()
            raise URLError(exp)
        raise URLError('file not on local host') 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:29,代码来源:request.py


注:本文中的urllib.request.host方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。