From 28296eb94b01d0bcb97262d859c4e97390143ee3 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 19 Dec 2012 11:41:08 +0200 Subject: [PATCH] TransRead: get rid of the __getattr__ method The TransRead class implements very limited file-like objects. It is safer to explicitely specify all the methods it supports, instead of defaulting to the methods of the underlying 'transfile_obj'. Change-Id: I51c4ee16f0313e0b39741f10bc04d480e48d19dc Signed-off-by: Artem Bityutskiy --- bmaptools/TransRead.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bmaptools/TransRead.py b/bmaptools/TransRead.py index 1bbe169..9cba9a5 100644 --- a/bmaptools/TransRead.py +++ b/bmaptools/TransRead.py @@ -243,9 +243,10 @@ class TransRead: if self._file_obj: self._file_obj.close() - def __getattr__(self, name): - """ Called for all attributes that do not exist in the 'TransRead' - class. We are pretending to be file-like objects, so we just return the - attributes of the '_transfile_obj' file-like object. """ + def seek(self, offset, whence = os.SEEK_SET): + """ The 'seek()' method, similar to the one file objects have. """ + self._transfile_obj.seek(offset, whence) - return getattr(self._transfile_obj, name) + def tell(self): + """ The 'tell()' method, similar to the one file objects have. """ + return self._transfile_obj.tell() -- 2.7.4