Patchwork [1,of,2] windows: add context manager support to mixedfilemodewrapper

login
register
mail settings
Submitter Matt Harbison
Date April 12, 2017, 2:42 a.m.
Message ID <ef3aa25da8e5b3137b91.1491964962@Envy>
Download mbox | patch
Permalink /patch/20125/
State Accepted
Headers show

Comments

Matt Harbison - April 12, 2017, 2:42 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1491961091 14400
#      Tue Apr 11 21:38:11 2017 -0400
# Node ID ef3aa25da8e5b3137b917e9a1756df7a7eac5c3a
# Parent  7b6f5632f09d85b96b2f986961576eb165d44cbf
windows: add context manager support to mixedfilemodewrapper

I stumbled into this in the next patch.  The difference between getting a
context manager capable object or not from vfs classes was as subtle as adding a
'+' to the file mode.

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -64,6 +64,12 @@ 
         object.__setattr__(self, r'_fp', fp)
         object.__setattr__(self, r'_lastop', 0)
 
+    def __enter__(self):
+        return self._fp.__enter__()
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        self._fp.__exit__(exc_type, exc_val, exc_tb)
+
     def __getattr__(self, name):
         return getattr(self._fp, name)