utilities
index
/home/daniel/projects/moosic/moosic-1.4.10/utilities.py

A library of commonly useful functions and classes.
 
This module contains a varied collection of functions and classes that are
potentially useful in a wide range of programming tasks.
 
It is safe to "import *" from this module.

 
Modules
       
operator
random
re
string

 
Functions
       
antigrep(regex, seq)
Returns a list of the elements of "seq" that do not match the regular
expression represented by "regex", which may be a string or a regular
expression object.
canLoopOver(maybeIterable)
Tests whether an object can be looped over.
center_text(text, line_width=80, pad_char='-')
Returns the given text centered within a line, with padding.
flatten(seq, scalarp=<function isScalar>)
Flattens a nested sequence.
 
For example, [[1, 2], [3, [4, 5]] becomes [1, 2, 3, 4, 5].
grep(regex, seq)
Returns a list of the elements of "seq" that match the regular expression
represented by "regex", which may be a string or a regular expression
object.
isScalar(obj)
Tests whether an object is a scalar value.  Strings are considered scalar.
isStringLike(obj)
Tests whether an object behaves like a string.
make_string_filter(keep)
Return a function that takes a string and returns a partial copy of that
string consisting only of the characters in 'keep'.
parse_range(range, start=0, end=0)
Changes a string representing a range into the indices of the range.
 
This function converts a string with a form similar to that of the Python
array slice notation into into a pair of ints which represent the starting
and ending indices of of the slice.
 
If the string contains a pair of colon-separated integers, a 2-tuple of
ints with the respective values of those integers will be returned.  If the
first number in this pair is omitted, then the value of the "start"
argument is used.  If the second number in this pair is omitted, then the
value of the "end" argument is used.
 
If the string contains a single integer, then a pair of ints with the
value of that integer and its successor, respectively, will be returned.
The to this rule is when the successor of the single integer is zero, in
which case the value of the second element of the returned pair will be the
value of the "end" argument.
 
If the string contains anything else, it is considered invalid and a
ValueError will be thrown.
sh_escape(text)
Returns a version of the given text that uses backslashes to make it
safe to pass to a Bourne-type shell if you enclose it in double quotes.
shuffle(seq)
Returns a shuffled version of the given sequence. (Deprecated)
 
The returned list contains exactly the same elements as the given sequence,
but in a random order.  This function is much slower than the shuffle
function in the random module in the standard library, and it returns a new
list instead of shuffling the sequence in place.  Using this function is not
recommended.
staggered_merge(*sequences)
Merges multiple sequences, interleaving their elements.
 
This returns a sequence whose elements alternate between the elements of
the input sequences.  For example, if the input sequences are (1, 2, 3) and
(11, 12, 13), then the output will be (1, 11, 2, 12, 3, 13).  And if the
input sequences are (a, b, c), (v, w, x, y, z), and (q, r, s, t), then the
output will be (a, v, q, b, w, r, c, x, s, y, t, z).
 
Beware that this function throws away input elements that are equal to
None.  This is the price that must be paid in order to merge sequences of
different lengths.
uniq(seq)
Returns a list of all the elements of the given sequence in their
original order, but without duplicates.
 
Unlike the Unix tool of the same name, duplicates are removed even if they
aren't adjacent.  This function only works if the elements of the input
sequence are hashable.
wrap(text, width)
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are posix newlines (\n).
xmlrpc_server_doc(server_proxy)
Produces documentation for the methods of an XML-RPC server.
 
This function queries an XML-RPC server via the introspection API, and
returns a collection of descriptions that document each of the server's
methods. The returned collection is a dictionary whose keys are the names of
the methods and whose values are blurbs of text that describe the methods.
 
This was inspired by the xml-rpc-api2txt Perl script that comes with
xmlrpc-c.

 
Data
        __all__ = ('grep', 'antigrep', 'staggered_merge', 'parse_range', 'wrap', 'xmlrpc_server_doc', 'center_text', 'uniq', 'sh_escape', 'flatten', 'canLoopOver', 'isStringLike', 'isScalar', 'make_string_filter')
generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 4096)