##// END OF EJS Templates
cmdutil: return a dummy, closable file object if it cannot be duped...
Idan Kamara -
r14638:1bdbca0b default
parent child Browse files
Show More
@@ -161,7 +161,22 b' def makefileobj(repo, pat, node=None, to'
161 161
162 162 if not pat or pat == '-':
163 163 fp = writable and repo.ui.fout or repo.ui.fin
164 return os.fdopen(os.dup(fp.fileno()), mode)
164 if hasattr(fp, 'fileno'):
165 return os.fdopen(os.dup(fp.fileno()), mode)
166 else:
167 # if this fp can't be duped properly, return
168 # a dummy object that can be closed
169 class wrappedfileobj(object):
170 noop = lambda x: None
171 def __init__(self, f):
172 self.f = f
173 def __getattr__(self, attr):
174 if attr == 'close':
175 return self.noop
176 else:
177 return getattr(self.f, attr)
178
179 return wrappedfileobj(fp)
165 180 if hasattr(pat, 'write') and writable:
166 181 return pat
167 182 if hasattr(pat, 'read') and 'r' in mode:
General Comments 0
You need to be logged in to leave comments. Login now