diff options
author | Nils Philippsen <nils@redhat.com> | 2015-08-19 16:32:16 +0200 |
---|---|---|
committer | Nils Philippsen <nils@redhat.com> | 2015-08-19 16:32:16 +0200 |
commit | be901601473bd3ba5826d86fb9912843a3517a07 (patch) | |
tree | 0d3ae1654e6901f23fce39da78b4ec21cf201562 /paste/util/filemixin.py | |
download | paste-git-be901601473bd3ba5826d86fb9912843a3517a07.tar.gz |
Python 3: App must always return binary type.
Fixes tests.test_wsgiwrappers.test_wsgirequest_charset
Diffstat (limited to 'paste/util/filemixin.py')
-rw-r--r-- | paste/util/filemixin.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/paste/util/filemixin.py b/paste/util/filemixin.py new file mode 100644 index 0000000..b06b039 --- /dev/null +++ b/paste/util/filemixin.py @@ -0,0 +1,53 @@ +# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) +# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php + +class FileMixin(object): + + """ + Used to provide auxiliary methods to objects simulating files. + Objects must implement write, and read if they are input files. + Also they should implement close. + + Other methods you may wish to override: + * flush() + * seek(offset[, whence]) + * tell() + * truncate([size]) + + Attributes you may wish to provide: + * closed + * encoding (you should also respect that in write()) + * mode + * newlines (hard to support) + * softspace + """ + + def flush(self): + pass + + def next(self): + return self.readline() + + def readline(self, size=None): + # @@: This is a lame implementation; but a buffer would probably + # be necessary for a better implementation + output = [] + while 1: + next = self.read(1) + if not next: + return ''.join(output) + output.append(next) + if size and size > 0 and len(output) >= size: + return ''.join(output) + if next == '\n': + # @@: also \r? + return ''.join(output) + + def xreadlines(self): + return self + + def writelines(self, lines): + for line in lines: + self.write(line) + + |