Rev 6517: (jelmer) Deprecate {lazy_, }register_filter_stack_map. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Fri Mar 30 02:23:42 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6517 [merge]
revision-id: pqm at pqm.ubuntu.com-20120330022341-y0a4sazkuim25wh0
parent: pqm at pqm.ubuntu.com-20120330015847-a0usc8fbawzc1bu4
parent: jelmer at samba.org-20120329145416-fj8qchygrc4d9uwr
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2012-03-30 02:23:41 +0000
message:
  (jelmer) Deprecate {lazy_,}register_filter_stack_map. (Jelmer Vernooij)
modified:
  bzrlib/filters/__init__.py     __init__.py-20080416080515-mkxl29amuwrf6uir-2
  bzrlib/tests/test_filters.py   test_filters.py-20080417120614-tc3zok0vvvprsc99-1
  bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
  doc/en/release-notes/bzr-2.6.txt bzr2.6.txt-20120116134316-8w1xxom1c7vcu1t5-1
=== modified file 'bzrlib/filters/__init__.py'
--- a/bzrlib/filters/__init__.py	2011-12-19 13:23:58 +0000
+++ b/bzrlib/filters/__init__.py	2012-03-29 14:54:16 +0000
@@ -50,6 +50,10 @@
     registry,
     )
 """)
+from bzrlib.symbol_versioning import (
+    deprecated_function,
+    deprecated_in,
+    )
 
 
 class ContentFilter(object):
@@ -187,8 +191,7 @@
 
 
 # The registry of filter stacks indexed by name.
-# See register_filter_stack_map for details on the registered values.
-_filter_stacks_registry = registry.Registry()
+filter_stacks_registry = registry.Registry()
 
 
 # Cache of preferences -> stack
@@ -196,6 +199,8 @@
 _stack_cache = {}
 
 
+# XXX: This function doesn't have any tests. JRV 2012-03-29
+ at deprecated_function(deprecated_in((2, 6, 0)))
 def register_filter_stack_map(name, stack_map_lookup):
     """Register the filter stacks to use for various preference values.
 
@@ -205,12 +210,11 @@
       the result is the matching stack of filters to use,
       or None if none.
     """
-    if name in _filter_stacks_registry:
-        raise errors.BzrError(
-            "filter stack for %s already installed" % name)
-    _filter_stacks_registry.register(name, stack_map_lookup)
-
-
+    filter_stacks_registry.register(name, stack_map_lookup)
+
+
+# XXX: This function doesn't have any tests. JRV 2012-03-29
+ at deprecated_function(deprecated_in((2, 6, 0)))
 def lazy_register_filter_stack_map(name, module_name, member_name):
     """Lazily register the filter stacks to use for various preference values.
 
@@ -219,17 +223,14 @@
     :param member_name: The name of the stack_map_lookup callable
       in the module.
     """
-    if name in _filter_stacks_registry:
-        raise errors.BzrError(
-            "filter stack for %s already installed" % name)
-    _filter_stacks_registry.register_lazy(name, module_name, member_name)
+    filter_stacks_registry.register_lazy(name, module_name, member_name)
 
 
 def _get_registered_names():
     """Get the list of names with filters registered."""
     # Note: We may want to intelligently order these later.
     # If so, the register_ fn will need to support an optional priority.
-    return _filter_stacks_registry.keys()
+    return filter_stacks_registry.keys()
 
 
 def _get_filter_stack_for(preferences):
@@ -250,7 +251,7 @@
         if v is None:
             continue
         try:
-            stack_map_lookup = _filter_stacks_registry.get(k)
+            stack_map_lookup = filter_stacks_registry.get(k)
         except KeyError:
             # Some preferences may not have associated filters
             continue
@@ -273,14 +274,14 @@
     :param value: the value to set the registry to or None for an empty one.
     :return: the existing value before it reset.
     """
-    global _filter_stacks_registry
-    original = _filter_stacks_registry
+    global filter_stacks_registry
+    original = filter_stacks_registry
     if value is None:
-        _filter_stacks_registry = registry.Registry()
+        filter_stacks_registry = registry.Registry()
     else:
-        _filter_stacks_registry = value
+        filter_stacks_registry = value
     _stack_cache.clear()
     return original
 
 
-lazy_register_filter_stack_map('eol', 'bzrlib.filters.eol', 'eol_lookup')
+filter_stacks_registry.register_lazy('eol', 'bzrlib.filters.eol', 'eol_lookup')

=== modified file 'bzrlib/tests/test_filters.py'
--- a/bzrlib/tests/test_filters.py	2009-06-10 23:29:48 +0000
+++ b/bzrlib/tests/test_filters.py	2012-03-29 14:54:16 +0000
@@ -24,7 +24,6 @@
     _get_filter_stack_for,
     _get_registered_names,
     internal_size_sha_file_byname,
-    register_filter_stack_map,
     )
 from bzrlib.osutils import sha_string
 from bzrlib.tests import TestCase, TestCaseInTempDir
@@ -114,51 +113,45 @@
     def _register_map(self, pref, stk1, stk2):
         def stk_lookup(key):
             return {'v1': stk1, 'v2': stk2}.get(key)
-        register_filter_stack_map(pref, stk_lookup)
+        filters.filter_stacks_registry.register(pref, stk_lookup)
 
     def test_filter_stack_maps(self):
         # Save the current registry
         original_registry = filters._reset_registry()
