Kaydet (Commit) 928fcede authored tarafından Guido van Rossum's avatar Guido van Rossum

actualized example/reference, fix bug w/ nonnumeric port

üst c7ae9206
# HTTP client class # HTTP client class
# #
# See the following document for a tentative protocol description: # See the following URL for a description of the HTTP/1.0 protocol:
# Hypertext Transfer Protocol (HTTP) Tim Berners-Lee, CERN # http://www.w3.org/hypertext/WWW/Protocols/
# Internet Draft 5 Nov 1993 # (I actually implemented it from a much earlier draft.)
# draft-ietf-iiir-http-00.txt Expires 5 May 1994
# #
# Example: # Example:
# #
# >>> from httplib import HTTP # >>> from httplib import HTTP
# >>> h = HTTP('www.cwi.nl') # >>> h = HTTP('www.python.org')
# >>> h.putreqest('GET', '/index.html') # >>> h.putrequest('GET', '/index.html')
# >>> h.putheader('Accept', 'text/html') # >>> h.putheader('Accept', 'text/html')
# >>> h.putheader('Accept', 'text/plain') # >>> h.putheader('Accept', 'text/plain')
# >>> h.endheaders() # >>> h.endheaders()
...@@ -18,7 +17,8 @@ ...@@ -18,7 +17,8 @@
# ... f = h.getfile() # ... f = h.getfile()
# ... print f.read() # Print the raw HTML # ... print f.read() # Print the raw HTML
# ... # ...
# <TITLE>Home Page of CWI, Amsterdam</TITLE> # <HEAD>
# <TITLE>Python Language Home Page</TITLE>
# [...many more lines...] # [...many more lines...]
# >>> # >>>
# #
...@@ -58,7 +58,8 @@ class HTTP: ...@@ -58,7 +58,8 @@ class HTTP:
if i >= 0: if i >= 0:
host, port = host[:i], host[i+1:] host, port = host[:i], host[i+1:]
try: port = string.atoi(port) try: port = string.atoi(port)
except string.atoi_error: pass except string.atoi_error:
raise socket.error, "nonnumeric port"
if not port: port = HTTP_PORT if not port: port = HTTP_PORT
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.debuglevel > 0: print 'connect:', (host, port) if self.debuglevel > 0: print 'connect:', (host, port)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment