Change some uses of cStringIO.StringIO to io.StringIO.

This is undoubtedly insufficient and in some cases just as broken as before.
This commit is contained in:
Guido van Rossum 2007-05-18 00:51:22 +00:00
parent 7ac9d40201
commit 68937b4cbc
19 changed files with 26 additions and 89 deletions

View File

@ -18,10 +18,7 @@ import urlparse
import cgi
import shutil
import mimetypes
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

View File

@ -577,10 +577,7 @@ class DatagramRequestHandler(BaseRequestHandler):
"""Define self.rfile and self.wfile for datagram sockets."""
def setup(self):
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
self.packet, self.socket = self.request
self.rfile = StringIO(self.packet)
self.wfile = StringIO()

View File

@ -41,10 +41,7 @@ import urllib
import mimetools
import rfc822
import UserDict
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
__all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict",
"SvFormContentDict", "InterpFormContentDict", "FormContent",

View File

@ -11,10 +11,7 @@ from _csv import Error, __version__, writer, reader, register_dialect, \
__doc__
from _csv import Dialect as _Dialect
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
"Error", "Dialect", "excel", "excel_tab", "reader", "writer",

View File

@ -77,10 +77,7 @@ def c2py(plural):
Python lambda function that implements an equivalent expression.
"""
# Security check, allow only the "n" identifier
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
import token, tokenize
tokens = tokenize.generate_tokens(StringIO(plural).readline)
try:

View File

@ -71,10 +71,7 @@ import mimetools
import socket
from urlparse import urlsplit
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
__all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPSConnection",
"HTTPException", "NotConnected", "UnknownProtocol",

View File

@ -697,10 +697,7 @@ class Message(mimetools.Message):
encoding = self.getencoding()
if not decode or encoding in ('', '7bit', '8bit', 'binary'):
return self.fp.read()
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
output = StringIO()
mimetools.decode(self.fp, output, encoding)
return output.getvalue()

View File

@ -105,7 +105,7 @@ def encode(input, output, quotetabs, header = 0):
def encodestring(s, quotetabs = 0, header = 0):
if b2a_qp is not None:
return b2a_qp(s, quotetabs = quotetabs, header = header)
from cStringIO import StringIO
from io import StringIO
infp = StringIO(s)
outfp = StringIO()
encode(infp, outfp, quotetabs, header)
@ -159,7 +159,7 @@ def decode(input, output, header = 0):
def decodestring(s, header = 0):
if a2b_qp is not None:
return a2b_qp(s, header = header)
from cStringIO import StringIO
from io import StringIO
infp = StringIO(s)
outfp = StringIO()
decode(infp, outfp, header = header)

View File

@ -56,17 +56,8 @@ entries in the cache, and empty the cache (d.sync() also synchronizes
the persistent dictionary on disk, if feasible).
"""
# Try using cPickle and cStringIO if available.
try:
from cPickle import Pickler, Unpickler
except ImportError:
from pickle import Pickler, Unpickler
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from pickle import Pickler, Unpickler
from io import StringIO
import UserDict
import warnings

View File

@ -11,10 +11,7 @@ import os.path
import sys
from collections import deque
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
__all__ = ["shlex", "split"]

View File

@ -374,7 +374,7 @@ class PureProxy(SMTPServer):
class MailmanProxy(PureProxy):
def process_message(self, peer, mailfrom, rcpttos, data):
from cStringIO import StringIO
from io import StringIO
from Mailman import Utils
from Mailman import Message
from Mailman import MailList

View File

@ -2459,10 +2459,7 @@ class TarFileCompat:
def write(self, filename, arcname=None, compress_type=None):
self.tarfile.add(filename, arcname)
def writestr(self, zinfo, bytes):
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
import calendar
zinfo.name = zinfo.filename
zinfo.size = zinfo.file_size

View File

@ -37,10 +37,7 @@ if _os.name == 'mac':
import Carbon.Folder as _Folder
import Carbon.Folders as _Folders
try:
from cStringIO import StringIO as _StringIO
except:
from StringIO import StringIO as _StringIO
from io import StringIO as _StringIO
try:
import fcntl as _fcntl

View File

@ -462,10 +462,7 @@ class URLopener:
def open_local_file(self, url):
"""Use local file."""
import mimetypes, mimetools, email.utils
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
host, file = splithost(url)
localname = url2pathname(file)
try:
@ -499,10 +496,7 @@ class URLopener:
if not isinstance(url, str):
raise IOError, ('ftp error', 'proxy support for ftp protocol currently not implemented')
import mimetypes, mimetools
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
host, path = splithost(url)
if not host: raise IOError, ('ftp error', 'no host given')
host, port = splitport(host)
@ -568,10 +562,7 @@ class URLopener:
# data := *urlchar
# parameter := attribute "=" value
import mimetools
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
try:
[type, data] = url.split(',', 1)
except ValueError:
@ -821,10 +812,7 @@ def noheaders():
global _noheaders
if _noheaders is None:
import mimetools
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
_noheaders = mimetools.Message(StringIO(), 0)
_noheaders.fp.close() # Recycle file descriptor
return _noheaders

View File

@ -101,10 +101,7 @@ import time
import urlparse
import bisect
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
from urllib import (unwrap, unquote, splittype, splithost, quote,
addinfourl, splitport, splitgophertype, splitquery,

View File

@ -350,10 +350,7 @@ def test():
else:
fp = open(fn)
else:
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from io import StringIO
fp = StringIO(test_input)
while 1:
line = fp.readline()

View File

@ -5,10 +5,7 @@ See: RFC 1014
"""
import struct
try:
from cStringIO import StringIO as _StringIO
except ImportError:
from StringIO import StringIO as _StringIO
from io import StringIO as _StringIO
__all__ = ["Error", "Packer", "Unpacker", "ConversionError"]

View File

@ -370,10 +370,7 @@ def _datetime_type(data):
# @param data An 8-bit string containing arbitrary data.
import base64
try:
import cStringIO as StringIO
except ImportError:
import StringIO
import io
class Binary:
"""Wrapper for binary data."""
@ -404,7 +401,7 @@ class Binary:
def encode(self, out):
out.write("<value><base64>\n")
base64.encode(StringIO.StringIO(self.data), out)
base64.encode(io.StringIO(self.data), out)
out.write("</base64></value>\n")
def _binary(data):

View File

@ -2,7 +2,7 @@
Read and write ZIP files.
"""
import struct, os, time, sys
import binascii, cStringIO
import binascii, io
try:
import zlib # We may need its compression method
@ -661,7 +661,7 @@ class ZipFile:
self.start_dir = offset_cd + concat
fp.seek(self.start_dir, 0)
data = fp.read(size_cd)
fp = cStringIO.StringIO(data)
fp = io.StringIO(data)
total = 0
while total < size_cd:
centdir = fp.read(46)