core

multiwith(*managers)[source]

Taken from contextlib’s nested(). We need the variable number of context managers that this function allows.

is_identifier(ident)[source]

Determines if string is valid Python identifier.

remove_duplicates(lst, key=<function <lambda>>)[source]

Remove duplicate values from a list, keeping just the first one, using a particular key function to compare them.

infinite_cycle(iterable)[source]

Iterate infinitely over the given iterable.

Watch out for calling this on a generator or iter: they can only be iterated over once, so you’ll get stuck in an infinite loop with no more items yielded once you’ve gone over it once.

You may also specify a callable, in which case it will be called each time to get a new iterable/iterator. This is useful in the case of generator functions.

Parameters:iterable – iterable or generator to loop over indefinitely
import_member(path)[source]

Import a class, function, or other module member by its fully-qualified Python name.

Parameters:path – path to member, including full package path and class/function/etc name
Returns:cls
split_seq(seq, separator, ignore_empty_final=False)[source]

Iterate over a sequence and group its values into lists, separated in the original sequence by the given value. If on is callable, it is called on each element to test whether it is a separator. Otherwise, elements that are equal to on a treated as separators.

Parameters:
  • seq – sequence to divide up
  • separator – separator or separator test function
  • ignore_empty_final – by default, if there’s a separator at the end, the last sequence yielded is empty. If ignore_empty_final=True, in this case the last empty sequence is dropped
Returns:

iterator over subsequences

split_seq_after(seq, separator)[source]

Somewhat like split_seq, but starts a new subsequence after each separator, without removing the separators. Each subsequence therefore ends with a separator, except the last one if there’s no separator at the end.

Parameters:
  • seq – sequence to divide up
  • separator – separator or separator test function
Returns:

iterator over subsequences

chunk_list(lst, length)[source]

Divides a list into chunks of max length length.

class cached_property(func)[source]

Bases: object

A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property.

Often useful in Pimlico datatypes, where it can be time-consuming to load data, but we can’t do it once when the datatype is first loaded, since the data might not be ready at that point. Instead, we can access the data, or particular parts of it, using properties and easily cache the result.

Taken from: https://github.com/bottlepy/bottle