Warning
External usage of internal utility functions and modules should be kept to a minimum as they may be altered, refactored or moved to other locations without notice (and without the typical deprecation cycle).
Warns about some type of deprecation that has been (or will be) made.
This helper function makes it easier to interact with the warnings module by standardizing the arguments that the warning function recieves so that it is easier to use.
This should be used to emit warnings to users (users can easily turn these warnings off/on, see https://docs.python.org/2/library/warnings.html as they see fit so that the messages do not fill up the users logs with warnings that they do not wish to see in production) about functions, methods, attributes or other code that is deprecated and will be removed in a future release (this is done using these warnings to avoid breaking existing users of those functions, methods, code; which a library should avoid doing by always giving at least N + 1 release for users to address the deprecation warnings).
Bases: object
Acts as a proxy to a class that was moved to another location.
Partially based on:
http://code.activestate.com/recipes/496741-object-proxying/ and other various examination of how to make a good enough proxy for our usage to move the various types we want to move during the deprecation process.
And partially based on the wrapt object proxy (which we should just use when it becomes available @ http://review.openstack.org/#/c/94754/).
Deprecates a class that was moved to another location.
This will emit warnings when the old locations class is initialized, telling where the new and improved location for the old class now is.
Iterates over a provided iterator up to the desired length.
If the source iterator does not have enough values then the filler value is yielded until the desired length is reached.
Returns how many values in the iterator (depletes the iterator).
Generator/iterator that provides back delays values.
The values it generates increments by a given multiple after each iteration (using the max delay as a upper bound). Negative values will never be generated... and it will iterate forever (ie it will never stop generating values).
Yields unique values from iterator(s) (and retains order).
Searches iterator for first value that matcher callback returns true.
Prettifies a checked commits failures (ignores sensitive data...).
Bases: kazoo.exceptions.KazooException
Exception raised when a checked commit fails.
Commits a kazoo transcation and validates the result.
NOTE(harlowja): Until https://github.com/python-zk/kazoo/pull/224 is fixed or a similar pull request is merged we have to workaround the transaction failing silently.
Stops and closes a client, even if it wasn’t started.
Checks if a kazoo client is backed by a zookeeper server version.
This check will verify that the zookeeper server version that the client is connected to satisfies a given minimum version (inclusive) and maximum (inclusive) version range. If the server is not in the provided version range then a exception is raised indiciating this.
Creates a kazoo client given a configuration dictionary.
Parameters: | conf (dict) – configuration dictionary that will be used to configure the created client |
---|
The keys that will be extracted are:
Bases: object
Wraps a message and delays prettifying it until requested.
TODO(harlowja): remove this when https://github.com/celery/kombu/pull/454/ is merged and a release is made that contains it (since that pull request is equivalent and/or better than this).
Bases: str, enum.Enum
An enumeration that is also a string and can be compared to strings.
Bases: StringIO.StringIO
String buffer with some small additions.
Gets the machines hostname; if not able to returns an invalid one.
Matches a given object using the given matchers list/iterable.
NOTE(harlowja): each element of the provided list/iterable must be tuple of (valid types, result).
Returns the result (the second element of the provided tuple) if a type match occurs, otherwise none if no matches are found.
Generator that decrements after each generation until <= zero.
NOTE(harlowja): we can likely remove this when we can use an itertools.count that takes a step (on py2.6 which we still support that step parameter does not exist and therefore can’t be used).
Common function to get a driver name and its configuration.
Like reversed(enumerate(items)) but with less copying/cloning...
Merges a parsed uri into the given configuration dictionary.
Merges the username, password, hostname, port, and query parameters of a URI into the given configuration dictionary (it does not overwrite existing configuration keys if they already exist) and returns the merged configuration.
NOTE(harlowja): does not merge the path, scheme or fragment.
Finds subclass types in the given locations.
This will examines the given locations for types which are subclasses of the base class type provided and returns the found subclasses (or fails with exceptions if this introspection can not be accomplished).
If a string is provided as one of the locations it will be imported and examined if it is a subclass of the base class. If a module is given, all of its members will be examined for attributes which are subclasses of the base class. If a type itself is given it will be examined for being a subclass of the base class.
Returns first of values that is not None (or None if all are/were).
Frozen checking/raising method decorator.
Clamps a value to ensure its >= minimum and <= maximum.
Fixes text that may end with wrong nl by replacing with right nl.
Encodes a text string into a binary string using given encoding.
Does nothing if data is already a binary string (raises on unknown types).
Decodes a binary string into a text string using given encoding.
Does nothing if data is already a text string (raises on unknown types).
Parse raw data to get decoded object.
Decodes a msgback encoded ‘blob’ from a given raw data binary string and checks that the root type of that decoded object is in the allowed set of types (by default a dict should be the root type).
Parse raw data to get decoded object.
Decodes a JSON encoded ‘blob’ from a given raw data binary string and checks that the root type of that decoded object is in the allowed set of types (by default a dict should be the root type).
Bases: object
A thread-safe descriptor property that is only evaluated once.
This caching descriptor can be placed on instance methods to translate those methods into properties that will be cached in the instance (avoiding repeated attribute checking logic to do the equivalent).
NOTE(harlowja): by default the property that will be saved will be under the decorated methods name prefixed with an underscore. For example if we were to attach this descriptor to an instance method ‘get_thing(self)’ the cached property would be stored under ‘_get_thing’ in the self object after the first call to ‘get_thing’ occurs.
Converts number of milliseconds (from epoch) into a datetime object.
Gets a object’s version as a string.
Returns string representation of object’s version taken from its ‘version’ attribute, or None if object does not have such attribute or its version is None.
Calculate difference of two sequences.
Result contains the elements from first sequence that are not present in second sequence, in original order. Works even if sequence elements are not hashable.
Create a directory (and any ancestor directories required).
Parameters: | path – Directory to create |
---|
Captures the occurring exception and provides a failure object back.
This will save the current exception information and yield back a failure object for the caller to use (it will raise a runtime error if no active exception is being handled).
This is useful since in some cases the exception context can be cleared, resulting in None being attempted to be saved after an exception handler is run. This can happen when eventlet switches greenthreads or when running an exception handler, code raises and catches an exception. In both cases the exception context will be cleared.
To work around this, we save the exception state, yield a failure and then run other code.
For example:
>>> from taskflow.utils import misc
>>>
>>> def cleanup():
... pass
...
>>>
>>> def save_failure(f):
... print("Saving %s" % f)
...
>>>
>>> try:
... raise IOError("Broken")
... except Exception:
... with misc.capture_failure() as fail:
... print("Activating cleanup")
... cleanup()
... save_failure(fail)
...
Activating cleanup
Saving Failure: IOError: Broken
Tests an object to to determine whether it is iterable.
This function will test the specified object to determine whether it is iterable. String types (both str and unicode) are ignored and will return False.
Parameters: | obj – object to be tested for iterable |
---|---|
Returns: | True if object is iterable and is not a string |
Bases: object
Mixin that helps deal with the PY2 and PY3 method differences.
http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/ explains why this is quite useful...
Creates a temporary logbook for temporary usage in the given backend.
Mainly useful for tests and other use cases where a temporary logbook is needed for a short-period of time.
Creates a temporary flow detail and logbook in the given backend.
Mainly useful for tests and other use cases where a temporary flow detail and a temporary logbook is needed for a short-period of time.
Creates a flow detail for a flow & adds & saves it in a logbook.
This will create a flow detail for the given flow using the flow name, and add it to the provided logbook and then uses the given backend to save the logbook and then returns the created flow detail.
If no book is provided a temporary one will be created automatically (no reference to the logbook will be returned, so this should nearly always be provided or only used in situations where no logbook is needed, for example in tests). If no backend is provided then no saving will occur and the created flow detail will not be persisted even if the flow detail was added to a given (or temporarily generated) logbook.
Bases: redis.client.StrictRedis
A redis client that can be closed (and raises on-usage after closed).
TODO(harlowja): if https://github.com/andymccurdy/redis-py/issues/613 ever gets resolved or merged or other then we can likely remove this.
Execute a command and return a parsed response
Convenience method for executing the callable func as a transaction while watching all keys specified in watches. The ‘func’ callable should expect a single argument which is a Pipeline object.
Return a Publish/Subscribe object. With this object, you can subscribe to channels and listen for messages that get published to them.
Bases: enum.IntEnum
Non-expiry (not ttls) results return from get_expiry().
See: http://redis.io/commands/ttl or http://redis.io/commands/pttl
The command returns -1 if the key exists but has no associated expire.
The command returns -2 if the key does not exist.
Gets an expiry for a key (using best determined ttl method).
Helper to determine if a thread is alive (handles none safely).
Return the ‘thread identifier’ of the current thread.
Try to guess optimal thread count for current system.
Makes a daemon thread that calls the given target when started.