mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-25 14:43:44 +00:00
Update httplib.py from upstream.
This commit is contained in:
parent
82cfd0b7f9
commit
28c58519d9
1 changed files with 8 additions and 73 deletions
|
|
@ -724,7 +724,10 @@ class HTTPConnection:
|
|||
try:
|
||||
port = int(host[i+1:])
|
||||
except ValueError:
|
||||
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
|
||||
if host[i+1:] == "": # http://foo.com:/ == http://foo.com/
|
||||
port = self.default_port
|
||||
else:
|
||||
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
|
||||
host = host[:i]
|
||||
else:
|
||||
port = self.default_port
|
||||
|
|
@ -837,7 +840,7 @@ class HTTPConnection:
|
|||
del self._buffer[:]
|
||||
# If msg and message_body are sent in a single send() call,
|
||||
# it will avoid performance problems caused by the interaction
|
||||
# between delayed ack and the Nagle algorithim.
|
||||
# between delayed ack and the Nagle algorithm.
|
||||
if isinstance(message_body, str):
|
||||
msg += message_body
|
||||
message_body = None
|
||||
|
|
@ -972,10 +975,10 @@ class HTTPConnection:
|
|||
"""Indicate that the last header line has been sent to the server.
|
||||
|
||||
This method sends the request to the server. The optional
|
||||
message_body argument can be used to pass message body
|
||||
message_body argument can be used to pass a message body
|
||||
associated with the request. The message body will be sent in
|
||||
the same packet as the message headers if possible. The
|
||||
message_body should be a string.
|
||||
the same packet as the message headers if it is a string, otherwise it is
|
||||
sent as a separate packet.
|
||||
"""
|
||||
|
||||
if self.__state == _CS_REQ_STARTED:
|
||||
|
|
@ -1367,71 +1370,3 @@ class LineAndFileWrapper:
|
|||
return L + self._file.readlines()
|
||||
else:
|
||||
return L + self._file.readlines(size)
|
||||
|
||||
def test():
|
||||
"""Test this module.
|
||||
|
||||
A hodge podge of tests collected here, because they have too many
|
||||
external dependencies for the regular test suite.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import getopt
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'd')
|
||||
dl = 0
|
||||
for o, a in opts:
|
||||
if o == '-d': dl = dl + 1
|
||||
host = 'www.python.org'
|
||||
selector = '/'
|
||||
if args[0:]: host = args[0]
|
||||
if args[1:]: selector = args[1]
|
||||
h = HTTP()
|
||||
h.set_debuglevel(dl)
|
||||
h.connect(host)
|
||||
h.putrequest('GET', selector)
|
||||
h.endheaders()
|
||||
status, reason, headers = h.getreply()
|
||||
print 'status =', status
|
||||
print 'reason =', reason
|
||||
print "read", len(h.getfile().read())
|
||||
print
|
||||
if headers:
|
||||
for header in headers.headers: print header.strip()
|
||||
print
|
||||
|
||||
# minimal test that code to extract host from url works
|
||||
class HTTP11(HTTP):
|
||||
_http_vsn = 11
|
||||
_http_vsn_str = 'HTTP/1.1'
|
||||
|
||||
h = HTTP11('www.python.org')
|
||||
h.putrequest('GET', 'http://www.python.org/~jeremy/')
|
||||
h.endheaders()
|
||||
h.getreply()
|
||||
h.close()
|
||||
|
||||
try:
|
||||
import ssl
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
|
||||
for host, selector in (('sourceforge.net', '/projects/python'),
|
||||
):
|
||||
print "https://%s%s" % (host, selector)
|
||||
hs = HTTPS()
|
||||
hs.set_debuglevel(dl)
|
||||
hs.connect(host)
|
||||
hs.putrequest('GET', selector)
|
||||
hs.endheaders()
|
||||
status, reason, headers = hs.getreply()
|
||||
print 'status =', status
|
||||
print 'reason =', reason
|
||||
print "read", len(hs.getfile().read())
|
||||
print
|
||||
if headers:
|
||||
for header in headers.headers: print header.strip()
|
||||
print
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
|
|
|
|||
Loading…
Reference in a new issue