Commits

Anonymous committed 78ca1c9

trunk - more changes to bring the two branches into a more similar state - this time normalizing StringIO imports.

Comments (0)

Files changed (14)

cherrypy/_cpmodpy.py

 """
 
 import logging
-import StringIO
 
 import cherrypy
+from cherrypy.py3util import StringIO
 from cherrypy._cperror import format_exc, bare_error
 from cherrypy.lib import httputil
 
                         method = "GET"
                         path = ir.path
                         qs = ir.query_string
-                        rfile = StringIO.StringIO()
+                        rfile = StringIO()
                 
                 send_response(req, response.status, response.header_list,
                               response.body, response.stream)

cherrypy/_cpwsgi.py

 """WSGI interface (see PEP 333)."""
 
-import StringIO as _StringIO
 import sys as _sys
 
 import cherrypy as _cherrypy
+from cherrypy.py3util import StringIO
 from cherrypy import _cperror
 from cherrypy.lib import httputil
 
         env['REQUEST_METHOD'] = "GET"
         env['PATH_INFO'] = path
         env['QUERY_STRING'] = query_string
-        env['wsgi.input'] = _StringIO.StringIO()
+        env['wsgi.input'] = StringIO()
         env['CONTENT_LENGTH'] = "0"
         
         self.setapp()

cherrypy/lib/encoding.py

 
 
 def decompress(body):
-    import gzip, StringIO
+    import gzip
+    from cherrypy.py3util import StringIO
     
-    zbuf = StringIO.StringIO()
+    zbuf = StringIO()
     zbuf.write(body)
     zbuf.seek(0)
     zfile = gzip.GzipFile(mode='rb', fileobj=zbuf)

cherrypy/lib/profiler.py

 import os, os.path
 import sys
 
-try:
-    from cStringIO import StringIO
-except ImportError:
-    from StringIO import StringIO
-
+from cherrypy.py3util import StringIO
 
 _count = 0
 

cherrypy/lib/tidy.py

 
 import cgi
 import os
-from StringIO import StringIO
+from cherrypy.py3util import StringIO
 import traceback
 
 import cherrypy

cherrypy/py3util.py

     output = sep.join(['%s' % arg for arg in args]) + end
     file.write(output)
 
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from StringIO import StringIO
+

cherrypy/test/test_config.py

 
 import os, sys
 localDir = os.path.join(os.getcwd(), os.path.dirname(__file__))
-import StringIO
 
 import cherrypy
+from cherrypy.py3util import StringIO
 import unittest
 
 def setup_server():
         incr.exposed = True
         incr._cp_config = {'raw.input.map': {'num': int}}
     
-    ioconf = StringIO.StringIO("""
+    ioconf = StringIO("""
 [/]
 neg: -1234
 filename: os.path.join(sys.prefix, "hello.py")
             'foo': 'this3',
             'bax': 'this4',
             }
-        for key, expected in expectedconf.iteritems():
+        for key, expected in expectedconf.items():
             self.getPage("/foo/bar?key=" + key)
             self.assertBody(repr(expected))
     
 class VariableSubstitutionTests(unittest.TestCase):
     
     def test_config(self):
-        import StringIO
         from textwrap import dedent
     
         # variable substitution with [DEFAULT]
 
         """)
 
-        fp = StringIO.StringIO(conf)
+        fp = StringIO(conf)
 
         cherrypy.config.update(fp)
         self.assertEqual(cherrypy.config["my"]["my.dir"], "/some/dir/my/dir")

cherrypy/test/test_config_server.py

 import os, sys
 localDir = os.path.join(os.getcwd(), os.path.dirname(__file__))
 import socket
-import StringIO
 import time
 
 import cherrypy
 
-
 def setup_server():
     
     class Root:

cherrypy/test/test_encoding.py

 test.prefer_parent_path()
 
 import sys
-import gzip, StringIO
+import gzip
 from httplib import IncompleteRead
 import cherrypy
+from cherrypy.py3util import StringIO
 europoundUnicode = u'\x80\xa3'
 sing = u"\u6bdb\u6cfd\u4e1c: Sing, Little Birdie?"
 sing8 = sing.encode('utf-8')
         self.assertStatus("406 Not Acceptable")
     
     def testGzip(self):
-        zbuf = StringIO.StringIO()
+        zbuf = StringIO()
         zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9)
         zfile.write("Hello, world")
         zfile.close()

cherrypy/test/test_mime.py

-"""Tests for various MIME issues."""
+"""Tests for various MIME issues, including the safe_multipart Tool."""
 
 from cherrypy.test import test
 test.prefer_parent_path()

cherrypy/test/test_request_obj.py

         callable_object = ParamErrorsCallable()
 
         def raise_type_error(self, **kwargs):
-            raise TypeError, "Client Error"
+            raise TypeError("Client Error")
         raise_type_error.exposed = True
 
 

cherrypy/test/test_tools.py

 """Test the various means of instantiating and invoking tools."""
 
 import gzip
-import StringIO
 import sys
 from httplib import IncompleteRead
 import time
 test.prefer_parent_path()
 
 import cherrypy
+from cherrypy.py3util import StringIO
 from cherrypy import tools
 
 
     cherrypy.tools.rotator = cherrypy.Tool('before_finalize', Rotator())
     
     def stream_handler(next_handler, *args, **kwargs):
-        cherrypy.response.output = o = StringIO.StringIO()
+        cherrypy.response.output = o = StringIO()
         try:
             response = next_handler(*args, **kwargs)
             # Ignore the response and return our accumulated output instead.
     
     def testCombinedTools(self):
         expectedResult = (u"Hello,world" + europoundUnicode).encode('utf-8')
-        zbuf = StringIO.StringIO()
+        zbuf = StringIO()
         zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=9)
         zfile.write(expectedResult)
         zfile.close()
                                         ("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")])
         self.assertInBody(zbuf.getvalue()[:3])
         
-        zbuf = StringIO.StringIO()
+        zbuf = StringIO()
         zfile = gzip.GzipFile(mode='wb', fileobj=zbuf, compresslevel=6)
         zfile.write(expectedResult)
         zfile.close()

cherrypy/test/test_wsgi_vhost.py

     default = cherrypy.Application(None)
     
     domains = {}
-    for year in xrange(1997, 2008):
+    for year in range(1997, 2008):
         app = cherrypy.Application(ClassOfRoot('Class of %s' % year))
         domains['www.classof%s.example' % year] = app
     
             cherrypy.py3print("skipped (not using WSGI)...", end=' ')
             return
         
-        for year in xrange(1997, 2008):
+        for year in range(1997, 2008):
             self.getPage("/", headers=[('Host', 'www.classof%s.example' % year)])
             self.assertBody("Welcome to the Class of %s website!" % year)
 

cherrypy/test/test_wsgiapps.py

         start_response(status, response_headers)
         output = ['Hello, world!\n',
                   'This is a wsgi app running within CherryPy!\n\n']
-        keys = environ.keys()
+        keys = list(environ.keys())
         keys.sort()
         for k in keys:
             output.append('%s: %s\n' % (k,environ[k]))