# HG changeset patch # User Augie Fackler # Date 2011-07-25 20:09:17 # Node ID 3aa34005a73df5d46cd81835b7faa2ed7591c1af # Parent 28762bf809d8602d4ac7babd35d9443e7b64b515 byterange: replace uses of hasattr with getattr diff --git a/mercurial/byterange.py b/mercurial/byterange.py --- a/mercurial/byterange.py +++ b/mercurial/byterange.py @@ -103,9 +103,7 @@ class RangeableFileObject(object): """This effectively allows us to wrap at the instance level. Any attribute not found in _this_ object will be searched for in self.fo. This includes methods.""" - if hasattr(self.fo, name): - return getattr(self.fo, name) - raise AttributeError(name) + return getattr(self.fo, name) def tell(self): """Return the position within the range. @@ -170,10 +168,8 @@ class RangeableFileObject(object): offset is relative to the current position (self.realpos). """ assert offset >= 0 - if not hasattr(self.fo, 'seek'): - self._poor_mans_seek(offset) - else: - self.fo.seek(self.realpos + offset) + seek = getattr(self.fo, 'seek', self._poor_mans_seek) + seek(self.realpos + offset) self.realpos += offset def _poor_mans_seek(self, offset):