From 68a890e79f660484d05482902663b6168f0bd71e Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Fri, 8 May 2009 15:08:09 +0000 Subject: Fixed #7712, #9404, #10249, #10300: a light refactor and cleanup of file storage and the `File` object. Thanks to Armin Ronacher and Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10717 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/files/utils.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 django/core/files/utils.py (limited to 'django/core/files/utils.py') diff --git a/django/core/files/utils.py b/django/core/files/utils.py new file mode 100644 index 0000000000..8cc212fe1f --- /dev/null +++ b/django/core/files/utils.py @@ -0,0 +1,29 @@ +class FileProxyMixin(object): + """ + A mixin class used to forward file methods to an underlaying file + object. The internal file object has to be called "file":: + + class FileProxy(FileProxyMixin): + def __init__(self, file): + self.file = file + """ + + encoding = property(lambda self: self.file.encoding) + fileno = property(lambda self: self.file.fileno) + flush = property(lambda self: self.file.flush) + isatty = property(lambda self: self.file.isatty) + newlines = property(lambda self: self.file.newlines) + read = property(lambda self: self.file.read) + readinto = property(lambda self: self.file.readinto) + readline = property(lambda self: self.file.readline) + readlines = property(lambda self: self.file.readlines) + seek = property(lambda self: self.file.seek) + softspace = property(lambda self: self.file.softspace) + tell = property(lambda self: self.file.tell) + truncate = property(lambda self: self.file.truncate) + write = property(lambda self: self.file.write) + writelines = property(lambda self: self.file.writelines) + xreadlines = property(lambda self: self.file.xreadlines) + + def __iter__(self): + return iter(self.file) -- cgit v1.2.1