Patchwork [1,of,9,V2] scmutil: factor out common logic of delayclosedfile to reuse it

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Sept. 22, 2016, 12:59 p.m.
Message ID <f2f665437a4939b06d9d.1474549160@feefifofum>
Download mbox | patch
Permalink /patch/16747/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - Sept. 22, 2016, 12:59 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1474548716 -32400
#      Thu Sep 22 21:51:56 2016 +0900
# Node ID f2f665437a4939b06d9d03ae70f41f51bc5338f4
# Parent  5271ae66615207f39cc41d78f4541bc6f8ca6ff6
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.

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1300,15 +1300,13 @@  def gddeltaconfig(ui):
     # 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 @@  class delayclosedfile(object):
         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):