@header@
 
 
matplotlib.cbook
index
/home/jdhunter/dev/lib/python2.5/site-packages/matplotlib/cbook.py

A collection of utility functions and classes.  Many (but not all)
from the Python Cookbook -- hence the name cbook

 
Modules
       
StringIO
__builtin__
datetime
errno
itertools
locale
numpy
os
re
sys
time
traceback

 
Classes
       
__builtin__.dict(__builtin__.object)
Xlator
maxdict
__builtin__.list(__builtin__.object)
silent_list
Bunch
CallbackRegistry
GetRealpathAndStat
MemoryMonitor
Null
RingBuffer
Sorter
Stack
converter
todate
todatetime
tofloat
toint
tostr

 
class Bunch
    Often we want to just collect a bunch of stuff together, naming each
item of the bunch; a dictionary's OK for that, but a small do- nothing
class is even handier, and prettier to use.  Whenever you want to
group a few variables:
 
  >>> point = Bunch(datum=2, squared=4, coord=12)
  >>> point.datum
 
  By: Alex Martelli
  From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308
 
  Methods defined here:
__init__(self, **kwds)

 
class CallbackRegistry
    Handle registering and disconnecting for a set of signals and
callbacks
 
   signals = 'eat', 'drink', 'be merry'
 
   def oneat(x):
       print 'eat', x
 
   def ondrink(x):
       print 'drink', x
 
   callbacks = CallbackRegistry(signals)
 
   ideat = callbacks.connect('eat', oneat)
   iddrink = callbacks.connect('drink', ondrink)
 
   #tmp = callbacks.connect('drunk', ondrink) # this will raise a ValueError
 
   callbacks.process('drink', 123)    # will call oneat
   callbacks.process('eat', 456)      # will call ondrink
   callbacks.process('be merry', 456) # nothing will be called
   callbacks.disconnect(ideat)        # disconnect oneat
   callbacks.process('eat', 456)      # nothing will be called
 
  Methods defined here:
__init__(self, signals)
signals is a sequence of valid signals
connect(self, s, func)
register func to be called when a signal s is generated
func will be called
disconnect(self, cid)
disconnect the callback registered with callback id cid
process(self, s, *args, **kwargs)
process signal s.  All of the functions registered to receive
callbacks on s will be called with *args and **kwargs

 
class GetRealpathAndStat
     Methods defined here:
__call__(self, path)
__init__(self)

 
class MemoryMonitor
     Methods defined here:
__call__(self)
__init__(self, nmax=20000)
clear(self)
plot(self, i0=0, isub=1, fig=None)
report(self, segments=4)
xy(self, i0=0, isub=1)

 
class Null
    Null objects always and reliably "do nothing."
 
  Methods defined here:
__call__(self, *args, **kwargs)
__delattr__(self, name)
__getattr__(self, name)
__init__(self, *args, **kwargs)
__nonzero__(self)
__repr__(self)
__setattr__(self, name, value)
__str__(self)

 
class RingBuffer
    class that implements a not-yet-full buffer
 
  Methods defined here:
__get_item__(self, i)
__init__(self, size_max)
append(self, x)
append an element at the end of the buffer
get(self)
Return a list of elements from the oldest to the newest.

 
class Sorter
    Sort by attribute or item
 
Example usage:
sort = Sorter()
 
list = [(1, 2), (4, 8), (0, 3)]
dict = [{'a': 3, 'b': 4}, {'a': 5, 'b': 2}, {'a': 0, 'b': 0},
{'a': 9, 'b': 9}]
 
 
sort(list)       # default sort
sort(list, 1)    # sort by index 1
sort(dict, 'a')  # sort a list of dicts by key 'a'
 
  Methods defined here:
__call__ = byItem(self, data, itemindex=None, inplace=1)
byAttribute(self, data, attributename, inplace=1)
byItem(self, data, itemindex=None, inplace=1)
sort = byItem(self, data, itemindex=None, inplace=1)

 
class Stack
    Implement a stack where elements can be pushed on and you can move
back and forth.  But no pop.  Should mimic home / back / forward
in a browser
 
  Methods defined here:
__call__(self)
return the current element, or None
__init__(self, default=None)
back(self)
move the position back and return the current element
bubble(self, o)
raise o to the top of the stack and return o.  o must be in
the stack
clear(self)
empty the stack
empty(self)
forward(self)
move the position forward and return the current element
home(self)
push the first element onto the top of the stack
push(self, o)
push object onto stack at current position - all elements
occurring later than the current position are discarded
remove(self, o)
remove element o from the stack

 
class Xlator(__builtin__.dict)
    All-in-one multiple-string-substitution class
 
