diff options
author | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-16 14:21:42 +0200 |
---|---|---|
committer | Emilio Pozuelo Monfort <pochu@debian.org> | 2020-07-29 10:20:41 +0200 |
commit | 98f3af78b58d33272664a3d2873be4fb5ea367b2 (patch) | |
tree | 1987a49998c89b69df0df3326ef7238a6c60d861 /lib | |
parent | 2a122964f52a313dfb215edbb622413de705a0a3 (diff) |
web_support.py: adapt StringIO for python3
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/web_support.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/python/web_support.py b/lib/python/web_support.py index e12a13201a..ebbf031944 100644 --- a/lib/python/web_support.py +++ b/lib/python/web_support.py @@ -16,7 +16,6 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import cgi -import cStringIO import os import re import socket @@ -29,6 +28,11 @@ import threading import SocketServer import BaseHTTPServer +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO + from helpers import isstring class ServinvokeError(Exception): @@ -111,7 +115,7 @@ class Service: else: break data = ''.join(data) - result = cStringIO.StringIO() + result = StringIO() self.handle(cli, env, data, result) client.sendall(result.getvalue()) client.close() @@ -124,7 +128,7 @@ class Service: raise except: client.close() - target = cStringIO.StringIO() + target = StringIO() traceback.print_exc(None, target) self.log("%s", target.getvalue()) @@ -252,7 +256,7 @@ class HTMLBase: def toString(self): """Invokes flatten to create a new string object.""" - r = cStringIO.StringIO() + r = StringIO() self.flatten(r.write) return r.getvalue() @@ -346,7 +350,7 @@ class Tag(HTMLBase): return "<websupport.Tag instance, name=%s>" % repr(self.__name) def toString(self): - r = cStringIO.StringIO() + r = StringIO() self.flatten(r.write) return r.getvalue() @@ -652,7 +656,7 @@ class HTMLResult(Result): def flatten_later(self): headers_later = super(HTMLResult, self).flatten_later() - buf = cStringIO.StringIO() + buf = StringIO() buf.write(self.doctype) buf.write('\n') def write_both(s): @@ -895,7 +899,7 @@ def __test(): == '<td><a href="http://www.example.net/">example</a></td>' #assert make_pre(['a', 'b']).toString() == '<pre>a\nb\n</pre>' - s = cStringIO.StringIO() + s = StringIO() RedirectResult(u.scriptRelativeFull("123")).flatten(s.write) assert s.getvalue() == '''Location: http://localhost.localdomain/cgi-bin/test.cgi/123 |