pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details.
Class |
|
Generic class to defer some work. |
Class |
|
Undocumented |
Exception |
|
Raised if one of the lookup functions didn't find a matching class. |
Exception |
|
Undocumented |
Function | docstring |
Undocumented |
Function | doctype |
Check if the doctype matches a regular expression (if present). |
Function | duplicates |
Returns a list with duplicates removed from the iterable `it`. |
Function | format |
Formats a sequence of strings for output. |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | get |
Undocumented |
Function | guess |
Decode *text* with guessed encoding. |
Function | guess |
Decode *text* coming from terminal *term*. |
Function | html |
Check if the file looks like it has a html doctype. |
Function | looks |
Check if a doctype exists or if we have some tags. |
Function | make |
Return a static text analyser function that returns float values. |
Function | shebang |
Check if the given regular expression matches the last part of the shebang if one exists. |
Function | surrogatepair |
Given a unicode character code with length greater than 16 bits, return the two 16 bit surrogate pair. |
Function | terminal |
Return our best guess of encoding for the given *term*. |
Variable | doctype |
Undocumented |
Variable | split |
Undocumented |
Variable | tag |
Undocumented |
Variable | xml |
Undocumented |
Variable | _looks |
Undocumented |
Check if the doctype matches a regular expression (if present). Note that this method only checks the first part of a DOCTYPE. eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
Decode *text* with guessed encoding. First try UTF-8; this should fail for non-UTF-8 encodings. Then try the preferred locale encoding. Fall back to latin-1, which always works.
Decode *text* coming from terminal *term*. First try the terminal encoding, if given. Then try UTF-8. Then try the preferred locale encoding. Fall back to latin-1, which always works.
Check if the given regular expression matches the last part of the shebang if one exists. >>> from pygments.util import shebang_matches >>> shebang_matches('#!/usr/bin/env python', r'python(2\.\d)?') True >>> shebang_matches('#!/usr/bin/python2.4', r'python(2\.\d)?') True >>> shebang_matches('#!/usr/bin/python-ruby', r'python(2\.\d)?') False >>> shebang_matches('#!/usr/bin/python/ruby', r'python(2\.\d)?') False >>> shebang_matches('#!/usr/bin/startsomethingwith python', ... r'python(2\.\d)?') True It also checks for common windows executable file extensions:: >>> shebang_matches('#!C:\\Python2.4\\Python.exe', r'python(2\.\d)?') True Parameters (``'-f'`` or ``'--foo'`` are ignored so ``'perl'`` does the same as ``'perl -e'``) Note that this method automatically searches the whole string (eg: the regular expression is wrapped in ``'^$'``)