本文整理汇总了Python中urllib2.Request.get_origin_req_host方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_origin_req_host方法的具体用法?Python Request.get_origin_req_host怎么用?Python Request.get_origin_req_host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.get_origin_req_host方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cookies
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_origin_req_host [as 别名]
def test_cookies(self):
cj = MockCookieJar()
h = urllib2.HTTPCookieProcessor(cj)
o = h.parent = MockOpener()
req = Request("http://example.com/")
r = MockResponse(200, "OK", {}, "")
newreq = h.http_request(req)
self.assert_(cj.ach_req is req is newreq)
self.assertEquals(req.get_origin_req_host(), "example.com")
self.assert_(not req.is_unverifiable())
newr = h.http_response(req, r)
self.assert_(cj.ec_req is req)
self.assert_(cj.ec_r is r is newr)
示例2: urlopen
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_origin_req_host [as 别名]
def urlopen(url, data=None, *args, **kwargs):
if not isinstance(url, Request):
url = Request(url, data)
data = None
if 'basic_auth' in kwargs:
if kwargs['basic_auth']:
a = base64.b64encode(':'.join(kwargs['basic_auth']))
url.add_header('Authorization', 'Basic '+a)
del(kwargs['basic_auth'])
if 'authorization' in kwargs:
if kwargs['authorization']:
url.add_header('Authorization', kwargs['authorization'])
del(kwargs['authorization'])
if sys.version_info[0] == 2:
url.add_header('Host', url.get_origin_req_host())
return _urlopen(url, data, *args, **kwargs)
else:
url.add_header('Host', url.origin_req_host)
kwargs['cadefaults'] = True
return _urlopen(url, data, *args, **kwargs)