aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Pygments/py3/pygments/formatters/__init__.py
diff options
context:
space:
mode:
authorilezhankin <ilezhankin@yandex-team.ru>2022-02-10 16:45:55 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:55 +0300
commit1d125034f06575234f83f24f08677955133f140e (patch)
treeec05fbbd61dc118d5de37f206ab978cff58774bd /contrib/python/Pygments/py3/pygments/formatters/__init__.py
parent3a7a498715ef1b66f5054455421b845e45e3a653 (diff)
downloadydb-1d125034f06575234f83f24f08677955133f140e.tar.gz
Restoring authorship annotation for <ilezhankin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/Pygments/py3/pygments/formatters/__init__.py')
-rw-r--r--contrib/python/Pygments/py3/pygments/formatters/__init__.py222
1 files changed, 111 insertions, 111 deletions
diff --git a/contrib/python/Pygments/py3/pygments/formatters/__init__.py b/contrib/python/Pygments/py3/pygments/formatters/__init__.py
index 66c9e9d404..4d64cf9ca6 100644
--- a/contrib/python/Pygments/py3/pygments/formatters/__init__.py
+++ b/contrib/python/Pygments/py3/pygments/formatters/__init__.py
@@ -1,83 +1,83 @@
-"""
- pygments.formatters
- ~~~~~~~~~~~~~~~~~~~
-
- Pygments formatters.
-
+"""
+ pygments.formatters
+ ~~~~~~~~~~~~~~~~~~~
+
+ Pygments formatters.
+
:copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
- :license: BSD, see LICENSE for details.
-"""
-
-import re
-import sys
-import types
-import fnmatch
-from os.path import basename
-
-from pygments.formatters._mapping import FORMATTERS
-from pygments.plugin import find_plugin_formatters
+ :license: BSD, see LICENSE for details.
+"""
+
+import re
+import sys
+import types
+import fnmatch
+from os.path import basename
+
+from pygments.formatters._mapping import FORMATTERS
+from pygments.plugin import find_plugin_formatters
from pygments.util import ClassNotFound
-
-__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
+
+__all__ = ['get_formatter_by_name', 'get_formatter_for_filename',
'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS)
-
-_formatter_cache = {} # classes by name
-_pattern_cache = {}
-
-
-def _fn_matches(fn, glob):
- """Return whether the supplied file name fn matches pattern filename."""
- if glob not in _pattern_cache:
- pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
- return pattern.match(fn)
- return _pattern_cache[glob].match(fn)
-
-
-def _load_formatters(module_name):
- """Load a formatter (and all others in the module too)."""
- mod = __import__(module_name, None, None, ['__all__'])
- for formatter_name in mod.__all__:
- cls = getattr(mod, formatter_name)
- _formatter_cache[cls.name] = cls
-
-
-def get_all_formatters():
- """Return a generator for all formatter classes."""
- # NB: this returns formatter classes, not info like get_all_lexers().
+
+_formatter_cache = {} # classes by name
+_pattern_cache = {}
+
+
+def _fn_matches(fn, glob):
+ """Return whether the supplied file name fn matches pattern filename."""
+ if glob not in _pattern_cache:
+ pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
+ return pattern.match(fn)
+ return _pattern_cache[glob].match(fn)
+
+
+def _load_formatters(module_name):
+ """Load a formatter (and all others in the module too)."""
+ mod = __import__(module_name, None, None, ['__all__'])
+ for formatter_name in mod.__all__:
+ cls = getattr(mod, formatter_name)
+ _formatter_cache[cls.name] = cls
+
+
+def get_all_formatters():
+ """Return a generator for all formatter classes."""
+ # NB: this returns formatter classes, not info like get_all_lexers().
for info in FORMATTERS.values():
- if info[1] not in _formatter_cache:
- _load_formatters(info[0])
- yield _formatter_cache[info[1]]
- for _, formatter in find_plugin_formatters():
- yield formatter
-
-
-def find_formatter_class(alias):
- """Lookup a formatter by alias.
-
- Returns None if not found.
- """
+ if info[1] not in _formatter_cache:
+ _load_formatters(info[0])
+ yield _formatter_cache[info[1]]
+ for _, formatter in find_plugin_formatters():
+ yield formatter
+
+
+def find_formatter_class(alias):
+ """Lookup a formatter by alias.
+
+ Returns None if not found.
+ """
for module_name, name, aliases, _, _ in FORMATTERS.values():
- if alias in aliases:
- if name not in _formatter_cache:
- _load_formatters(module_name)
- return _formatter_cache[name]
- for _, cls in find_plugin_formatters():
- if alias in cls.aliases:
- return cls
-
-
-def get_formatter_by_name(_alias, **options):
- """Lookup and instantiate a formatter by alias.
-
- Raises ClassNotFound if not found.
- """
- cls = find_formatter_class(_alias)
- if cls is None:
- raise ClassNotFound("no formatter found for name %r" % _alias)
- return cls(**options)
-
-
+ if alias in aliases:
+ if name not in _formatter_cache:
+ _load_formatters(module_name)
+ return _formatter_cache[name]
+ for _, cls in find_plugin_formatters():
+ if alias in cls.aliases:
+ return cls
+
+
+def get_formatter_by_name(_alias, **options):
+ """Lookup and instantiate a formatter by alias.
+
+ Raises ClassNotFound if not found.
+ """
+ cls = find_formatter_class(_alias)
+ if cls is None:
+ raise ClassNotFound("no formatter found for name %r" % _alias)
+ return cls(**options)
+
+
def load_formatter_from_file(filename, formattername="CustomFormatter",
**options):
"""Load a formatter from a file.
@@ -114,40 +114,40 @@ def load_formatter_from_file(filename, formattername="CustomFormatter",
raise ClassNotFound('error when loading custom formatter: %s' % err)
-def get_formatter_for_filename(fn, **options):
- """Lookup and instantiate a formatter by filename pattern.
-
- Raises ClassNotFound if not found.
- """
- fn = basename(fn)
+def get_formatter_for_filename(fn, **options):
+ """Lookup and instantiate a formatter by filename pattern.
+
+ Raises ClassNotFound if not found.
+ """
+ fn = basename(fn)
for modname, name, _, filenames, _ in FORMATTERS.values():
- for filename in filenames:
- if _fn_matches(fn, filename):
- if name not in _formatter_cache:
- _load_formatters(modname)
- return _formatter_cache[name](**options)
- for cls in find_plugin_formatters():
- for filename in cls.filenames:
- if _fn_matches(fn, filename):
- return cls(**options)
- raise ClassNotFound("no formatter found for file name %r" % fn)
-
-
-class _automodule(types.ModuleType):
- """Automatically import formatters."""
-
- def __getattr__(self, name):
- info = FORMATTERS.get(name)
- if info:
- _load_formatters(info[0])
- cls = _formatter_cache[info[1]]
- setattr(self, name, cls)
- return cls
- raise AttributeError(name)
-
-
-oldmod = sys.modules[__name__]
-newmod = _automodule(__name__)
-newmod.__dict__.update(oldmod.__dict__)
-sys.modules[__name__] = newmod
-del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types
+ for filename in filenames:
+ if _fn_matches(fn, filename):
+ if name not in _formatter_cache:
+ _load_formatters(modname)
+ return _formatter_cache[name](**options)
+ for cls in find_plugin_formatters():
+ for filename in cls.filenames:
+ if _fn_matches(fn, filename):
+ return cls(**options)
+ raise ClassNotFound("no formatter found for file name %r" % fn)
+
+
+class _automodule(types.ModuleType):
+ """Automatically import formatters."""
+
+ def __getattr__(self, name):
+ info = FORMATTERS.get(name)
+ if info:
+ _load_formatters(info[0])
+ cls = _formatter_cache[info[1]]
+ setattr(self, name, cls)
+ return cls
+ raise AttributeError(name)
+
+
+oldmod = sys.modules[__name__]
+newmod = _automodule(__name__)
+newmod.__dict__.update(oldmod.__dict__)
+sys.modules[__name__] = newmod
+del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types