##// END OF EJS Templates
httpclient: update to upstream revision 2995635573d2...
Augie Fackler -
r29131:8a66eda4 default
parent child Browse files
Show More
@@ -41,18 +41,29 b' from __future__ import absolute_import'
41 41 # Many functions in this file have too many arguments.
42 42 # pylint: disable=R0913
43 43
44 import cStringIO
45 44 import errno
46 import httplib
45 import inspect
47 46 import logging
48 47 import rfc822
49 48 import select
50 49 import socket
51 50
51 try:
52 import cStringIO as io
53 io.StringIO
54 except ImportError:
55 import io
56
57 try:
58 import httplib
59 httplib.HTTPException
60 except ImportError:
61 import http.client as httplib
62
52 63 from . import (
53 64 _readers,
54 65 socketutil,
55 )
66 )
56 67
57 68 logger = logging.getLogger(__name__)
58 69
@@ -242,7 +253,7 b' class HTTPResponse(object):'
242 253 self.status = int(self.status)
243 254 if self._eol != EOL:
244 255 hdrs = hdrs.replace(self._eol, '\r\n')
245 headers = rfc822.Message(cStringIO.StringIO(hdrs))
256 headers = rfc822.Message(io.StringIO(hdrs))
246 257 content_len = None
247 258 if HDR_CONTENT_LENGTH in headers:
248 259 content_len = int(headers[HDR_CONTENT_LENGTH])
@@ -296,6 +307,46 b' def _foldheaders(headers):'
296 307 """
297 308 return dict((k.lower(), (k, v)) for k, v in headers.iteritems())
298 309
310 try:
311 inspect.signature
312 def _handlesarg(func, arg):
313 """ Try to determine if func accepts arg
314
315 If it takes arg, return True
316 If it happens to take **args, then it could do anything:
317 * It could throw a different TypeError, just for fun
318 * It could throw an ArgumentError or anything else
319 * It could choose not to throw an Exception at all
320 ... return 'unknown'
321
322 Otherwise, return False
323 """
324 params = inspect.signature(func).parameters
325 if arg in params:
326 return True
327 for p in params:
328 if params[p].kind == inspect._ParameterKind.VAR_KEYWORD:
329 return 'unknown'
330 return False
331 except AttributeError:
332 def _handlesarg(func, arg):
333 """ Try to determine if func accepts arg
334
335 If it takes arg, return True
336 If it happens to take **args, then it could do anything:
337 * It could throw a different TypeError, just for fun
338 * It could throw an ArgumentError or anything else
339 * It could choose not to throw an Exception at all
340 ... return 'unknown'
341
342 Otherwise, return False
343 """
344 spec = inspect.getargspec(func)
345 if arg in spec.args:
346 return True
347 if spec.keywords:
348 return 'unknown'
349 return False
299 350
300 351 class HTTPConnection(object):
301 352 """Connection to a single http server.
@@ -346,9 +397,31 b' class HTTPConnection(object):'
346 397 if '[' in host:
347 398 host = host[1:-1]
348 399 if ssl_wrap_socket is not None:
349 self._ssl_wrap_socket = ssl_wrap_socket
400 _wrap_socket = ssl_wrap_socket
350 401 else:
351 self._ssl_wrap_socket = socketutil.wrap_socket
402 _wrap_socket = socketutil.wrap_socket
403 call_wrap_socket = None
404 handlesubar = _handlesarg(_wrap_socket, 'server_hostname')
405 if handlesubar is True:
406 # supports server_hostname
407 call_wrap_socket = _wrap_socket
408 handlesnobar = _handlesarg(_wrap_socket, 'serverhostname')
409 if handlesnobar is True and handlesubar is not True:
410 # supports serverhostname
411 def call_wrap_socket(sock, server_hostname=None, **ssl_opts):
412 return _wrap_socket(sock, serverhostname=server_hostname,
413 **ssl_opts)
414 if handlesubar is False and handlesnobar is False:
415 # does not support either
416 def call_wrap_socket(sock, server_hostname=None, **ssl_opts):
417 return _wrap_socket(sock, **ssl_opts)
418 if call_wrap_socket is None:
419 # we assume it takes **args
420 def call_wrap_socket(sock, **ssl_opts):
421 if 'server_hostname' in ssl_opts:
422 ssl_opts['serverhostname'] = ssl_opts['server_hostname']
423 return _wrap_socket(sock, **ssl_opts)
424 self._ssl_wrap_socket = call_wrap_socket
352 425 if use_ssl is None and port is None:
353 426 use_ssl = False
354 427 port = 80
@@ -429,7 +502,8 b' class HTTPConnection(object):'
429 502 sock.setblocking(1)
430 503 logger.debug('wrapping socket for ssl with options %r',
431 504 self.ssl_opts)
432 sock = self._ssl_wrap_socket(sock, **self.ssl_opts)
505 sock = self._ssl_wrap_socket(sock, server_hostname=self.host,
506 **self.ssl_opts)
433 507 if self._ssl_validator:
434 508 self._ssl_validator(sock)
435 509 sock.setblocking(0)
@@ -33,7 +33,12 b' have any clients outside of httpplus.'
33 33 """
34 34 from __future__ import absolute_import
35 35
36 import httplib
36 try:
37 import httplib
38 httplib.HTTPException
39 except ImportError:
40 import http.client as httplib
41
37 42 import logging
38 43
39 44 logger = logging.getLogger(__name__)
@@ -122,7 +122,8 b' else:'
122 122 server_side=False, cert_reqs=CERT_NONE,
123 123 ssl_version=_PROTOCOL_SSLv23, ca_certs=None,
124 124 do_handshake_on_connect=True,
125 suppress_ragged_eofs=True):
125 suppress_ragged_eofs=True,
126 server_hostname=None):
126 127 """Backport of ssl.wrap_socket from Python 2.6."""
127 128 if cert_reqs != CERT_NONE and ca_certs:
128 129 raise CertificateValidationUnsupported(
General Comments 0
You need to be logged in to leave comments. Login now