~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/filters/__init__.py

  • Committer: Patch Queue Manager
  • Date: 2016-01-15 09:21:49 UTC
  • mfrom: (6606.2.1 autodoc-unicode)
  • Revision ID: pqm@pqm.ubuntu.com-20160115092149-z5f4sfq3jvaz0enb
(vila) Fix autodoc runner when LANG=C. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Working tree content filtering support.
19
18
 
20
19
A filter consists of a read converter, write converter pair.
21
20
The content in the working tree is called the convenience format
22
 
while the content actually stored in called the canonical format.
 
21
while the content actually stored is called the canonical format.
23
22
The read converter produces canonical content from convenience
24
23
content while the writer goes the other way.
25
24
 
39
38
Note that context is currently only supported for write converters.
40
39
"""
41
40
 
 
41
from __future__ import absolute_import
42
42
 
43
43
from cStringIO import StringIO
44
44
from bzrlib.lazy_import import lazy_import
50
50
    registry,
51
51
    )
52
52
""")
 
53
from bzrlib.symbol_versioning import (
 
54
    deprecated_function,
 
55
    deprecated_in,
 
56
    )
53
57
 
54
58
 
55
59
class ContentFilter(object):
86
90
        # Cached values
87
91
        self._revision_id = None
88
92
        self._revision = None
89
 
        self._config = None
90
93
 
91
94
    def relpath(self):
92
95
        """Relative path of file to tree-root."""
127
130
                self._revision = repo.get_revision(rev_id)
128
131
        return self._revision
129
132
 
130
 
    def config(self):
131
 
        """The Config object to search for configuration settings."""
132
 
        if self._config is None:
133
 
            branch = getattr(self._tree, 'branch', None)
134
 
            if branch is not None:
135
 
                self._config = branch.get_config()
136
 
            else:
137
 
                self._config = config.GlobalConfig()
138
 
        return self._config
139
 
 
140
133
 
141
134
def filtered_input_file(f, filters):
142
135
    """Get an input file that converts external to internal content.
187
180
 
188
181
 
189
182
# The registry of filter stacks indexed by name.
190
 
# See register_filter_stack_map for details on the registered values.
191
 
_filter_stacks_registry = registry.Registry()
 
183
filter_stacks_registry = registry.Registry()
192
184
 
193
185
 
194
186
# Cache of preferences -> stack
196
188
_stack_cache = {}
197
189
 
198
190
 
 
191
# XXX: This function doesn't have any tests. JRV 2012-03-29
 
192
@deprecated_function(deprecated_in((2, 6, 0)))
199
193
def register_filter_stack_map(name, stack_map_lookup):
200
194
    """Register the filter stacks to use for various preference values.
201
195
 
205
199
      the result is the matching stack of filters to use,
206
200
      or None if none.
207
201
    """
208
 
    if name in _filter_stacks_registry:
209
 
        raise errors.BzrError(
210
 
            "filter stack for %s already installed" % name)
211
 
    _filter_stacks_registry.register(name, stack_map_lookup)
212
 
 
213
 
 
 
202
    filter_stacks_registry.register(name, stack_map_lookup)
 
203
 
 
204
 
 
205
# XXX: This function doesn't have any tests. JRV 2012-03-29
 
206
@deprecated_function(deprecated_in((2, 6, 0)))
214
207
def lazy_register_filter_stack_map(name, module_name, member_name):
215
208
    """Lazily register the filter stacks to use for various preference values.
216
209
 
219
212
    :param member_name: The name of the stack_map_lookup callable
220
213
      in the module.
221
214
    """
222
 
    if name in _filter_stacks_registry:
223
 
        raise errors.BzrError(
224
 
            "filter stack for %s already installed" % name)
225
 
    _filter_stacks_registry.register_lazy(name, module_name, member_name)
 
215
    filter_stacks_registry.register_lazy(name, module_name, member_name)
226
216
 
227
217
 
228
218
def _get_registered_names():
229
219
    """Get the list of names with filters registered."""
230
220
    # Note: We may want to intelligently order these later.
231
221
    # If so, the register_ fn will need to support an optional priority.
232
 
    return _filter_stacks_registry.keys()
 
222
    return filter_stacks_registry.keys()
233
223
 
234
224
 
235
225
def _get_filter_stack_for(preferences):
250
240
        if v is None:
251
241
            continue
252
242
        try:
253
 
            stack_map_lookup = _filter_stacks_registry.get(k)
 
243
            stack_map_lookup = filter_stacks_registry.get(k)
254
244
        except KeyError:
255
245
            # Some preferences may not have associated filters
256
246
            continue
273
263
    :param value: the value to set the registry to or None for an empty one.
274
264
    :return: the existing value before it reset.
275
265
    """
276
 
    global _filter_stacks_registry
277
 
    original = _filter_stacks_registry
 
266
    global filter_stacks_registry
 
267
    original = filter_stacks_registry
278
268
    if value is None:
279
 
        _filter_stacks_registry = registry.Registry()
 
269
        filter_stacks_registry = registry.Registry()
280
270
    else:
281
 
        _filter_stacks_registry = value
 
271
        filter_stacks_registry = value
282
272
    _stack_cache.clear()
283
273
    return original
284
274
 
285
275
 
286
 
# Register the standard filters
287
 
from bzrlib.filters import eol
288
 
eol.register_eol_content_filter()
 
276
filter_stacks_registry.register_lazy('eol', 'bzrlib.filters.eol', 'eol_lookup')