-        try:
-            # Test registration
-            a_stack = [ContentFilter('b', 'c')]
-            z_stack = [ContentFilter('y', 'x'), ContentFilter('w', 'v')]
-            self._register_map('foo', a_stack, z_stack)
-            self.assertEqual(['foo'], _get_registered_names())
-            self._register_map('bar', z_stack, a_stack)
-            self.assertEqual(['bar', 'foo'], _get_registered_names())
-            # Test re-registration raises an error
-            self.assertRaises(errors.BzrError, self._register_map,
-                'foo', [], [])
-        finally:
-            # Restore the real registry
-            filters._reset_registry(original_registry)
+        self.addCleanup(filters._reset_registry, original_registry)
+        # Test registration
+        a_stack = [ContentFilter('b', 'c')]
+        z_stack = [ContentFilter('y', 'x'), ContentFilter('w', 'v')]
+        self._register_map('foo', a_stack, z_stack)
+        self.assertEqual(['foo'], _get_registered_names())
+        self._register_map('bar', z_stack, a_stack)
+        self.assertEqual(['bar', 'foo'], _get_registered_names())
+        # Test re-registration raises an error
+        self.assertRaises(KeyError, self._register_map,
+            'foo', [], [])
 
     def test_get_filter_stack_for(self):
         # Save the current registry
         original_registry = filters._reset_registry()
-        try:
-            # Test filter stack lookup
-            a_stack = [ContentFilter('b', 'c')]
-            d_stack = [ContentFilter('d', 'D')]
-            z_stack = [ContentFilter('y', 'x'), ContentFilter('w', 'v')]
-            self._register_map('foo', a_stack, z_stack)
-            self._register_map('bar', d_stack, z_stack)
-            prefs = (('foo','v1'),)
-            self.assertEqual(a_stack, _get_filter_stack_for(prefs))
-            prefs = (('foo','v2'),)
-            self.assertEqual(z_stack, _get_filter_stack_for(prefs))
-            prefs = (('foo','v1'), ('bar','v1'))
-            self.assertEqual(a_stack + d_stack, _get_filter_stack_for(prefs))
-            # Test an unknown preference
-            prefs = (('baz','v1'),)
-            self.assertEqual([], _get_filter_stack_for(prefs))
-            # Test an unknown value
-            prefs = (('foo','v3'),)
-            self.assertEqual([], _get_filter_stack_for(prefs))
-            # Test a value of None is skipped
-            prefs = (('foo',None), ('bar', 'v1'))
-            self.assertEqual(d_stack, _get_filter_stack_for(prefs))
-        finally:
-            # Restore the real registry
-            filters._reset_registry(original_registry)
+        self.addCleanup(filters._reset_registry, original_registry)
+        # Test filter stack lookup
+        a_stack = [ContentFilter('b', 'c')]
+        d_stack = [ContentFilter('d', 'D')]
+        z_stack = [ContentFilter('y', 'x'), ContentFilter('w', 'v')]
+        self._register_map('foo', a_stack, z_stack)
+        self._register_map('bar', d_stack, z_stack)
+        prefs = (('foo','v1'),)
+        self.assertEqual(a_stack, _get_filter_stack_for(prefs))
+        prefs = (('foo','v2'),)
+        self.assertEqual(z_stack, _get_filter_stack_for(prefs))
+        prefs = (('foo','v1'), ('bar','v1'))
+        self.assertEqual(a_stack + d_stack, _get_filter_stack_for(prefs))
+        # Test an unknown preference
+        prefs = (('baz','v1'),)
+        self.assertEqual([], _get_filter_stack_for(prefs))
+        # Test an unknown value
+        prefs = (('foo','v3'),)
+        self.assertEqual([], _get_filter_stack_for(prefs))
+        # Test a value of None is skipped
+        prefs = (('foo',None), ('bar', 'v1'))
+        self.assertEqual(d_stack, _get_filter_stack_for(prefs))

=== modified file 'bzrlib/tests/test_transform.py'
--- a/bzrlib/tests/test_transform.py	2012-03-14 10:17:12 +0000
+++ b/bzrlib/tests/test_transform.py	2012-03-30 02:23:41 +0000
@@ -2184,7 +2184,8 @@
         def rot13(chunks, context=None):
             return [''.join(chunks).encode('rot13')]
         rot13filter = filters.ContentFilter(rot13, rot13)
-        filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
+        filters.filter_stacks_registry.register(
+            'rot13', {'yes': [rot13filter]}.get)
         os.mkdir(self.test_home_dir + '/.bazaar')
         rules_filename = self.test_home_dir + '/.bazaar/rules'
         f = open(rules_filename, 'wb')

=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- a/doc/en/release-notes/bzr-2.6.txt	2012-03-30 01:58:47 +0000
+++ b/doc/en/release-notes/bzr-2.6.txt	2012-03-30 02:23:41 +0000
@@ -163,9 +163,10 @@
 * New convenience API method ``WorkingTree.get_config_stack``.
   (Jelmer Vernooij)
 
-* Remove deprecated ``Branch.set_revision_history`` and
-  ``Branch.revision_history`` methods and the ``set_rh``
-  hook on ``Branch``. (Jelmer Vernooij)
+* ``register_filter_stack_map`` and ``lazy_register_filter_stack_map``
+  are noew deprecated. Instead, use ``filter_stacks_registry.register``
+  and ``filter_stacks_registry.register_lazy``.
+  (Jelmer Vernooij)
 
 * Remove 
   ``branch.PullResult.__int__`` deprecated in 2.3.0,
@@ -196,6 +197,10 @@
   ``workingtree.WorkingTreeFormat.unregister_format`` deprecated in 2.4.0,
   (Vincent Ladeuil)
 
+* Remove deprecated ``Branch.set_revision_history`` and
+  ``Branch.revision_history`` methods and the ``set_rh``
+  hook on ``Branch``. (Jelmer Vernooij)
+
 Internals
 *********
 




More information about the bazaar-commits mailing list