Mercurial > hg-stable
changeset 27418:2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
There's no need to dynamically create wrappedfileobj class and define
close() as lambda. Also, __iter__() was missing.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 13 Dec 2015 20:01:11 +0900 |
parents | 9073a1e457c9 |
children | 7e2495bf0ad8 |
files | mercurial/cmdutil.py |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Sun Dec 13 19:57:54 2015 +0900 +++ b/mercurial/cmdutil.py Sun Dec 13 20:01:11 2015 +0900 @@ -438,6 +438,19 @@ raise error.Abort(_("invalid format spec '%%%s' in output filename") % inst.args[0]) +class _unclosablefile(object): + def __init__(self, fp): + self._fp = fp + + def close(self): + pass + + def __iter__(self): + return iter(self._fp) + + def __getattr__(self, attr): + return getattr(self._fp, attr) + def makefileobj(repo, pat, node=None, desc=None, total=None, seqno=None, revwidth=None, mode='wb', modemap=None, pathname=None): @@ -454,17 +467,7 @@ else: # if this fp can't be duped properly, return # a dummy object that can be closed - class wrappedfileobj(object): - noop = lambda x: None - def __init__(self, f): - self.f = f - def __getattr__(self, attr): - if attr == 'close': - return self.noop - else: - return getattr(self.f, attr) - - return wrappedfileobj(fp) + return _unclosablefile(fp) if util.safehasattr(pat, 'write') and writable: return pat if util.safehasattr(pat, 'read') and 'r' in mode: