##// END OF EJS Templates
scmutil: factor out common logic of delayclosedfile to reuse it...
FUJIWARA Katsunori -
r29994:0c40e64d default
parent child Browse files
Show More
@@ -1300,15 +1300,13 b' def gddeltaconfig(ui):'
1300 # experimental config: format.generaldelta
1300 # experimental config: format.generaldelta
1301 return ui.configbool('format', 'generaldelta', False)
1301 return ui.configbool('format', 'generaldelta', False)
1302
1302
1303 class delayclosedfile(object):
1303 class closewrapbase(object):
1304 """Proxy for a file object whose close is delayed.
1304 """Base class of wrapper, which hooks closing
1305
1305
1306 Do not instantiate outside of the vfs layer.
1306 Do not instantiate outside of the vfs layer.
1307 """
1307 """
1308
1308 def __init__(self, fh):
1309 def __init__(self, fh, closer):
1310 object.__setattr__(self, '_origfh', fh)
1309 object.__setattr__(self, '_origfh', fh)
1311 object.__setattr__(self, '_closer', closer)
1312
1310
1313 def __getattr__(self, attr):
1311 def __getattr__(self, attr):
1314 return getattr(self._origfh, attr)
1312 return getattr(self._origfh, attr)
@@ -1323,6 +1321,21 b' class delayclosedfile(object):'
1323 return self._origfh.__enter__()
1321 return self._origfh.__enter__()
1324
1322
1325 def __exit__(self, exc_type, exc_value, exc_tb):
1323 def __exit__(self, exc_type, exc_value, exc_tb):
1324 raise NotImplementedError('attempted instantiating ' + str(type(self)))
1325
1326 def close(self):
1327 raise NotImplementedError('attempted instantiating ' + str(type(self)))
1328
1329 class delayclosedfile(closewrapbase):
1330 """Proxy for a file object whose close is delayed.
1331
1332 Do not instantiate outside of the vfs layer.
1333 """
1334 def __init__(self, fh, closer):
1335 super(delayclosedfile, self).__init__(fh)
1336 object.__setattr__(self, '_closer', closer)
1337
1338 def __exit__(self, exc_type, exc_value, exc_tb):
1326 self._closer.close(self._origfh)
1339 self._closer.close(self._origfh)
1327
1340
1328 def close(self):
1341 def close(self):
General Comments 0
You need to be logged in to leave comments. Login now