Pluggdapps

Component system. Web framework. And more ...

lib – Common library functions.

Commonly used utility functions.

Module contents

class pluggdapps.utils.lib.Context(*args, **kwargs)[source]

Dictionary like context object passed to resource callables and view callables. Use of context objects has more implications than just passing around data values. Resource callables, typically identified by the request-URLs, are responsible for fetching the necessary data for before representing it to clients. And view callables are responsible to represent the data in desired format to clients.

pluggdapps.utils.lib.sourcepath(obj)[source]

Source path for module defining obj.

pluggdapps.utils.lib.parsecsv(line)[source]

Parse a single line of comma separated values, into a list of strings

pluggdapps.utils.lib.parsecsvlines(lines)[source]

Parse a multi-line text where each line contains comma separated values.

pluggdapps.utils.lib.classof(obj)[source]

If obj is class object return the same. Other wise assume that it is an instance object and return its class.

pluggdapps.utils.lib.subclassof(cls, supers)[source]

Check whether cls is a subclass of one of the super-classes passed in supers. Gotcha : if supers has a built-in type this function will fail.

pluggdapps.utils.lib.asbool(val, default=None)[source]

Convert a string representation of boolean value to boolean type.

pluggdapps.utils.lib.asint(val, default=None)[source]

Convert string representation of integer value to integer type.

pluggdapps.utils.lib.asfloat(val, default=None)[source]

Convert string representation of float value to floating type.

pluggdapps.utils.lib.timedelta_to_seconds(td)[source]

Equivalent to td.total_seconds() (introduced in python 2.7).

pluggdapps.utils.lib.set_close_exec(*fds)[source]

Use stdlib’s fcnt.fcnt() function to set FILE-DESCRIPTORS fds to be automatically closed when this program exits.

pluggdapps.utils.lib.set_nonblocking(*fds)[source]

Use stdlib’s fcnt.fcnt() function to set FILE-DESCRIPTORS fds to non-blocking read / write.

pluggdapps.utils.lib.call_entrypoint(distribution, group, name, *args, **kwargs)[source]

If an entrypoint is callable, use this API to both identify the entry point, evaluate them by loading and calling it. Return the result from the called function. Note that the entrypoint must be uniquely identified using, distribution, group and name. args and kwargs will be passed on to the entypoint callable.

pluggdapps.utils.lib.docstr(obj)[source]

Return the doc-string for the object.

pluggdapps.utils.lib.cpu_count()[source]

Returns the number of processors on this machine.

pluggdapps.utils.lib.reseed_random()[source]

If os.urandom is available, this method does the same thing as random.seed ! (at least as of python 2.6). If os.urandom is not available, we mix in the pid in addition to a timestamp.

pluggdapps.utils.lib.mergedict(*args)[source]

For a list of dictionaries in args return a new dictionary containing super-imposed key,value pairs from args

pluggdapps.utils.lib.multivalue_dict(ls)[source]

List ls is a list of tuple (attr, value), there can be more than one tuple with the same attr name. Make a dictionary where the key values are list.

pluggdapps.utils.lib.takewhile(pred, lst)[source]

Iterate over lst until pred is True and return only the iterated elements.

pluggdapps.utils.lib.dropwhile(pred, lst)[source]

Iterate over lst until pred is True and return the remaining elements in lst.

pluggdapps.utils.lib.print_exc()[source]

Return a string representing exception info.

pluggdapps.utils.lib.eval_import(s)[source]

Import a module, or import an object from a module.

A module name like foo.bar:baz() can be used, where foo.bar is the module, and baz() is an expression evaluated in the context of that module. Note this is not safe on arbitrary strings because of the eval.

pluggdapps.utils.lib.string_import(s)[source]

Import a module, object, or an attribute on an object.

A string like foo.bar.baz can be a module foo.bar.baz or a module foo.bar with an object baz in it, or a module foo with an object bar with an attribute baz.

pluggdapps.utils.lib.str2module(s)[source]

Import a module from string specification s.