Some useful class for request logging.
This module implements context-local objects.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
Bases: object
Acts as a proxy for a werkzeug local. Forwards all operations to a proxied object. The only operations not supported for forwarding are right handed operands and any kind of assignment.
Example usage:
from thriftpool.utils.local import Local
l = Local()
# these are proxies
request = l('request')
user = l('user')
from thriftpool.utils.local import LocalStack
_response_local = LocalStack()
# this is a proxy
response = _response_local()
Whenever something is bound to l.user / l.request the proxy objects will forward all operations. If no object is bound a RuntimeError will be raised.
To create proxies to Local or LocalStack objects, call the object as shown above. If you want to have a proxy to an object looked up by a function, you can (as of Werkzeug 0.6.1) pass a function to the LocalProxy constructor:
session = LocalProxy(lambda: get_current_request().session)
Bases: object
This class works similar to a Local but keeps a stack of objects instead. This is best explained with an example:
>>> ls = LocalStack()
>>> ls.push(42)
>>> ls.top
42
>>> ls.push(23)
>>> ls.top
23
>>> ls.pop()
23
>>> ls.top
42
They can be force released by using a LocalManager or with the release_local() function but the correct way is to pop the item from the stack after using. When the stack is empty it will no longer be bound to the current context (and as such released).
By calling the stack without arguments it returns a proxy that resolves to the topmost item on the stack.
Releases the contents of the local for the current context. This makes it possible to use locals without a manager.
Example:
>>> loc = Local()
>>> loc.foo = 42
>>> release_local(loc)
>>> hasattr(loc, 'foo')
False
With this function one can release Local objects as well as StackLocal objects. However it is not possible to release data held by proxies that way, one always has to retain a reference to the underlying local object in order to be able to release it.
Some useful tools for logging.
This file was copied and adapted from celery.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
Bases: logging.Formatter
Loglevel -> Color mapping.
Bases: object
Forward file object to logging.Logger instance.
Parameters: |
|
---|
When the object is closed, no write requests are forwarded to the logging object anymore.
Bases: object
Subclass an app-compatible class by setting its app attribute to be this app instance.
App-compatible means that the class has a class attribute that provides the default app it should use, e.g. class Foo: app = None.
Parameters: |
|
---|
Bases: object
Fork and close needed resources.
Bases: object
Create PID lock and work with it as with resource.
Some base structures.
This file was copied and adapted from celery.
copyright: |
|
---|---|
license: | BSD, see LICENSE for more details. |
Bases: object
A directed acyclic graph of objects and their dependencies.
Supports a robust topological sort to detect the order in which they must be handled.
Takes an optional iterator of (obj, dependencies) tuples to build the graph from.
Warning
Does not support cycle detection.
Convert the graph to DOT format.
Parameters: | fh – A file, or a file-like object to write the graph to. |
---|
Bases: dict, thriftpool.utils.structures.AttributeDictMixin
Dict subclass with attribute access.
Terminals and colors.
Bases: object
Terminal colored text.
>>> c = colored(enabled=True)
>>> print(str(c.red('the quick '), c.blue('brown ', c.bold('fox ')),
... c.magenta(c.underline('jumps over')),
... c.yellow(' the lazy '),
... c.green('dog ')))