summaryrefslogtreecommitdiff
path: root/wsgitools/internal.py
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2015-04-18 20:38:13 +0200
committerHelmut Grohne <helmut@subdivi.de>2015-04-18 20:38:13 +0200
commit828d8f22ee3e785692d019ed02c4f7874792a8e9 (patch)
treeb14886c4cca174d993ee7e882ea4f4ba3eabb55e /wsgitools/internal.py
parent42f5ccf09799d3e475eb996b023a0daabae49cdb (diff)
parentc1ba0c783fc59dc8d00b9b8aed7250569bcc14d4 (diff)
downloadwsgitools-828d8f22ee3e785692d019ed02c4f7874792a8e9.tar.gz
Merge branch py3k
Diffstat (limited to 'wsgitools/internal.py')
-rw-r--r--wsgitools/internal.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/wsgitools/internal.py b/wsgitools/internal.py
new file mode 100644
index 0000000..c4f1da1
--- /dev/null
+++ b/wsgitools/internal.py
@@ -0,0 +1,19 @@
+if bytes is str:
+ def bytes2str(bstr):
+ assert isinstance(bstr, bytes)
+ return bstr
+ def str2bytes(sstr):
+ assert isinstance(sstr, str)
+ return sstr
+ def textopen(filename, mode):
+ return open(filename, mode)
+else:
+ def bytes2str(bstr):
+ assert isinstance(bstr, bytes)
+ return bstr.decode("iso-8859-1") # always successful
+ def str2bytes(sstr):
+ assert isinstance(sstr, str)
+ return sstr.encode("iso-8859-1") # might fail, but spec says it doesn't
+ def textopen(filename, mode):
+ # We use the same encoding as for all wsgi strings here.
+ return open(filename, mode, encoding="iso-8859-1")