本文整理汇总了Python中http.client.HTTP_PORT属性的典型用法代码示例。如果您正苦于以下问题:Python client.HTTP_PORT属性的具体用法?Python client.HTTP_PORT怎么用?Python client.HTTP_PORT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类http.client
的用法示例。
在下文中一共展示了client.HTTP_PORT属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTP_PORT [as 别名]
def __init__(self, uri, timeout=None, ssl_context_factory=None):
"""Initialize a HTTP Socket.
@param uri(str) The http_scheme:://host:port/path to connect to.
@param timeout timeout in ms
"""
parsed = urllib.parse.urlparse(uri)
self.scheme = parsed.scheme
assert self.scheme in ('http', 'https')
if self.scheme == 'http':
self.port = parsed.port or http_client.HTTP_PORT
elif self.scheme == 'https':
self.port = parsed.port or http_client.HTTPS_PORT
self.host = parsed.hostname
self.path = parsed.path
if parsed.query:
self.path += '?%s' % parsed.query
self.__wbuf = BytesIO()
self.__http = None
self.__custom_headers = None
self.__timeout = None
if timeout:
self.setTimeout(timeout)
self._ssl_context_factory = ssl_context_factory
示例2: test_set_tunnel_host_port_headers
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTP_PORT [as 别名]
def test_set_tunnel_host_port_headers(self):
tunnel_host = 'destination.com'
tunnel_port = 8888
tunnel_headers = {'User-Agent': 'Mozilla/5.0 (compatible, MSIE 11)'}
self.conn.set_tunnel(tunnel_host, port=tunnel_port,
headers=tunnel_headers)
self.conn.request('HEAD', '/', '')
self.assertEqual(self.conn.sock.host, self.host)
self.assertEqual(self.conn.sock.port, client.HTTP_PORT)
self.assertEqual(self.conn._tunnel_host, tunnel_host)
self.assertEqual(self.conn._tunnel_port, tunnel_port)
self.assertEqual(self.conn._tunnel_headers, tunnel_headers)
示例3: test_connect_with_tunnel
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTP_PORT [as 别名]
def test_connect_with_tunnel(self):
self.conn.set_tunnel('destination.com')
self.conn.request('HEAD', '/', '')
self.assertEqual(self.conn.sock.host, self.host)
self.assertEqual(self.conn.sock.port, client.HTTP_PORT)
self.assertIn(b'CONNECT destination.com', self.conn.sock.data)
# issue22095
self.assertNotIn(b'Host: destination.com:None', self.conn.sock.data)
self.assertIn(b'Host: destination.com', self.conn.sock.data)
# This test should be removed when CONNECT gets the HTTP/1.1 blessing
self.assertNotIn(b'Host: proxy.com', self.conn.sock.data)
示例4: test_connect_put_request
# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import HTTP_PORT [as 别名]
def test_connect_put_request(self):
self.conn.set_tunnel('destination.com')
self.conn.request('PUT', '/', '')
self.assertEqual(self.conn.sock.host, self.host)
self.assertEqual(self.conn.sock.port, client.HTTP_PORT)
self.assertIn(b'CONNECT destination.com', self.conn.sock.data)
self.assertIn(b'Host: destination.com', self.conn.sock.data)