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.
--- 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: