External Documentation

This page contains the External Package documentation.

The decorator Module

Decorator module, see http://pypi.python.org/pypi/decorator for the documentation.

cmpy.external.decorator.decorator(caller, func=None)

decorator(caller) converts a caller function into a decorator; decorator(caller, func) decorates a function using a caller.

class cmpy.external.decorator.FunctionMaker(func=None, name=None, signature=None, defaults=None, doc=None, module=None, funcdict=None)

Bases: object

An object with the ability to create functions with a given signature. It has attributes name, doc, module, signature, defaults, dict and methods update and make.


create(obj, body, evaldict[, defaults, doc, ...]) Create a function from the strings name, signature and body.
make(src_templ[, evaldict, addsource]) Make a new function from a given template and update the signature
update(func, **kw) Update the signature of func with the data in self
classmethod create(obj, body, evaldict, defaults=None, doc=None, module=None, addsource=True, **attrs)

Create a function from the strings name, signature and body. evaldict is the evaluation dictionary. If addsource is true an attribute __source__ is added to the result. The attributes attrs are added, if any.

make(src_templ, evaldict=None, addsource=False, **attrs)

Make a new function from a given template and update the signature

update(func, **kw)

Update the signature of func with the data in self

class cmpy.external.decorator.partial

Bases: object

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.


tuple of arguments to future partial calls


function object to use in future partial calls


dictionary of keyword arguments to future partial calls


A decorator for deprecated functions


Returns an info dictionary containing: - name (the name of the function : str) - argnames (the names of the arguments : list) - defaults (the values of the default arguments : tuple) - signature (the signature : str) - doc (the docstring : str) - module (the module name : str) - dict (the function __dict__ : str)

>>> def f(self, x=1, y=2, *args, **kw): pass
>>> info = getinfo(f)
>>> info["name"]
>>> info["argnames"]
['self', 'x', 'y', 'args', 'kw']
>>> info["defaults"]
(1, 2)
>>> info["signature"]
'self, x, y, *args, **kw'
cmpy.external.decorator.new_wrapper(wrapper, model)

An improvement over functools.update_wrapper. The wrapper is a generic callable object. It works by generating a copy of the wrapper with the right signature and by updating the copy, not the original. Moreovoer, ‘model’ can be a dictionary with keys ‘name’, ‘doc’, ‘module’, ‘dict’, ‘defaults’.

The pkg_resources Module

Code from:
Provide minimal code needed to check versions.
pkg_resources.py was taking too long to import.

Convert a version string to a chronologically-sortable key

This is a rough cross between distutils’ StrictVersion and LooseVersion; if you give it versions that would work with StrictVersion, then it behaves the same; otherwise it acts like a slightly-smarter LooseVersion. It is possible to create pathological version coding schemes that will fool this parser, but they should be very rare in practice.

The returned value will be a tuple of strings. Numeric portions of the version are padded to 8 digits so they will compare numerically, but without relying on how numbers compare relative to strings. Dots are dropped, but dashes are retained. Trailing zeros between alpha segments or dashes are suppressed, so that e.g. “2.4.0” is considered the same as “2.4”. Alphanumeric parts are lower-cased.

The algorithm assumes that strings like “-” and any alpha string that alphabetically follows “final” represents a “patch level”. So, “2.4-1” is assumed to be a branch or patch of “2.4”, and therefore “2.4.1” is considered newer than “2.4-1”, which in turn is newer than “2.4”.

Strings like “a”, “b”, “c”, “alpha”, “beta”, “candidate” and so on (that come before “final” alphabetically) are assumed to be pre-release versions, so that the version “2.4” is considered newer than “2.4a1”.

Finally, to handle miscellaneous cases, the strings “pre”, “preview”, and “rc” are treated as if they were “c”, i.e. as though they were release candidates, and therefore are not as new as a version string that does not contain them, and “dev” is replaced with an ‘@’ so that it sorts lower than than any other pre-release tag.


D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.