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


Python Request.get_host方法代码示例

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


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

示例1: test_proxy_https

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
 def test_proxy_https(self):
     o = OpenerDirector()
     ph = urllib2.ProxyHandler(dict(https="proxy.example.com:3128"))
     o.add_handler(ph)
     meth_spec = [[("https_open", "return response")]]
     handlers = add_ordered_mock_handlers(o, meth_spec)
     req = Request("https://www.example.com/")
     self.assertEqual(req.get_host(), "www.example.com")
     r = o.open(req)
     self.assertEqual(req.get_host(), "proxy.example.com:3128")
     self.assertEqual([(handlers[0], "https_open")], [tup[0:2] for tup in o.calls])
开发者ID:int3,项目名称:jython,代码行数:13,代码来源:test_urllib2.py

示例2: get_host

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
 def get_host(self):
     _Request.get_host(self)
     if self.port is None:
         if self.get_type() == 'http':
             default = 80
         elif self.get_type() == 'https':
             default = 443
         else:
             raise ValueError('Unsupported type.', self.get_type())
         self.host, self.port = splitnport(self.host, default)
     return self.host
开发者ID:mcruse,项目名称:monotone,代码行数:13,代码来源:request.py

示例3: test_proxy_no_proxy

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
 def test_proxy_no_proxy(self):
     os.environ['no_proxy'] = 'python.org'
     o = OpenerDirector()
     ph = urllib2.ProxyHandler(dict(http="proxy.example.com"))
     o.add_handler(ph)
     req = Request("http://www.perl.org/")
     self.assertEqual(req.get_host(), "www.perl.org")
     r = o.open(req)
     self.assertEqual(req.get_host(), "proxy.example.com")
     req = Request("http://www.python.org")
     self.assertEqual(req.get_host(), "www.python.org")
     r = o.open(req)
     self.assertEqual(req.get_host(), "www.python.org")
     del os.environ['no_proxy']
开发者ID:005,项目名称:gevent,代码行数:16,代码来源:test_urllib2.py

示例4: sign_request

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
def sign_request(request, secret_key):
	req = Request(request)
	raw = "%s\n%s\n%s\n%s" % (req.get_method(),req.get_host(),req.get_selector().split('?')[0],req.get_selector().split('?')[1])
	key = bytes(secret_key)
	print(raw)
	hashed = hmac.new(key, raw, sha1)
	signature = binascii.b2a_base64(hashed.digest())
	return request + '&signature=%s' % quote(signature, '\n')
开发者ID:stodd,项目名称:hmac-python,代码行数:10,代码来源:hmac_sign.py

示例5: test_proxy_https_proxy_authorization

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
 def test_proxy_https_proxy_authorization(self):
     o = OpenerDirector()
     ph = urllib2.ProxyHandler(dict(https="proxy.example.com:3128"))
     o.add_handler(ph)
     https_handler = MockHTTPSHandler()
     o.add_handler(https_handler)
     req = Request("https://www.example.com/")
     req.add_header("Proxy-Authorization", "FooBar")
     req.add_header("User-Agent", "Grail")
     self.assertEqual(req.get_host(), "www.example.com")
     self.assertIsNone(req._tunnel_host)
     r = o.open(req)
     # Verify Proxy-Authorization gets tunneled to request.
     # httpsconn req_headers do not have the Proxy-Authorization header but
     # the req will have.
     self.assertNotIn(("Proxy-Authorization", "FooBar"), https_handler.httpconn.req_headers)
     self.assertIn(("User-Agent", "Grail"), https_handler.httpconn.req_headers)
     self.assertIsNotNone(req._tunnel_host)
     self.assertEqual(req.get_host(), "proxy.example.com:3128")
     self.assertEqual(req.get_header("Proxy-authorization"), "FooBar")
开发者ID:int3,项目名称:jython,代码行数:22,代码来源:test_urllib2.py

示例6: test_wrapped_url

# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import get_host [as 别名]
 def test_wrapped_url(self):
     req = Request("<URL:http://www.python.org>")
     self.assertEqual("www.python.org", req.get_host())
开发者ID:321boom,项目名称:The-Powder-Toy,代码行数:5,代码来源:test_urllib2.py


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