mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
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)
This commit is contained in:
parent
44620646fd
commit
2567dd6d44
1 changed files with 13 additions and 14 deletions
|
@ -28,20 +28,13 @@
|
||||||
# connection for each request.)
|
# connection for each request.)
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
import regex
|
|
||||||
import regsub
|
|
||||||
import mimetools
|
import mimetools
|
||||||
|
|
||||||
HTTP_VERSION = 'HTTP/1.0'
|
HTTP_VERSION = 'HTTP/1.0'
|
||||||
HTTP_VERSIONS_ACCEPTED = 'HTTP/1\.[0-9.]+'
|
|
||||||
HTTP_PORT = 80
|
HTTP_PORT = 80
|
||||||
|
|
||||||
replypat = HTTP_VERSIONS_ACCEPTED + '[ \t]+\([0-9][0-9][0-9]\)\(.*\)'
|
|
||||||
replyprog = regex.compile(replypat)
|
|
||||||
|
|
||||||
class HTTP:
|
class HTTP:
|
||||||
|
|
||||||
def __init__(self, host = '', port = 0):
|
def __init__(self, host = '', port = 0):
|
||||||
|
@ -83,15 +76,18 @@ class HTTP:
|
||||||
|
|
||||||
def getreply(self):
|
def getreply(self):
|
||||||
self.file = self.sock.makefile('rb')
|
self.file = self.sock.makefile('rb')
|
||||||
self.sock = None
|
|
||||||
line = self.file.readline()
|
line = self.file.readline()
|
||||||
if self.debuglevel > 0: print 'reply:', `line`
|
if self.debuglevel > 0: print 'reply:', `line`
|
||||||
if replyprog.match(line) < 0:
|
try:
|
||||||
self.headers = None
|
[ver, code, msg] = string.split(line, None, 2)
|
||||||
return -1, line, self.headers
|
except ValueError:
|
||||||
errcode, errmsg = replyprog.group(1, 2)
|
self.headers = None
|
||||||
errcode = string.atoi(errcode)
|
return -1, line, self.headers
|
||||||
errmsg = string.strip(errmsg)
|
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)
|
self.headers = mimetools.Message(self.file, 0)
|
||||||
return errcode, errmsg, self.headers
|
return errcode, errmsg, self.headers
|
||||||
|
|
||||||
|
@ -102,6 +98,9 @@ class HTTP:
|
||||||
if self.file:
|
if self.file:
|
||||||
self.file.close()
|
self.file.close()
|
||||||
self.file = None
|
self.file = None
|
||||||
|
if self.sock:
|
||||||
|
self.sock.close()
|
||||||
|
self.sock = None
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue