Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
filter.py
Go to the documentation of this file.
1
"""
2
pygments.filter
3
~~~~~~~~~~~~~~~
4
5
Module that implements the default filter.
6
7
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8
:license: BSD, see LICENSE for details.
9
"""
10
11
12
def
apply_filters(stream, filters, lexer=None):
13
"""
14
Use this method to apply an iterable of filters to
15
a stream. If lexer is given it's forwarded to the
16
filter, otherwise the filter receives `None`.
17
"""
18
def
_apply
(filter_, stream):
19
yield
from
filter_.filter
(lexer, stream)
20
for
filter_
in
filters:
21
stream =
_apply
(filter_, stream)
22
return
stream
23
24
25
def
simplefilter
(f):
26
"""
27
Decorator that converts a function into a filter::
28
29
@simplefilter
30
def lowercase(self, lexer, stream, options):
31
for ttype, value in stream:
32
yield ttype, value.lower()
33
"""
34
return
type(
f.__name__
, (FunctionFilter,), {
35
'__module__'
:
getattr
(f,
'__module__'
),
36
'__doc__'
:
f.__doc__
,
37
'function'
: f,
38
})
39
40
41
class
Filter
:
42
"""
43
Default filter. Subclass this class or use the `simplefilter`
44
decorator to create own filters.
45
"""
46
47
def
__init__
(self, **options):
48
self.
options
= options
49
50
def
filter(self, lexer, stream):
51
raise
NotImplementedError
()
52
53
54
class
FunctionFilter
(
Filter
):
55
"""
56
Abstract class used by `simplefilter` to create simple
57
function filters on the fly. The `simplefilter` decorator
58
automatically creates subclasses of this class for
59
functions passed to it.
60
"""
61
function =
None
62
63
def
__init__
(self, **options):
64
if
not
hasattr
(self,
'function'
):
65
raise
TypeError(
'%r used without bound function'
%
66
self.__class__.__name__)
67
Filter.__init__
(self, **options)
68
69
def
filter(self, lexer, stream):
70
# pylint: disable=not-callable
71
yield
from
self.
function
(lexer, stream, self.
options
options
)
pip._vendor.pygments.filter.Filter
Definition
filter.py:41
pip._vendor.pygments.filter.Filter.options
options
Definition
filter.py:48
pip._vendor.pygments.filter.Filter.__init__
__init__(self, **options)
Definition
filter.py:47
pip._vendor.pygments.filter.FunctionFilter
Definition
filter.py:54
pip._vendor.pygments.filter.FunctionFilter.options
options
Definition
filter.py:71
pip._vendor.pygments.filter.FunctionFilter.__init__
__init__(self, **options)
Definition
filter.py:63
pip._vendor.pygments.filter.FunctionFilter.function
function
Definition
filter.py:61
pip._vendor.pygments.filter.simplefilter
simplefilter(f)
Definition
filter.py:25
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_vendor
pygments
filter.py
Generated by
1.9.8