From b0938bb51c915ea5d888e2e88bbb62f4d1da199c Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 1 Jul 2012 11:38:29 +0200 Subject: make HtdigestTokenGenerator work with py3k Define a textopen function that returns "native strings" (in the sense of pep3333). Therefore textopen needs to decode using iso-8859-1 iff running on py3k. Additionally use a with construct to close the file being read in all circumstances. --- wsgitools/internal.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'wsgitools/internal.py') diff --git a/wsgitools/internal.py b/wsgitools/internal.py index c392b6a..c4f1da1 100644 --- a/wsgitools/internal.py +++ b/wsgitools/internal.py @@ -5,6 +5,8 @@ if bytes is str: 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) @@ -12,3 +14,6 @@ else: 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") -- cgit v1.2.3