# HG changeset patch # User Yuya Nishihara # Date 2015-12-13 11:01:11 # Node ID 2ce4661ac226925f7505d598a28ef6d648bb4f86 # Parent 9073a1e457c9054c9dc0e47ab079962a56481331 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -438,6 +438,19 @@ def makefilename(repo, pat, node, desc=N 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 @@ def makefileobj(repo, pat, node=None, de 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: