utils Package

decorators Module

Some decorator implementations.

thriftworker.utils.decorators.cached_property[source]

Property descriptor that caches the return value of the get function.

Examples

@cached_property
def connection(self):
    return Connection()

@connection.setter  # Prepares stored value
def connection(self, value):
    if value is None:
        raise TypeError('Connection must be a connection')
    return value

@connection.deleter
def connection(self, value):
    # Additional action to do at del(self.attr)
    if value is not None:
        print('Connection %r deleted' % (value, ))

env Module

finalize Module

Execute cleanup handlers when objects go out of scope.

Taken from multiprocessing.util.Finalize.

copyright:
  1. 2009 - 2012 by Ask Solem.
license:

BSD, see LICENSE for more details.

class thriftworker.utils.finalize.Finalize(obj, callback, args=(), kwargs=None, exitpriority=None)[source]

Bases: object

Object finalization using weakrefs.

cancel()[source]

Cancel finalization of the object.

still_active()[source]

imports Module

thriftworker.utils.imports.cwd_in_path(*args, **kwds)[source]
thriftworker.utils.imports.get_real_module(name)[source]

Get the real Python module, regardless of any monkeypatching

thriftworker.utils.imports.import_from_cwd(module, imp=None, package=None)[source]

Import module, but make sure it finds modules located in the current directory.

Modules located in the current directory has precedence over modules located in sys.path.

thriftworker.utils.imports.instantiate(name, *args, **kwargs)[source]

Instantiate class by name.

See symbol_by_name().

thriftworker.utils.imports.qualname(obj)[source]
thriftworker.utils.imports.symbol_by_name(name, aliases={}, imp=None, package=None, sep='.', default=None, **kwargs)[source]

Get symbol by qualified name.

The name should be the full dot-separated path to the class:

modulename.ClassName

Example:

celery.concurrency.processes.TaskPool
                            ^- class name

or using ‘:’ to separate module and symbol:

celery.concurrency.processes:TaskPool

If aliases is provided, a dict containing short name/long name mappings, the name is looked up in the aliases first.

Examples:

>>> symbol_by_name("celery.concurrency.processes.TaskPool")
<class 'celery.concurrency.processes.TaskPool'>
>>> symbol_by_name("default", {
...     "default": "celery.concurrency.processes.TaskPool"})
<class 'celery.concurrency.processes.TaskPool'>

# Does not try to look up non-string names. >>> from celery.concurrency.processes import TaskPool >>> symbol_by_name(TaskPool) is TaskPool True

loop Module

Execute some function in loop and wait for answer.

class thriftworker.utils.loop.Container(func, timeout=None)[source]

Bases: object

Mutable that store result.

dispatch()[source]
exception[source]
from_greenlet(g)[source]
func
result[source]
timeout
thriftworker.utils.loop.DELEGATION_TIMEOUT = 5.0

Specify default timeout for delegation decorators.

thriftworker.utils.loop.in_loop[source]

Schedule execution of given function in main event loop. Wait for function execution.

mixin Module

Some useful mixins here.

class thriftworker.utils.mixin.LoopMixin[source]

Bases: object

Move loop closer to instance.

app = None
loop[source]

Shortcut to loop.

class thriftworker.utils.mixin.PropertyMixin[source]

Bases: object

class thriftworker.utils.mixin.StartStopMixin[source]

Bases: object

Implement some stubs method for object that can be started / stopped.

start()[source]
stop()[source]
class thriftworker.utils.mixin.SubclassMixin[source]

Bases: object

subclass_with_self(Class, name=None, attribute='app', reverse=None, **kw)[source]

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:
  • Class – The app-compatible class to subclass.
  • name – Custom name for the target class.
  • attribute – Name of the attribute holding the app, default is ‘app’.

other Module

Some other useful tools.

thriftworker.utils.other.get_addresses_from_pool(name, address, port_range=None)[source]

Get addresses from pool.

thriftworker.utils.other.get_port_from_range(name, range_start, range_end)[source]

Get random port from given range [range_start, range_end].

thriftworker.utils.other.rgetattr(obj, path)[source]

Get nested attribute from object.

Parameters:
  • obj – object
  • path – path to attribute

proxy Module

Parts of this module is Copyright by Werkzeug Team.

class thriftworker.utils.proxy.PromiseProxy(local, args=None, kwargs=None, name=None)[source]

Bases: <property object at 0x2bb3e10>.Proxy

This is a proxy to an object that has not yet been evaluated.

Proxy will evaluate the object each time, while the promise will only evaluate it once.

thriftworker.utils.proxy.maybe_evaluate(obj)[source]
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.