本文整理匯總了Python中future.backports.http.client.HTTPConnection方法的典型用法代碼示例。如果您正苦於以下問題:Python client.HTTPConnection方法的具體用法?Python client.HTTPConnection怎麽用?Python client.HTTPConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類future.backports.http.client
的用法示例。
在下文中一共展示了client.HTTPConnection方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compressLZMA
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def compressLZMA(cls, path):
# improves console readability
path = os.path.normpath(path)
printLog('INFO', 'Compressing file: ' + path)
with open(path, 'rb') as fin:
conn = client.HTTPConnection(getAppManagerHost(False))
headers = {'Content-type': 'application/octet-stream'}
conn.request('POST', '/storage/lzma/', body=fin, headers=headers)
response = conn.getresponse()
if response.status != 200:
printLog('ERROR', 'LZMA compression error: ' + response.reason)
with open(path + '.xz', 'wb') as fout:
fout.write(response.read())
示例2: get_host_info
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def get_host_info(self, host):
x509 = {}
if isinstance(host, tuple):
host, x509 = host
auth, host = urllib_parse.splituser(host)
if auth:
auth = urllib_parse.unquote_to_bytes(auth)
auth = base64.encodebytes(auth).decode("utf-8")
auth = "".join(auth.split()) # get rid of whitespace
extra_headers = [
("Authorization", "Basic " + auth)
]
else:
extra_headers = []
return host, extra_headers, x509
##
# Connect to server.
#
# @param host Target host.
# @return An HTTPConnection object
示例3: test_userpass_inurl_w_spaces
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def test_userpass_inurl_w_spaces(self):
self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
try:
userpass = "a b:c d"
url = "http://{0}@python.org/".format(userpass)
fakehttp_wrapper = http_client.HTTPConnection
authorization = ("Authorization: Basic %s\r\n" %
b64encode(userpass.encode("ASCII")).decode("ASCII"))
fp = urlopen(url)
# The authorization header must be in place
self.assertIn(authorization, fakehttp_wrapper.buf.decode("UTF-8"))
self.assertEqual(fp.readline(), b"Hello!")
self.assertEqual(fp.readline(), b"")
# the spaces are quoted in URL so no match
self.assertNotEqual(fp.geturl(), url)
self.assertEqual(fp.getcode(), 200)
finally:
self.unfakehttp()
示例4: test_ipv6host_header
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def test_ipv6host_header(self):
# Default host header on IPv6 transaction should wrapped by [] if
# its actual IPv6 address
expected = bytes(b'GET /foo HTTP/1.1\r\nHost: [2001::]:81\r\n') + \
bytes(b'Accept-Encoding: identity\r\n\r\n')
conn = client.HTTPConnection('[2001::]:81')
sock = FakeSocket('')
conn.sock = sock
conn.request('GET', '/foo')
self.assertTrue(sock.data.startswith(expected))
expected = bytes(b'GET /foo HTTP/1.1\r\nHost: [2001:102A::]\r\n') + \
bytes(b'Accept-Encoding: identity\r\n\r\n')
conn = client.HTTPConnection('[2001:102A::]')
sock = FakeSocket('')
conn.sock = sock
conn.request('GET', '/foo')
self.assertTrue(sock.data.startswith(expected))
示例5: test_host_port
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def test_host_port(self):
# Check invalid host_port
# Note that http.client does not accept user:password@ in the host-port.
for hp in ("www.python.org:abc", "user:password@www.python.org"):
self.assertRaises(client.InvalidURL, client.HTTPConnection, hp)
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b",
8000),
("www.python.org:80", "www.python.org", 80),
("www.python.org", "www.python.org", 80),
("www.python.org:", "www.python.org", 80),
("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)):
c = client.HTTPConnection(hp)
self.assertEqual(h, c.host)
self.assertEqual(p, c.port)
示例6: test_send
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def test_send(self):
expected = bytes(b'this is a test this is only a test')
conn = client.HTTPConnection('example.com')
sock = FakeSocket(None)
conn.sock = sock
conn.send(expected)
self.assertEqual(expected, sock.data)
sock.data = bytes(b'')
if utils.PY3:
mydata = array.array('b', expected)
else:
mydata = array.array(b'b', expected)
conn.send(mydata)
self.assertEqual(expected, sock.data)
sock.data = bytes(b'')
conn.send(io.BytesIO(expected))
self.assertEqual(expected, sock.data)
示例7: make_connection
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def make_connection(self, host):
#return an existing connection if possible. This allows
#HTTP/1.1 keep-alive.
if self._connection and host == self._connection[0]:
return self._connection[1]
# create a HTTP connection object from a host descriptor
chost, self._extra_headers, x509 = self.get_host_info(host)
self._connection = host, http_client.HTTPConnection(chost)
return self._connection[1]
##
# Clear any cached connection object.
# Used in the event of socket errors.
#
示例8: close
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def close(self):
if self._connection[1]:
self._connection[1].close()
self._connection = (None, None)
##
# Send HTTP request.
#
# @param host Host descriptor (URL or (URL, x509 info) tuple).
# @param handler Targer RPC handler (a path relative to host)
# @param request_body The XML-RPC request body
# @param debug Enable debugging if debug is true.
# @return An HTTPConnection.
示例9: open_http
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def open_http(self, url, data=None):
"""Use HTTP protocol."""
return self._open_generic_http(http_client.HTTPConnection, url, data)
示例10: http_open
# 需要導入模塊: from future.backports.http import client [as 別名]
# 或者: from future.backports.http.client import HTTPConnection [as 別名]
def http_open(self, req):
return self.do_open(http_client.HTTPConnection, req)