ll.misc

Miscellaneous utility functions and classes

Home › Python software › ll.miscText · XIST · Python

ll.misc contains various utility functions and classes used by the other LivingLogic modules and packages.

def notimplemented​(function):

A decorator that raises NotImplementedError when the method is called. This saves you the trouble of formatting the error message yourself for each implementation.

def withdoc​(doc):

A decorator that adds a docstring to the function it decorates. This can be useful if the docstring is not static, and adding it afterwards is not possible.

class _propclass_Meta​(type):

class propclass​(property):

propclass provides an alternate way to define properties.

Subclassing propclass and defining methods __get__, __set__ and __delete__ will automatically generate the appropriate property:

class name(misc.propclass):
        """
        The name property
        """
        def __get__(self):
                return self._name
        def __set__(self, name):
                self._name = name.lower()
        def __delete__(self):
                self._name = None

class __metaclass__​(type):

class Pool​(object):

A Pool object can be used as an inheritable alternative to modules. The attributes of a module can be put into a pool and each pool can have base pools where lookup continues if an attribute can't be found.

def __init__​(self, *objects):

def register​(self, object):

Register object in the pool. object can be a module, a dictionary or a Pool objects (with registers the pool as a base pool. If object is a module and has an attribute __bases__ (being a sequence of other modules) this attribute will be used to initialize self base pool.

def __getitem__​(self, key):

def __getattr__​(self, key):

def clear​(self):

Make self empty.

def clone​(self):

Return a copy of self.

def __repr__​(self):

def iterone​(item):

Return an iterator that will produce one item: item.

class Iterator​(object):

Iterator adds __getitem__ support to an iterator. This is done by calling item internally.

def __init__​(self, iterator):

def __getitem__​(self, index):

def __iter__​(self):

def next​(self):

def __nonzero__​(self):

def get​(self, index, default=None):

Return the index h item from the iterator (or default if there's no such item).

class Queue​(object):

Queue provides FIFO queues: The method write writes to the queue and the method read read from the other end of the queue and remove the characters read.

def __init__​(self):

def write​(self, chars):

Write the string chars to the buffer.

def read​(self, size=-1):

Read up to size character from the buffer (or all if size is negative). Those characters will be removed from the buffer.

class Const​(object):

This class can be used for singleton constants.

def __init__​(self, name):

def __repr__​(self):

def tokenizepi​(string):

Tokenize the string object string according to the processing instructions in the string. tokenize will generate tuples with the first item being the processing instruction target and the second being the PI data. "Text" content (i.e. anything other than PIs) will be returned as (None, data).

def gzip​(data, compresslevel=9):

Compresses the byte string data with gzip using the compression level compresslevel.

def gunzip​(data):

Uncompresses the byte string data with gzip.

def itersplitat​(string, positions):

Split string at the positions specified in positions.

For example:

>>> from ll import misc
>>> import datetime
>>> datetime.datetime(*map(int, misc.itersplitat("20090609172345", (4, 6, 8, 10, 12))))
datetime.datetime(2009, 6, 9, 17, 23, 45)

This is a generator.

class JSMinUnterminatedComment​(exceptions.Exception):

class JSMinUnterminatedStringLiteral​(exceptions.Exception):

class JSMinUnterminatedRegularExpression​(exceptions.Exception):

def jsmin​(input):

Minimizes the Javascript source input.