summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-11 21:52:17 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-11 21:52:17 (GMT)
commit2567dd6d4487f665f67fa1b19458ab587b2eaace (patch)
tree95e31ca0bcc477be215ce8983aa105d364056d78 /Lib
parent44620646fd7666dffa362137c9b69a3c9e18c715 (diff)
downloadcpython-2567dd6d4487f665f67fa1b19458ab587b2eaace.zip
cpython-2567dd6d4487f665f67fa1b19458ab587b2eaace.tar.gz
cpython-2567dd6d4487f665f67fa1b19458ab587b2eaace.tar.bz2
Two changes:
(1) No longer close self.sock; close it on close(). (Guido) (2) Don't use regular expressions for what can be done simply with string.split() -- regex is thread unsafe. (Jeremy) (3) Delete unused imports. (Jeremy)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/httplib.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 68553c5..fa7d2b7 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -28,20 +28,13 @@
# connection for each request.)
-import os
import socket
import string
-import regex
-import regsub
import mimetools
HTTP_VERSION = 'HTTP/1.0'
-HTTP_VERSIONS_ACCEPTED = 'HTTP/1\.[0-9.]+'
HTTP_PORT = 80
-replypat = HTTP_VERSIONS_ACCEPTED + '[ \t]+\([0-9][0-9][0-9]\)\(.*\)'
-replyprog = regex.compile(replypat)
-
class HTTP:
def __init__(self, host = '', port = 0):
@@ -83,15 +76,18 @@ class HTTP:
def getreply(self):
self.file = self.sock.makefile('rb')
- self.sock = None
line = self.file.readline()
if self.debuglevel > 0: print 'reply:', `line`
- if replyprog.match(line) < 0:
- self.headers = None
- return -1, line, self.headers
- errcode, errmsg = replyprog.group(1, 2)
- errcode = string.atoi(errcode)
- errmsg = string.strip(errmsg)
+ try:
+ [ver, code, msg] = string.split(line, None, 2)
+ except ValueError:
+ self.headers = None
+ return -1, line, self.headers
+ if ver[:5] != 'HTTP/':
+ self.headers = None
+ return -1, line, self.headers
+ errcode = string.atoi(code)
+ errmsg = string.strip(msg)
self.headers = mimetools.Message(self.file, 0)
return errcode, errmsg, self.headers
@@ -102,6 +98,9 @@ class HTTP:
if self.file:
self.file.close()
self.file = None
+ if self.sock:
+ self.sock.close()
+ self.sock = None
def test():