Example usage:
 
text = "Larry Wall is the creator of Perl"
adict = {
"Larry Wall" : "Guido van Rossum",
"creator" : "Benevolent Dictator for Life",
"Perl" : "Python",
}
 
print multiple_replace(adict, text)
 
xlat = Xlator(adict)
print xlat.xlat(text)
 
 
Method resolution order:
Xlator
__builtin__.dict
__builtin__.object

Methods defined here:
__call__(self, match)
Handler invoked for each regex match
xlat(self, text)
Translate text, returns the modified text.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
D.__contains__(k) -> True if D has a key k, else False
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update(E, **F) -> None.  Update D from E and F: for k in E: D[k] = E[k]
(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]
values(...)
D.values() -> list of D's values

Data and other attributes inherited from __builtin__.dict:
__new__ = <built-in method __new__ of type object at 0x8145420>
T.__new__(S, ...) -> a new object with type S, a subtype of T
fromkeys = <built-in method fromkeys of type object at 0x848d6f4>
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.

 
class converter
    Base class for handling string -> python type with support for
missing values
 
  Methods defined here:
__call__(self, s)
__init__(self, missing='Null', missingval=None)
is_missing(self, s)

 
class maxdict(__builtin__.dict)
    A dictionary with a maximum size; this doesn't override all the
relevant methods to contrain size, just setitem, so use with
caution
 
 
Method resolution order:
maxdict
__builtin__.dict
__builtin__.object

Methods defined here:
__init__(self, maxsize)
__setitem__(self, k, v)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
D.__contains__(k) -> True if D has a key k, else False
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update(E, **F) -> None.  Update D from E and F: for k in E: D[k] = E[k]
(if E has keys else: for (k, v) in E: D[k] = v) then: for k in F: D[k] = F[k]
values(...)
D.values() -> list of D's values

Data and other attributes inherited from __builtin__.dict:
__new__ = <built-in method __new__ of type object at 0x8145420>
T.__new__(S, ...) -> a new object with type S, a subtype of T
fromkeys = <built-in method fromkeys of type object at 0x84e05c4>
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.

 
class silent_list(__builtin__.list)
    override repr when returning a list of matplotlib artists to
prevent long, meaningless output.  This is meant to be used for a
homogeneous list of a give type
 
 
Method resolution order:
silent_list
__builtin__.list
__builtin__.object

Methods defined here:
__init__(self, type, seq=None)
__repr__(self)
__str__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from __builtin__.list:
__add__(...)
x.__add__(y) <==> x+y
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__delslice__(...)
x.__delslice__(i, j) <==> del x[i:j]
 
Use of negative indices is not supported.
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__iadd__(...)
x.__iadd__(y) <==> x+=y
__imul__(...)
x.__imul__(y) <==> x*=y
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__mul__(...)
x.__mul__(n) <==> x*n
__ne__(...)
x.__ne__(y) <==> x!=y
__reversed__(...)
L.__reversed__() -- return a reverse iterator over the list
__rmul__(...)
x.__rmul__(n) <==> n*x
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
__setslice__(...)
x.__setslice__(i, j, y) <==> x[i:j]=y
 
Use  of negative indices is not supported.
append(...)
L.append(object) -- append object to end
count(...)
L.count(value) -> integer -- return number of occurrences of value
extend(...)
L.extend(iterable) -- extend list by appending elements from the iterable
index(...)
L.index(value, [start, [stop]]) -> integer -- return first index of value
insert(...)
L.insert(index, object) -- insert object before index
pop(...)
L.pop([index]) -> item -- remove and return item at index (default last)
remove(...)
L.remove(value) -- remove first occurrence of value
reverse(...)
L.reverse() -- reverse *IN PLACE*
sort(...)
L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*;
cmp(x, y) -> -1, 0, 1

Data and other attributes inherited from __builtin__.list:
__new__ = <built-in method __new__ of type object at 0x8144360>
T.__new__(S, ...) -> a new object with type S, a subtype of T

 
class todate(converter)
    convert to a date or None
 
  Methods defined here:
__call__(self, s)
__init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None)
use a time.strptime format string for conversion

Methods inherited from converter:
is_missing(self, s)

 
class todatetime(converter)
    convert to a datetime or None
 
  Methods defined here:
