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:
parent
7ac9d40201
commit
68937b4cbc
|
@ -18,10 +18,7 @@ import urlparse
|
||||||
import cgi
|
import cgi
|
||||||
import shutil
|
import shutil
|
||||||
import mimetypes
|
import mimetypes
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
|
|
|
@ -577,10 +577,7 @@ class DatagramRequestHandler(BaseRequestHandler):
|
||||||
"""Define self.rfile and self.wfile for datagram sockets."""
|
"""Define self.rfile and self.wfile for datagram sockets."""
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
self.packet, self.socket = self.request
|
self.packet, self.socket = self.request
|
||||||
self.rfile = StringIO(self.packet)
|
self.rfile = StringIO(self.packet)
|
||||||
self.wfile = StringIO()
|
self.wfile = StringIO()
|
||||||
|
|
|
@ -41,10 +41,7 @@ import urllib
|
||||||
import mimetools
|
import mimetools
|
||||||
import rfc822
|
import rfc822
|
||||||
import UserDict
|
import UserDict
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
__all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict",
|
__all__ = ["MiniFieldStorage", "FieldStorage", "FormContentDict",
|
||||||
"SvFormContentDict", "InterpFormContentDict", "FormContent",
|
"SvFormContentDict", "InterpFormContentDict", "FormContent",
|
||||||
|
|
|
@ -11,10 +11,7 @@ from _csv import Error, __version__, writer, reader, register_dialect, \
|
||||||
__doc__
|
__doc__
|
||||||
from _csv import Dialect as _Dialect
|
from _csv import Dialect as _Dialect
|
||||||
|
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
|
__all__ = [ "QUOTE_MINIMAL", "QUOTE_ALL", "QUOTE_NONNUMERIC", "QUOTE_NONE",
|
||||||
"Error", "Dialect", "excel", "excel_tab", "reader", "writer",
|
"Error", "Dialect", "excel", "excel_tab", "reader", "writer",
|
||||||
|
|
|
@ -77,10 +77,7 @@ def c2py(plural):
|
||||||
Python lambda function that implements an equivalent expression.
|
Python lambda function that implements an equivalent expression.
|
||||||
"""
|
"""
|
||||||
# Security check, allow only the "n" identifier
|
# Security check, allow only the "n" identifier
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
import token, tokenize
|
import token, tokenize
|
||||||
tokens = tokenize.generate_tokens(StringIO(plural).readline)
|
tokens = tokenize.generate_tokens(StringIO(plural).readline)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -71,10 +71,7 @@ import mimetools
|
||||||
import socket
|
import socket
|
||||||
from urlparse import urlsplit
|
from urlparse import urlsplit
|
||||||
|
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
__all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPSConnection",
|
__all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPSConnection",
|
||||||
"HTTPException", "NotConnected", "UnknownProtocol",
|
"HTTPException", "NotConnected", "UnknownProtocol",
|
||||||
|
|
|
@ -697,10 +697,7 @@ class Message(mimetools.Message):
|
||||||
encoding = self.getencoding()
|
encoding = self.getencoding()
|
||||||
if not decode or encoding in ('', '7bit', '8bit', 'binary'):
|
if not decode or encoding in ('', '7bit', '8bit', 'binary'):
|
||||||
return self.fp.read()
|
return self.fp.read()
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
output = StringIO()
|
output = StringIO()
|
||||||
mimetools.decode(self.fp, output, encoding)
|
mimetools.decode(self.fp, output, encoding)
|
||||||
return output.getvalue()
|
return output.getvalue()
|
||||||
|
|
|
@ -105,7 +105,7 @@ def encode(input, output, quotetabs, header = 0):
|
||||||
def encodestring(s, quotetabs = 0, header = 0):
|
def encodestring(s, quotetabs = 0, header = 0):
|
||||||
if b2a_qp is not None:
|
if b2a_qp is not None:
|
||||||
return b2a_qp(s, quotetabs = quotetabs, header = header)
|
return b2a_qp(s, quotetabs = quotetabs, header = header)
|
||||||
from cStringIO import StringIO
|
from io import StringIO
|
||||||
infp = StringIO(s)
|
infp = StringIO(s)
|
||||||
outfp = StringIO()
|
outfp = StringIO()
|
||||||
encode(infp, outfp, quotetabs, header)
|
encode(infp, outfp, quotetabs, header)
|
||||||
|
@ -159,7 +159,7 @@ def decode(input, output, header = 0):
|
||||||
def decodestring(s, header = 0):
|
def decodestring(s, header = 0):
|
||||||
if a2b_qp is not None:
|
if a2b_qp is not None:
|
||||||
return a2b_qp(s, header = header)
|
return a2b_qp(s, header = header)
|
||||||
from cStringIO import StringIO
|
from io import StringIO
|
||||||
infp = StringIO(s)
|
infp = StringIO(s)
|
||||||
outfp = StringIO()
|
outfp = StringIO()
|
||||||
decode(infp, outfp, header = header)
|
decode(infp, outfp, header = header)
|
||||||
|
|
|
@ -56,17 +56,8 @@ entries in the cache, and empty the cache (d.sync() also synchronizes
|
||||||
the persistent dictionary on disk, if feasible).
|
the persistent dictionary on disk, if feasible).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Try using cPickle and cStringIO if available.
|
from pickle import Pickler, Unpickler
|
||||||
|
from io import StringIO
|
||||||
try:
|
|
||||||
from cPickle import Pickler, Unpickler
|
|
||||||
except ImportError:
|
|
||||||
from pickle import Pickler, Unpickler
|
|
||||||
|
|
||||||
try:
|
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
import UserDict
|
import UserDict
|
||||||
import warnings
|
import warnings
|
||||||
|
|
|
@ -11,10 +11,7 @@ import os.path
|
||||||
import sys
|
import sys
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
__all__ = ["shlex", "split"]
|
__all__ = ["shlex", "split"]
|
||||||
|
|
||||||
|
|
|
@ -374,7 +374,7 @@ class PureProxy(SMTPServer):
|
||||||
|
|
||||||
class MailmanProxy(PureProxy):
|
class MailmanProxy(PureProxy):
|
||||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||||
from cStringIO import StringIO
|
from io import StringIO
|
||||||
from Mailman import Utils
|
from Mailman import Utils
|
||||||
from Mailman import Message
|
from Mailman import Message
|
||||||
from Mailman import MailList
|
from Mailman import MailList
|
||||||
|
|
|
@ -2459,10 +2459,7 @@ class TarFileCompat:
|
||||||
def write(self, filename, arcname=None, compress_type=None):
|
def write(self, filename, arcname=None, compress_type=None):
|
||||||
self.tarfile.add(filename, arcname)
|
self.tarfile.add(filename, arcname)
|
||||||
def writestr(self, zinfo, bytes):
|
def writestr(self, zinfo, bytes):
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
import calendar
|
import calendar
|
||||||
zinfo.name = zinfo.filename
|
zinfo.name = zinfo.filename
|
||||||
zinfo.size = zinfo.file_size
|
zinfo.size = zinfo.file_size
|
||||||
|
|
|
@ -37,10 +37,7 @@ if _os.name == 'mac':
|
||||||
import Carbon.Folder as _Folder
|
import Carbon.Folder as _Folder
|
||||||
import Carbon.Folders as _Folders
|
import Carbon.Folders as _Folders
|
||||||
|
|
||||||
try:
|
from io import StringIO as _StringIO
|
||||||
from cStringIO import StringIO as _StringIO
|
|
||||||
except:
|
|
||||||
from StringIO import StringIO as _StringIO
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import fcntl as _fcntl
|
import fcntl as _fcntl
|
||||||
|
|
|
@ -462,10 +462,7 @@ class URLopener:
|
||||||
def open_local_file(self, url):
|
def open_local_file(self, url):
|
||||||
"""Use local file."""
|
"""Use local file."""
|
||||||
import mimetypes, mimetools, email.utils
|
import mimetypes, mimetools, email.utils
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
host, file = splithost(url)
|
host, file = splithost(url)
|
||||||
localname = url2pathname(file)
|
localname = url2pathname(file)
|
||||||
try:
|
try:
|
||||||
|
@ -499,10 +496,7 @@ class URLopener:
|
||||||
if not isinstance(url, str):
|
if not isinstance(url, str):
|
||||||
raise IOError, ('ftp error', 'proxy support for ftp protocol currently not implemented')
|
raise IOError, ('ftp error', 'proxy support for ftp protocol currently not implemented')
|
||||||
import mimetypes, mimetools
|
import mimetypes, mimetools
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
host, path = splithost(url)
|
host, path = splithost(url)
|
||||||
if not host: raise IOError, ('ftp error', 'no host given')
|
if not host: raise IOError, ('ftp error', 'no host given')
|
||||||
host, port = splitport(host)
|
host, port = splitport(host)
|
||||||
|
@ -568,10 +562,7 @@ class URLopener:
|
||||||
# data := *urlchar
|
# data := *urlchar
|
||||||
# parameter := attribute "=" value
|
# parameter := attribute "=" value
|
||||||
import mimetools
|
import mimetools
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
try:
|
try:
|
||||||
[type, data] = url.split(',', 1)
|
[type, data] = url.split(',', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -821,10 +812,7 @@ def noheaders():
|
||||||
global _noheaders
|
global _noheaders
|
||||||
if _noheaders is None:
|
if _noheaders is None:
|
||||||
import mimetools
|
import mimetools
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
_noheaders = mimetools.Message(StringIO(), 0)
|
_noheaders = mimetools.Message(StringIO(), 0)
|
||||||
_noheaders.fp.close() # Recycle file descriptor
|
_noheaders.fp.close() # Recycle file descriptor
|
||||||
return _noheaders
|
return _noheaders
|
||||||
|
|
|
@ -101,10 +101,7 @@ import time
|
||||||
import urlparse
|
import urlparse
|
||||||
import bisect
|
import bisect
|
||||||
|
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
|
|
||||||
from urllib import (unwrap, unquote, splittype, splithost, quote,
|
from urllib import (unwrap, unquote, splittype, splithost, quote,
|
||||||
addinfourl, splitport, splitgophertype, splitquery,
|
addinfourl, splitport, splitgophertype, splitquery,
|
||||||
|
|
|
@ -350,10 +350,7 @@ def test():
|
||||||
else:
|
else:
|
||||||
fp = open(fn)
|
fp = open(fn)
|
||||||
else:
|
else:
|
||||||
try:
|
from io import StringIO
|
||||||
from cStringIO import StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO
|
|
||||||
fp = StringIO(test_input)
|
fp = StringIO(test_input)
|
||||||
while 1:
|
while 1:
|
||||||
line = fp.readline()
|
line = fp.readline()
|
||||||
|
|
|
@ -5,10 +5,7 @@ See: RFC 1014
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import struct
|
import struct
|
||||||
try:
|
from io import StringIO as _StringIO
|
||||||
from cStringIO import StringIO as _StringIO
|
|
||||||
except ImportError:
|
|
||||||
from StringIO import StringIO as _StringIO
|
|
||||||
|
|
||||||
__all__ = ["Error", "Packer", "Unpacker", "ConversionError"]
|
__all__ = ["Error", "Packer", "Unpacker", "ConversionError"]
|
||||||
|
|
||||||
|
|
|
@ -370,10 +370,7 @@ def _datetime_type(data):
|
||||||
# @param data An 8-bit string containing arbitrary data.
|
# @param data An 8-bit string containing arbitrary data.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
try:
|
import io
|
||||||
import cStringIO as StringIO
|
|
||||||
except ImportError:
|
|
||||||
import StringIO
|
|
||||||
|
|
||||||
class Binary:
|
class Binary:
|
||||||
"""Wrapper for binary data."""
|
"""Wrapper for binary data."""
|
||||||
|
@ -404,7 +401,7 @@ class Binary:
|
||||||
|
|
||||||
def encode(self, out):
|
def encode(self, out):
|
||||||
out.write("<value><base64>\n")
|
out.write("<value><base64>\n")
|
||||||
base64.encode(StringIO.StringIO(self.data), out)
|
base64.encode(io.StringIO(self.data), out)
|
||||||
out.write("</base64></value>\n")
|
out.write("</base64></value>\n")
|
||||||
|
|
||||||
def _binary(data):
|
def _binary(data):
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Read and write ZIP files.
|
Read and write ZIP files.
|
||||||
"""
|
"""
|
||||||
import struct, os, time, sys
|
import struct, os, time, sys
|
||||||
import binascii, cStringIO
|
import binascii, io
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import zlib # We may need its compression method
|
import zlib # We may need its compression method
|
||||||
|
@ -661,7 +661,7 @@ class ZipFile:
|
||||||
self.start_dir = offset_cd + concat
|
self.start_dir = offset_cd + concat
|
||||||
fp.seek(self.start_dir, 0)
|
fp.seek(self.start_dir, 0)
|
||||||
data = fp.read(size_cd)
|
data = fp.read(size_cd)
|
||||||
fp = cStringIO.StringIO(data)
|
fp = io.StringIO(data)
|
||||||
total = 0
|
total = 0
|
||||||
while total < size_cd:
|
while total < size_cd:
|
||||||
centdir = fp.read(46)
|
centdir = fp.read(46)
|
||||||
|
|
Loading…
Reference in New Issue