pygments.util

Utility functions.

copyright:Copyright 2006-2013 by the Pygments team, see AUTHORS.
license:BSD, see LICENSE for details.
exception pygments.util.ClassNotFound[source]

If one of the get_*_by_* functions didn’t find a matching class.

pygments.util.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”’

pygments.util.html_doctype_matches(text)[source]

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

pygments.util.looks_like_xml(text)[source]

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

pygments.util.make_analysator(f)[source]

Return a static text analysation function that returns float values.

pygments.util.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 '^$')

pygments.util.unirange(a, b)[source]

Returns a regular expression string to match the given non-BMP range.

Project Versions

This Page