__call__(self, s)
__init__(self, fmt='%Y-%m-%d', missing='Null', missingval=None)
use a time.strptime format string for conversion

Methods inherited from converter:
is_missing(self, s)

 
class tofloat(converter)
    convert to a float or None
 
  Methods defined here:
__call__(self, s)
__init__(self, missing='Null', missingval=None)

Methods inherited from converter:
is_missing(self, s)

 
class toint(converter)
    convert to an int or None
 
  Methods defined here:
__call__(self, s)
__init__(self, missing='Null', missingval=None)

Methods inherited from converter:
is_missing(self, s)

 
class tostr(converter)
    convert to string or None
 
  Methods defined here:
__init__(self, missing='Null', missingval='')

Methods inherited from converter:
__call__(self, s)
is_missing(self, s)

 
Functions
       
allequal(seq)
return true if all elements of seq compare equal.  If seq is 0 or
1 length, return True
allpairs(x)
return all possible pairs in sequence x
 
Condensed by Alex Martelli from this thread on c.l.python
http://groups.google.com/groups?q=all+pairs+group:*python*&hl=en&lr=&ie=UTF-8&selm=mailman.4028.1096403649.5135.python-list%40python.org&rnum=1
alltrue(seq)
dedent(s)
Remove excess indentation from docstrings.
 
Discards any leading blank lines, then removes up to
n whitespace characters from each line, where n is
the number of leading whitespace characters in the
first line. It differs from textwrap.dedent in its
deletion of leading blank lines and its use of the
first non-blank line to determine the indentation.
 
It is also faster in most cases.
dict_delall(d, keys)
delete all of the keys from the dict d
exception_to_str(s=None)
finddir(o, match, case=False)
return all attributes of o which match string in match.  if case
is True require an exact case match.
flatten(seq, scalarp=<function is_scalar at 0x84976bc>)
this generator flattens nested containers such as
 
>>> l=( ('John', 'Hunter'), (1,23), [[[[42,(5,23)]]]])
 
so that
 
>>> for i in flatten(l): print i,
John Hunter 1 23 42 5 23
 
By: Composite of Holger Krekel and Luther Blissett
From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/121294
and Recipe 1.12 in cookbook
get_recursive_filelist(args)
Recurs all the files and dirs in args ignoring symbolic links and
return the files as a list of strings
get_split_ind(seq, N)
seq is a list of words.  Return the index into seq such that
len(' '.join(seq[:ind])<=N
is_numlike(obj)
is_scalar(obj)
is_string_like(obj)
is_writable_file_like(obj)
iterable(obj)
listFiles(root, patterns='*', recurse=1, return_folders=0)
Recursively list files
from Parmar and Martelli in the Python Cookbook
mkdirs(newdir, mode=511)
onetrue(seq)
pieces(seq, num=2)
Break up the seq into num tuples
popall(seq)
empty a list
popd(d, *args)
Should behave like python2.3 pop method; d is a dict
 
# returns value for key and deletes item; raises a KeyError if key
# is not in dict
val = popd(d, key)
 
# returns value for key if key exists, else default.  Delete key,
# val item if it exists.  Will not raise a KeyError
val = popd(d, key, default)
print_cycles(objects, outstream=<open file '<stdout>', mode 'w' at 0xb7dbd068>, show_progress=False)
objects:       A list of objects to find cycles in.  It is often useful
               to pass in gc.garbage to find the cycles that are
               preventing some objects from being garbage collected.
outstream:     The stream for output.
show_progress: If True, print the number of objects reached as they are
               found.
report_memory(i=0)
return the memory consumed by process
reverse_dict(d)
reverse the dictionary -- may lose data if values are not uniq!
safezip(*args)
make sure args are equal len before zipping
soundex(name, len=4)
soundex module conforming to Odell-Russell algorithm
strip_math(s)
remove latex formatting from mathtext
to_filehandle(fname, flag='r')
fname can be a filename or a file handle.  Support for gzipped
files is automatic, if the filename ends in .gz.  flag is a
read/write flag for file
unicode_safe(s)
unique(x)
Return a list of unique elements of x
wrap(prefix, text, cols)
wrap text with prefix at length cols

 
Data
        generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 0)
get_realpath_and_stat = <matplotlib.cbook.GetRealpathAndStat instance at 0x844fe6c>
major = 2
minor1 = 5
minor2 = 1
preferredencoding = 'ANSI_X3.4-1968'
s = 'final'
tmp = 0
@footer@