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


Python cookielib.request_host方法代码示例

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


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

示例1: test_request_host

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import request_host [as 别名]
def test_request_host(self):
        from urllib2 import Request
        from cookielib import request_host
        # this request is illegal (RFC2616, 14.2.3)
        req = Request("http://1.1.1.1/",
                      headers={"Host": "www.acme.com:80"})
        # libwww-perl wants this response, but that seems wrong (RFC 2616,
        # section 5.2, point 1., and RFC 2965 section 1, paragraph 3)
        #self.assertEqual(request_host(req), "www.acme.com")
        self.assertEqual(request_host(req), "1.1.1.1")
        req = Request("http://www.acme.com/",
                      headers={"Host": "irrelevant.com"})
        self.assertEqual(request_host(req), "www.acme.com")
        # not actually sure this one is valid Request object, so maybe should
        # remove test for no host in url in request_host function?
        req = Request("/resource.html",
                      headers={"Host": "www.acme.com"})
        self.assertEqual(request_host(req), "www.acme.com")
        # port shouldn't be in request-host
        req = Request("http://www.acme.com:2345/resource.html",
                      headers={"Host": "www.acme.com:5432"})
        self.assertEqual(request_host(req), "www.acme.com") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_cookielib.py

示例2: test_request_host

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import request_host [as 别名]
def test_request_host(self):
        from urllib2 import Request
        from cookielib import request_host
        # this request is illegal (RFC2616, 14.2.3)
        req = Request("http://1.1.1.1/",
                      headers={"Host": "www.acme.com:80"})
        # libwww-perl wants this response, but that seems wrong (RFC 2616,
        # section 5.2, point 1., and RFC 2965 section 1, paragraph 3)
        #self.assertEquals(request_host(req), "www.acme.com")
        self.assertEquals(request_host(req), "1.1.1.1")
        req = Request("http://www.acme.com/",
                      headers={"Host": "irrelevant.com"})
        self.assertEquals(request_host(req), "www.acme.com")
        # not actually sure this one is valid Request object, so maybe should
        # remove test for no host in url in request_host function?
        req = Request("/resource.html",
                      headers={"Host": "www.acme.com"})
        self.assertEquals(request_host(req), "www.acme.com")
        # port shouldn't be in request-host
        req = Request("http://www.acme.com:2345/resource.html",
                      headers={"Host": "www.acme.com:5432"})
        self.assertEquals(request_host(req), "www.acme.com") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:24,代码来源:test_cookielib.py

示例3: get_origin_req_host

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import request_host [as 别名]
def get_origin_req_host(self):
        if self.origin_req_host is None:
            return request_host(self.host)
        else:
            return self.origin_req_host 
开发者ID:hubo1016,项目名称:vlcp,代码行数:7,代码来源:webclient.py

示例4: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import request_host [as 别名]
def __init__(self, url, data = None, method = None, headers = {}, origin_req_host = None, unverifiable = False,
                 rawurl = False):
        '''
        :param url: request url
        :param data: request data, can be a str/bytes, or a stream(vlcp.event.stream.XXXStream)
        :param method: request method (GET, POST, ...)
        :param headers: request header dict ({'user-agent':'myagent'})
        :param origin_req_host: origin request host for cookie policy check
        :param unverifiable: unverifiable for cookie policy check
        '''
        self.url = _str(url, 'ascii')
        s = urlsplit(self.url, 'http')
        self.type = 'https' if s.scheme == 'https' else 'http'
        self.host = s.netloc
        if not self.host:
            raise ValueError('Invalid URL: ' + self.url)
        if rawurl:
            self.path = urlunsplit(('', '', s.path, s.query, ''))
        else:
            self.path = urlunsplit(('', '', quote(s.path), quote(s.query,'/&='), ''))
        if not self.path:
            self.path = '/'
        self.data = data
        if method is None:
            if self.data is None:
                self.method = 'GET'
            else:
                self.method = 'POST'
        else:
            self.method = method.upper()
        if self.data is not None:
            if isinstance(self.data, unicode):
                self.data = _bytes(self.data)
        headers = dict(headers)
        self.headers = dict((_str(k), _str(v, 'iso-8859-1')) for k,v in headers.items())
        self.headerdict = dict((k.lower(), v) for k,v in self.headers.items())
        self.headermap = dict((k.lower(), k) for k in self.headers.keys())
        self.undirectedheaders = {}
        self.undirectedheaderdict = {}
        self.undirectedheadermap = {}
        self.hostname = request_host(self)
        if origin_req_host is None:
            origin_req_host = request_host(self)
        self.origin_req_host = origin_req_host
        self.unverifiable = unverifiable
        self.redirect_count = 0
        if self.data and not self.has_header('Content-Type'):
            self.add_header('Content-Type', 'application/x-www-form-urlencoded') 
开发者ID:hubo1016,项目名称:vlcp,代码行数:50,代码来源:webclient.py


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