scmutil: factor out common logic of delayclosedfile to reuse it
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Thu, 22 Sep 2016 21:51:56 +0900
changeset 29998 0c40e64d6154
parent 29997 041a77a223ca
child 29999 57830bd0e787
scmutil: factor out common logic of delayclosedfile to reuse it This is a preparation for the subsequent patch, which adds another proxy class for a file object.
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Thu Sep 22 13:20:06 2016 +0800
+++ b/mercurial/scmutil.py	Thu Sep 22 21:51:56 2016 +0900
@@ -1300,15 +1300,13 @@
     # experimental config: format.generaldelta
     return ui.configbool('format', 'generaldelta', False)
 
-class delayclosedfile(object):
-    """Proxy for a file object whose close is delayed.
+class closewrapbase(object):
+    """Base class of wrapper, which hooks closing
 
     Do not instantiate outside of the vfs layer.
     """
-
-    def __init__(self, fh, closer):
+    def __init__(self, fh):
         object.__setattr__(self, '_origfh', fh)
-        object.__setattr__(self, '_closer', closer)
 
     def __getattr__(self, attr):
         return getattr(self._origfh, attr)
@@ -1323,6 +1321,21 @@
         return self._origfh.__enter__()
 
     def __exit__(self, exc_type, exc_value, exc_tb):
+        raise NotImplementedError('attempted instantiating ' + str(type(self)))
+
+    def close(self):
+        raise NotImplementedError('attempted instantiating ' + str(type(self)))
+
+class delayclosedfile(closewrapbase):
+    """Proxy for a file object whose close is delayed.
+
+    Do not instantiate outside of the vfs layer.
+    """
+    def __init__(self, fh, closer):
+        super(delayclosedfile, self).__init__(fh)
+        object.__setattr__(self, '_closer', closer)
+
+    def __exit__(self, exc_type, exc_value, exc_tb):
         self._closer.close(self._origfh)
 
     def close(self):