Part of bzrlib
A filter consists of a read converter, write converter pair. The content in the working tree is called the convenience format while the content actually stored in called the canonical format. The read converter produces canonical content from convenience content while the writer goes the other way.
Converters have the following signatures:
read_converter(chunks) -> chunks write_converter(chunks, context) -> chunks
where:
- chunks is an iterator over a sequence of byte strings
- context is an optional ContentFilterContent object (possibly None) providing converters access to interesting information, e.g. the relative path of the file.
Note that context is currently only supported for write converters.
Module | eol | End of Line Conversion filters. |
From the __init__.py module:
Class | ContentFilter | No class docstring; 1/2 methods documented |
Class | ContentFilterContext | Object providing information that filters can use. |
Function | filtered_input_file | Get an input file that converts external to internal content. |
Function | filtered_output_bytes | Convert byte chunks from internal to external format. |
Function | internal_size_sha_file_byname | Get size and sha of internal content given external content. |
Function | lazy_register_filter_stack_map | Lazily register the filter stacks to use for various preference values. |
Function | register_filter_stack_map | Register the filter stacks to use for various preference values. |
Function | _get_filter_stack_for | Get the filter stack given a sequence of preferences. |
Function | _get_registered_names | Get the list of names with filters registered. |
Function | _reset_registry | Reset the filter stack registry. |
Parameters | f | the original input file |
filters | the stack of filters to apply | |
Returns | a file-like object |
Parameters | chunks | an iterator containing the original content |
filters | the stack of filters to apply | |
context | a ContentFilterContext object passed to each filter | |
Returns | an iterator containing the content to output |
Parameters | name | path to file |
filters | the stack of filters to apply |
Parameters | name | the preference/filter-stack name |
stack_map_lookup | a callable where the parameter is the preference value to match and the result is the matching stack of filters to use, or None if none. |
Parameters | name | the preference/filter-stack name |
module_name | The python path to the module of the filter stack map. | |
member_name | The name of the stack_map_lookup callable in the module. |
Parameters | preferences | a sequence of (name,value) tuples where name is the preference name and value is the key into the filter stack map registered for that preference. |
Reset the filter stack registry.
This function is provided to aid testing. The expected usage is:
old = _reset_registry() # run tests _reset_registry(old)
Parameters | value | the value to set the registry to or None for an empty one. |
Returns | the existing value before it reset. |