6. sphinx.util

Utility functions for Sphinx.

copyright:Copyright 2007-2016 by the Sphinx team, see AUTHORS.
license:BSD, see LICENSE for details.

6.1. Functions

copy_static_entry(source, targetdir, builder) Copy a HTML builder static_path entry from source to targetdir.
copyfile(source, dest) Copy a file and its modification times, if possible.
copytimes(source, dest) Copy a file’s modification times.
detect_encoding(readline) Like tokenize.detect_encoding() from Py3k, but a bit simplified.
docname_join(basedocname, docname)
encode_uri(uri)
ensuredir(path) Ensure that a path exists.
force_decode(string, encoding) Forcibly get a unicode string out of a bytestring.
format_exception_cut_frames([x]) Format an exception with traceback, but only the last x frames.
get_figtype(node) Return figtype for given node.
get_full_modname(modname, attribute)
get_matching_docs(dirname, suffixes[, ...]) Get all file names (without suffixes) matching a suffix in a directory, recursively.
get_matching_files(dirname[, exclude_matchers]) Get all file names in a directory, recursively.
get_module_source(modname) Try to find the source code for a module.
import_object(objname[, source])
iteritems(d, **kw) Return an iterator over the (key, value) pairs of a dictionary.
make_filename(string)
movefile(source, dest) Move a file, removing the destination if it exists.
mtimes_of_files(dirnames, suffix)
nested_parse_with_titles(state, content, node) Version of state.nested_parse() that allows titles and does not require titles to have the same decoration as the calling document.
open(filename[, mode, encoding, errors, ...]) Open an encoded file using the given mode and return a wrapped version providing transparent encoding/decoding.
os_path(canonicalpath)
parse_qsl(qs[, keep_blank_values, ...]) Parse a query given as a string argument.
parselinenos(spec, total) Parse a line number spec (such as “1,2,4-6”) and return a list of wanted line numbers.
patfilter(names, pat) Return the subset of the list NAMES that match PAT.
path_stabilize(filepath) normalize path separater and unicode string
quote_plus(s[, safe]) Quote the query fragment of a URL; replacing ‘ ‘ with ‘+’
relative_path(source, target) Build and return a path to target, relative to source (both files).
relative_uri(base, to) Return a relative URL from base to to.
rpartition(s, t) Similar to str.rpartition from 2.5, but doesn’t return the separator.
save_traceback(app) Save the current exception’s traceback in a temporary file.
split_explicit_title(text) Split role content into title and target, if given.
split_index_msg(type, value)
split_into(n, type, value) Split an index entry into a given number of parts at semicolons.
strip_colors(s)
urlencode(query[, doseq]) Encode a sequence of two-element tuples or dictionary into a URL query string.
urlsplit(url[, scheme, allow_fragments]) Parse a URL into 5 components: <scheme>://<netloc>/<path>?<query>#<fragment> Return a 5-tuple: (scheme, netloc, path, query, fragment).
urlunsplit(data) Combine the elements of a tuple as returned by urlsplit() into a complete URL as a string.
ustrftime(format, *args)
walk(top[, topdown, followlinks]) Backport of os.walk from 2.6, where the followlinks argument was added.

6.2. Classes

FilenameUniqDict() A dictionary that automatically generates unique names for its keys, interpreted as filenames, and keeps track of a set of docnames they appear in.
PeekableIterator(iterable) An iterator which wraps any iterable and makes it possible to peek to see what’s the next item.
Tee(stream1, stream2) File-like object writing to two streams.
attrdict
binary_type alias of str
deque deque([iterable[, maxlen]]) –> deque object
range alias of xrange
text_type alias of unicode

6.3. Exceptions

ExtensionError(message[, orig_exc]) Raised if something’s wrong with the configuration.
PycodeError
SphinxParallelError(orig_exc, traceback)