From 2567dd6d4487f665f67fa1b19458ab587b2eaace Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 11 Aug 1997 21:52:17 +0000 Subject: 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) --- Lib/httplib.py | 27 +++++++++++++-------------- 1 file 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(): -- cgit v0.12