|
70 | 70 |
|
71 | 71 | from __future__ import (absolute_import, division,
|
72 | 72 | print_function, unicode_literals)
|
| 73 | +from future.utils import isbytes, istext |
73 | 74 | from future.builtins import *
|
74 | 75 |
|
75 | 76 | import email.parser
|
|
84 | 85 | from urlparse import urlsplit
|
85 | 86 | from array import array
|
86 | 87 | import warnings
|
| 88 | +import numbers |
87 | 89 |
|
88 | 90 | __all__ = ["HTTPResponse", "HTTPConnection",
|
89 | 91 | "HTTPException", "NotConnected", "UnknownProtocol",
|
@@ -703,7 +705,7 @@ def getheader(self, name, default=None):
|
703 | 705 | if self.headers is None:
|
704 | 706 | raise ResponseNotReady()
|
705 | 707 | headers = self.headers.get_all(name) or default
|
706 |
| - if isinstance(headers, str) or not hasattr(headers, '__iter__'): |
| 708 | + if istext(headers) or not hasattr(headers, '__iter__'): |
707 | 709 | return headers
|
708 | 710 | else:
|
709 | 711 | return ', '.join(headers)
|
@@ -909,7 +911,7 @@ def _send_output(self, message_body=None):
|
909 | 911 | # If msg and message_body are sent in a single send() call,
|
910 | 912 | # it will avoid performance problems caused by the interaction
|
911 | 913 | # between delayed ack and the Nagle algorithm.
|
912 |
| - if isinstance(message_body, bytes): |
| 914 | + if isbytes(message_body): |
913 | 915 | msg += message_body
|
914 | 916 | message_body = None
|
915 | 917 | self.send(msg)
|
@@ -1105,7 +1107,7 @@ def _send_request(self, method, url, body, headers):
|
1105 | 1107 | self._set_content_length(body)
|
1106 | 1108 | for hdr, value in headers.items():
|
1107 | 1109 | self.putheader(hdr, value)
|
1108 |
| - if isinstance(body, str): |
| 1110 | + if istext(body): |
1109 | 1111 | # RFC 2616 Section 3.7.1 says that text default has a
|
1110 | 1112 | # default charset of iso-8859-1.
|
1111 | 1113 | body = body.encode('iso-8859-1')
|
|
0 commit comments