Package grassyknoll :: Package concurrent :: Module Wrappers
[hide private]

Module Wrappers

source code

Classes [hide private]
  FunctionCall
a representation of a function call
  MethodCall
a represention of a method to be called on object.
  NullContextManager
a null context manager that simply returns what it was constructed with.
  FactoryContextManager
a context manager for working with factories.
Functions [hide private]
 
functionMessenger(send_none=False)
wrap a func so that it can handle Messages.
source code
 
methodMessenger(send_none=False)
wrap a method so that it can handle Messages.
source code
 
objectMessenger(obj, send_none=False)
wrap an obj so that it can handle Messages by dispatching to methods.
source code
 
errorMessenger(*exception_types)
wrap a func so that it returns Messages on errors
source code
 
debugMessenger(func)
wrap a func with debugging.
source code
Variables [hide private]
  __debug_logger = logging.getLogger()
Function Details [hide private]

functionMessenger(send_none=False)

source code 

wrap a func so that it can handle Messages.

The resulting messenger function takes messages with FuncCall as a payload. messenger calls the decorated func and stuffs the return value in a reply message. If the original message does not specify a Message.reply_box, the return value will be discarded.
Parameters:
  • send_none (boolean) - if true and func returns None, use None as the reply's Message.payload. Otherwise, do not return a message.

methodMessenger(send_none=False)

source code 

wrap a method so that it can handle Messages.

The resulting messenger function takes messages with FuncCall as a payload. messenger calls the decorated method and stuffs the return value in a reply message. If the original message does not specify a Message.reply_box, the return value will be discarded.
Parameters:
  • send_none (boolean) - if true and method returns None, use None as the reply's Message.payload. Otherwise, do not return a message.

Warning: This wrapper does not provide thread safety; you should use it only on read-only objects.

objectMessenger(obj, send_none=False)

source code 

wrap an obj so that it can handle Messages by dispatching to methods.

The resulting messenger function takes messages with MethodCall as a payload. messenger calls the appropriate obj.method and stuffs the return value in a reply message. If the original message does not specify a Message.reply_box, the return value will be discarded.
Parameters:
  • obj (instance) - the instance to be wrapped
  • send_none (boolean) - if true and func returns None, use None as the reply's Message.payload. Otherwise, do not return a message.

errorMessenger(*exception_types)

source code 

wrap a func so that it returns Messages on errors

The resulting messenger function takes messages and calls the decorated func. If func raises an exception in exception_types, the exception is packed in a Fault.Fault in a reply message.

If the original message does not specify a Message.reply_box, the exception value will be discarded. Exceptions not in exception_types will be raise normally.
Parameters:
  • exception_types (classes) - types of exceptions to catch. These are meant as intentionally raised exceptions, as opposed to unhandled (programmer) errors.
  • include_tb (boolean) - include a textified traceback in the message, see current_tb_message

debugMessenger(func)

source code 

wrap a func with debugging.

The resulting messenger function will log the messages and replies of the decorated func.