[Python-checkins] python/dist/src/Lib SimpleHTTPServer.py, 1.22,
1.23 SocketServer.py, 1.37, 1.38 cgi.py, 1.80, 1.81 gettext.py,
1.24, 1.25 mhlib.py, 1.37, 1.38 tarfile.py, 1.21,
1.22 urllib.py, 1.165, 1.166 urlparse.py, 1.45, 1.46
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Fri Dec 31 20:15:29 CET 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5738
Modified Files:
SimpleHTTPServer.py SocketServer.py cgi.py gettext.py mhlib.py
tarfile.py urllib.py urlparse.py
Log Message:
Use cStringIO where available.
Index: SimpleHTTPServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/SimpleHTTPServer.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- SimpleHTTPServer.py 21 Aug 2004 10:43:29 -0000 1.22
+++ SimpleHTTPServer.py 31 Dec 2004 19:15:26 -0000 1.23
@@ -17,7 +17,10 @@
import cgi
import shutil
import mimetypes
-from StringIO import StringIO
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
Index: SocketServer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/SocketServer.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- SocketServer.py 9 Oct 2003 23:48:52 -0000 1.37
+++ SocketServer.py 31 Dec 2004 19:15:26 -0000 1.38
@@ -575,10 +575,13 @@
"""Define self.rfile and self.wfile for datagram sockets."""
def setup(self):
- import StringIO
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
self.packet, self.socket = self.request
- self.rfile = StringIO.StringIO(self.packet)
- self.wfile = StringIO.StringIO()
+ self.rfile = StringIO(self.packet)
+ self.wfile = StringIO()
def finish(self):
self.socket.sendto(self.wfile.getvalue(), self.client_address)
Index: cgi.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cgi.py,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -d -r1.80 -r1.81
--- cgi.py 14 Aug 2004 15:39:34 -0000 1.80
+++ cgi.py 31 Dec 2004 19:15:26 -0000 1.81
@@ -40,7 +40,10 @@
import mimetools
import rfc822
import UserDict
-from StringIO import StringIO
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
__all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict",
"SvFormContentDict", "InterpFormContentDict", "FormContent",
Index: gettext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/gettext.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- gettext.py 22 Jul 2004 18:44:00 -0000 1.24
+++ gettext.py 31 Dec 2004 19:15:26 -0000 1.25
@@ -77,7 +77,10 @@
Python lambda function that implements an equivalent expression.
"""
# Security check, allow only the "n" identifier
- from StringIO import StringIO
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
import token, tokenize
tokens = tokenize.generate_tokens(StringIO(plural).readline)
try:
Index: mhlib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/mhlib.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- mhlib.py 12 Feb 2004 17:35:06 -0000 1.37
+++ mhlib.py 31 Dec 2004 19:15:26 -0000 1.38
@@ -697,7 +697,10 @@
encoding = self.getencoding()
if not decode or encoding in ('', '7bit', '8bit', 'binary'):
return self.fp.read()
- from StringIO import StringIO
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
output = StringIO()
mimetools.decode(self.fp, output, encoding)
return output.getvalue()
Index: tarfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/tarfile.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- tarfile.py 20 Oct 2004 11:48:42 -0000 1.21
+++ tarfile.py 31 Dec 2004 19:15:26 -0000 1.22
@@ -1936,12 +1936,15 @@
def write(self, filename, arcname=None, compress_type=None):
self.tarfile.add(filename, arcname)
def writestr(self, zinfo, bytes):
- import StringIO
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
import calendar
zinfo.name = zinfo.filename
zinfo.size = zinfo.file_size
zinfo.mtime = calendar.timegm(zinfo.date_time)
- self.tarfile.addfile(zinfo, StringIO.StringIO(bytes))
+ self.tarfile.addfile(zinfo, StringIO(bytes))
def close(self):
self.tarfile.close()
#class TarFileCompat
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -d -r1.165 -r1.166
--- urllib.py 11 Oct 2004 13:53:07 -0000 1.165
+++ urllib.py 31 Dec 2004 19:15:26 -0000 1.166
@@ -410,7 +410,11 @@
def open_local_file(self, url):
"""Use local file."""
- import mimetypes, mimetools, email.Utils, StringIO
+ import mimetypes, mimetools, email.Utils
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
host, file = splithost(url)
localname = url2pathname(file)
try:
@@ -420,7 +424,7 @@
size = stats.st_size
modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
mtype = mimetypes.guess_type(url)[0]
- headers = mimetools.Message(StringIO.StringIO(
+ headers = mimetools.Message(StringIO(
'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
(mtype or 'text/plain', size, modified)))
if not host:
@@ -441,7 +445,11 @@
def open_ftp(self, url):
"""Use FTP protocol."""
- import mimetypes, mimetools, StringIO
+ import mimetypes, mimetools
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
host, path = splithost(url)
if not host: raise IOError, ('ftp error', 'no host given')
host, port = splitport(host)
@@ -490,7 +498,7 @@
headers += "Content-Type: %s\n" % mtype
if retrlen is not None and retrlen >= 0:
headers += "Content-Length: %d\n" % retrlen
- headers = mimetools.Message(StringIO.StringIO(headers))
+ headers = mimetools.Message(StringIO(headers))
return addinfourl(fp, headers, "ftp:" + url)
except ftperrors(), msg:
raise IOError, ('ftp error', msg), sys.exc_info()[2]
@@ -504,7 +512,11 @@
# mediatype := [ type "/" subtype ] *( ";" parameter )
# data := *urlchar
# parameter := attribute "=" value
- import StringIO, mimetools
+ import mimetools
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
try:
[type, data] = url.split(',', 1)
except ValueError:
@@ -530,7 +542,7 @@
msg.append('')
msg.append(data)
msg = '\n'.join(msg)
- f = StringIO.StringIO(msg)
+ f = StringIO(msg)
headers = mimetools.Message(f, 0)
f.fileno = None # needed for addinfourl
return addinfourl(f, headers, url)
@@ -697,8 +709,11 @@
global _noheaders
if _noheaders is None:
import mimetools
- import StringIO
- _noheaders = mimetools.Message(StringIO.StringIO(), 0)
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
+ _noheaders = mimetools.Message(StringIO(), 0)
_noheaders.fp.close() # Recycle file descriptor
return _noheaders
Index: urlparse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urlparse.py,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- urlparse.py 29 Jun 2004 04:02:39 -0000 1.45
+++ urlparse.py 31 Dec 2004 19:15:26 -0000 1.46
@@ -243,8 +243,11 @@
else:
fp = open(fn)
else:
- import StringIO
- fp = StringIO.StringIO(test_input)
+ try:
+ from cStringIO import StringIO
+ except ImportError:
+ from StringIO import StringIO
+ fp = StringIO(test_input)
while 1:
line = fp.readline()
if not line: break
More information about the Python-checkins
mailing list