module documentation

pygments.util ~~~~~~~~~~~~~ Utility functions. :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details.

Class Future Generic class to defer some work.
Class UnclosingTextIOWrapper Undocumented
Exception ClassNotFound Raised if one of the lookup functions didn't find a matching class.
Exception OptionError Undocumented
Function docstring_headline Undocumented
Function doctype_matches Check if the doctype matches a regular expression (if present).
Function duplicates_removed Returns a list with duplicates removed from the iterable `it`.
Function format_lines Formats a sequence of strings for output.
Function get_bool_opt Undocumented
Function get_choice_opt Undocumented
Function get_int_opt Undocumented
Function get_list_opt Undocumented
Function guess_decode Decode *text* with guessed encoding.
Function guess_decode_from_terminal Decode *text* coming from terminal *term*.
Function html_doctype_matches Check if the file looks like it has a html doctype.
Function looks_like_xml Check if a doctype exists or if we have some tags.
Function make_analysator Return a static text analyser function that returns float values.
Function shebang_matches 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_encoding Return our best guess of encoding for the given *term*.
Variable doctype_lookup_re Undocumented
Variable split_path_re Undocumented
Variable tag_re Undocumented
Variable xml_decl_re Undocumented
Variable _looks_like_xml_cache Undocumented
def docstring_headline(obj): (source)

Undocumented

def doctype_matches(text, regex): (source)

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"'

def duplicates_removed(it, already_seen=()): (source)

Returns a list with duplicates removed from the iterable `it`. Order is preserved.

def format_lines(var_name, seq, raw=False, indent_level=0): (source)

Formats a sequence of strings for output.

def get_bool_opt(options, optname, default=None): (source)

Undocumented

def get_choice_opt(options, optname, allowed, default=None, normcase=False): (source)

Undocumented

def get_int_opt(options, optname, default=None): (source)

Undocumented

def get_list_opt(options, optname, default=None): (source)

Undocumented

def guess_decode(text): (source)

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.

def guess_decode_from_terminal(text, term): (source)

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.

def html_doctype_matches(text): (source)

Check if the file looks like it has a html doctype.

def looks_like_xml(text): (source)

Check if a doctype exists or if we have some tags.

def make_analysator(f): (source)

Return a static text analyser function that returns float values.

def shebang_matches(text, regex): (source)

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 ``'^$'``)

def surrogatepair(c): (source)

Given a unicode character code with length greater than 16 bits, return the two 16 bit surrogate pair.

def terminal_encoding(term): (source)

Return our best guess of encoding for the given *term*.

doctype_lookup_re = (source)

Undocumented

split_path_re = (source)

Undocumented

Undocumented

xml_decl_re = (source)

Undocumented

_looks_like_xml_cache: dict = (source)

Undocumented