pyhaystack.util package

Submodules

pyhaystack.util.asyncexc module

Asynchronous Exception Handler. This implements a small lightweight object for capturing an exception in a manner that can be passed in callback arguments then re-raised elsewhere for handling in the callback function.

Typical usage:

def _some_async_function(…, callback_fn):
    try:
        do some async op that may fail
        result = ...
    except: # Capture all exceptions
        result = AsynchronousException()
    callback_fn(result)
class pyhaystack.util.asyncexc.AsynchronousException

Bases: object

reraise()

pyhaystack.util.filterbuilder module

Filter abstract syntax tree builder. These classes and functions attempt to build a filter string for use with ‘read’ operations by combining Python’s operators to trick it into producing the desired values.

Yes, we’re hijacking operators to do what they weren’t expected to do.

Typical usage:

from pyhaystack.util import filterbuilder as fb

# Get all historical points:
session.find_points(fb.Field('his'))

# All historical points in Brisbane timezone.
session.find_points(fb.Field('his') &                 ( fb.Field('tz') == fb.Scalar('Brisbane') ))
class pyhaystack.util.filterbuilder.And(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = 'and'
class pyhaystack.util.filterbuilder.Base

Bases: object

class pyhaystack.util.filterbuilder.Binary(x, y)

Bases: pyhaystack.util.filterbuilder.Base

class pyhaystack.util.filterbuilder.Equal(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '=='
class pyhaystack.util.filterbuilder.Field(value)

Bases: pyhaystack.util.filterbuilder.Base

class pyhaystack.util.filterbuilder.GreaterThan(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '>'
class pyhaystack.util.filterbuilder.GreaterThanOrEqual(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '>='
class pyhaystack.util.filterbuilder.LessThan(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '<'
class pyhaystack.util.filterbuilder.LessThanOrEqual(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '<='
class pyhaystack.util.filterbuilder.Not(value)

Bases: pyhaystack.util.filterbuilder.Unary

OP = 'not'
class pyhaystack.util.filterbuilder.NotEqual(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = '!='
class pyhaystack.util.filterbuilder.Or(x, y)

Bases: pyhaystack.util.filterbuilder.Binary

OP = 'or'
class pyhaystack.util.filterbuilder.Scalar(value)

Bases: pyhaystack.util.filterbuilder.Base

class pyhaystack.util.filterbuilder.Unary(value)

Bases: pyhaystack.util.filterbuilder.Base

pyhaystack.util.state module

State machine interface. This is a base class for implementing state machines.

class pyhaystack.util.state.HaystackOperation(result_copy=True, result_deepcopy=True)

Bases: object

A core state machine object. This implements the basic interface presented for all operations in pyhaystack.

Initialisation. This should be overridden by subclasses to accept and validate the inputs presented for the operation, raising an appropriate Exception subclass if the inputs are found to be invalid.

These should be stored here by the initialisation function as private variables in suitably sanitised form. The core state machine object shall then be created and stored before the object is returned to the caller.

go()

Start processing the operation. This is called by the caller (so after all __init__ functions have executed) in order to begin the asynchronous operation.

is_done

Return true if the operation is complete.

is_failed

Return true if the result is an Exception.

result

Return the result of the operation or raise its exception. Raises NotReadyError if not ready.

state

Return the current state machine’s state.

wait(timeout=None)

Wait for an operation to finish. This should NOT be called in the same thread as the thread executing the operation as this will deadlock.

exception pyhaystack.util.state.NotReadyError

Bases: exceptions.Exception

Exception raised when an attempt is made to retrieve the result of an operation before it is ready.

pyhaystack.util.tools module

pyhaystack.util.tools.isBool(value)

Helper function to detect if a value is boolean

pyhaystack.util.tools.isfloat(value)

Helper function to detect if a value is a float

pyhaystack.util.tools.prettyprint(jsonData)

Pretty print json object

Module contents