Rev 5224: Haul the context manager support for UI factories to the base class, to avoid breaking non-text programs. in http://bazaar.launchpad.net/~lifeless/bzr/fix-terminal-spew

Robert Collins robertc at robertcollins.net
Mon Jun 21 01:58:23 BST 2010


At http://bazaar.launchpad.net/~lifeless/bzr/fix-terminal-spew

------------------------------------------------------------
revno: 5224
revision-id: robertc at robertcollins.net-20100621005822-ao3u4rs1327bbl4x
parent: aaron at aaronbentley.com-20100513131820-4g1l5wsf8jjh9h5l
committer: Robert Collins <robertc at robertcollins.net>
branch nick: fix-terminal-spew
timestamp: Mon 2010-06-21 12:58:22 +1200
message:
  Haul the context manager support for UI factories to the base class, to avoid breaking non-text programs.
=== modified file 'bzrlib/ui/__init__.py'
--- a/bzrlib/ui/__init__.py	2010-03-25 07:34:15 +0000
+++ b/bzrlib/ui/__init__.py	2010-06-21 00:58:22 +0000
@@ -106,6 +106,9 @@
     This tells the library how to display things to the user.  Through this
     layer different applications can choose the style of UI.
 
+    UI Factories are also context managers, for some syntactic sugar some users
+    need.
+
     :ivar suppressed_warnings: Identifiers for user warnings that should 
         no be emitted.
     """
@@ -123,6 +126,21 @@
         self.suppressed_warnings = set()
         self._quiet = False
 
+    def __enter__(self):
+        """Context manager entry support.
+
+        Override in a concrete factory class if initialisation before use is
+        needed.
+        """
+
+    def __exit__(self, exc_type, exc_val, exc_tb):
+        """Context manager exit support.
+
+        Override in a concrete factory class if more cleanup than a simple
+        self.clear_term() is needed when the UIFactory is finished with.
+        """
+        self.clear_term()
+
     def be_quiet(self, state):
         """Tell the UI to be more quiet, or not.
 
@@ -352,7 +370,6 @@
                 "without an upgrade path.\n" % (inter.target._format,))
 
 
-
 class SilentUIFactory(UIFactory):
     """A UI Factory which never prints anything.
 

=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py	2010-05-13 13:18:20 +0000
+++ b/bzrlib/ui/text.py	2010-06-21 00:58:22 +0000
@@ -65,12 +65,6 @@
         # hook up the signals to watch for terminal size changes
         watch_sigwinch()
 
-    def __enter__(self):
-        pass
-
-    def __exit__(self, exc_type, exc_val, exc_tb):
-        self.clear_term()
-
     def be_quiet(self, state):
         if state and not self._quiet:
             self.clear_term()




More information about the bazaar-commits mailing list