paradrop.base package


paradrop.base.cxbr module

Wamp utility methods.

class BaseClientFactory(factory, *args, **kwargs)[source]

Bases: autobahn.twisted.websocket.WampWebSocketClientFactory, twisted.internet.protocol.ReconnectingClientFactory

clientConnectionFailed(connector, reason)[source]

Called when a connection has failed to connect.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

clientConnectionLost(connector, reason)[source]

Called when an established connection is lost.

It may be useful to call connector.connect() - this will reconnect.

@type reason: L{twisted.python.failure.Failure}

initialDelay = 1
maxDelay = 60
class BaseSession(config=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSession

Temporary base class for crossbar implementation

call(procedure, *args, **kwargs)[source]



Implements autobahn.wamp.interfaces.ISession.leave()


Implements autobahn.wamp.interfaces.ISession.onJoin()

publish(topic, *args, **kwargs)[source]

Implements autobahn.wamp.interfaces.IPublisher.publish()

register(endpoint, procedure=None, options=None)[source]

Implements autobahn.wamp.interfaces.ICallee.register()

classmethod start(address, pdid, realm='paradrop', start_reactor=False, debug=False, extra=None, reconnect=True)[source]

Creates a new instance of this session and attaches it to the router at the given address and realm.

reconnect: The session will attempt to reconnect on connection failure
and continue trying indefinitely.
stockCall(procedure, *args, **kwargs)[source]
stockPublish(topic, *args, **kwargs)[source]
stockRegister(endpoint, procedure=None, options=None)[source]
stockSubscribe(handler, topic=None, options=None)[source]
subscribe(handler, topic=None, options=None)[source]

Implements autobahn.wamp.interfaces.ISubscriber.subscribe()

class BaseSessionFactory(config, deferred=None)[source]

Bases: autobahn.twisted.wamp.ApplicationSessionFactory

paradrop.base.exceptions module

Exceptions and their subclasses

TODO: Distill these down and make a heirarchy.

exception AuthenticationError[source]

Bases: paradrop.base.exceptions.PdServerException

exception ChuteNotFound[source]

Bases: paradrop.base.exceptions.ParadropException

exception ChuteNotRunning[source]

Bases: paradrop.base.exceptions.ParadropException

exception DeviceNotFoundException[source]

Bases: paradrop.base.exceptions.ParadropException

exception InteralException[source]

Bases: exceptions.Exception

exception InvalidCredentials[source]

Bases: paradrop.base.exceptions.PdServerException

exception ModelNotFound[source]

Bases: paradrop.base.exceptions.PdServerException

exception ParadropException[source]

Bases: exceptions.Exception

exception PdServerException[source]

Bases: exceptions.Exception

exception PdidError[source]

Bases: paradrop.base.exceptions.PdServerException

exception PdidExclusionError[source]

Bases: paradrop.base.exceptions.PdServerException

exception ServiceNotFound(name)[source]

Bases: paradrop.base.exceptions.ParadropException module

Stateful, singleton, paradrop daemon command center. See docstring for NexusBase class for information on settings.


# assuming the following import from paradrop.base import nexus

class AttrWrapper[source]

Bases: object

Simple attr interceptor to make accessing settings simple.

Stores values in an internal dict called contents.

Does not allow modification once _lock() is called. Respect it.

Once you’ve filled it up with the appropriate initial values, set onChange to assign

class NexusBase(stealStdio=True, printToConsole=True)[source]

Bases: object

Resolving these values to their final forms:

1 - module imported, initial values assigned(as written below) 2 - class is instatiated, passed settings to replace values 3 - instance chooses appropriate values based on current state(production or local)

Each category has its own method for initialization here (see: resolveNetwork, resolvePaths)
PDID = None

Takes the given session class and attempts to connect to the crossbar fabric.

If an existing session is connected, it is cleanly closed.


Returns the given key or None

onInfoChange(key, value)[source]

Called when an internal setting is changed. Trigger a save automatically.

provision(pdid, pdserver='', wampRouter='wss://')[source]

Checks if this[whatever] appears to be provisioned or not


Ehh. Ideally this should happen asynchronously.

saveKey(key, name)[source]

Save the key with the given name. Overwrites by default

resolveInfo(nexus, path)[source]

Given a path to the config file, load its contents and assign it to the config file as appropriate.


Error checking on the read YAML file. This is a temporary method.

param contents:
the read - in yaml to check
type contents:
True if valid, else false
writeYaml(contents, path)[source]

Overwrites content with YAML representation at given path

paradrop.base.output module

Output mapping, capture, storange, and display.

Some of the methods and choice here may seem strange – they are meant to keep this file in

class BaseOutput(logType)[source]

Bases: object

Base output type class.

This class and its subclasses are registered with an attribute on the global ‘out’ function and is responsible for formatting the given output stream and returning it as a “log structure” (which is a dict.)

For example:“Text”, anObject)

requires a custom object to figure out what to do with anObject where the default case will simply parse the string with an appropriate color.

Objects are required to output a dict that mininmally contains the keys message and type.


Convert a logdict into a custom formatted, human readable version suitable for printing to console.

class ExceptionOutput(logType)[source]

Bases: paradrop.base.output.BaseOutput

Handle vanilla exceptions passed directly to us using out.exception

class Level

Bases: enum.Enum

ERR = 6
INFO = 3
PERF = 4
WARN = 5
class Output(**kwargs)[source]

Bases: object

Class that allows stdout/stderr trickery. By default the paradrop object will contain an @out variable (defined below) and it will contain 2 members of “err” and “fatal”.

Each attribute of this class should be a function which points to a class that inherits IOutput(). We call these functions “output streams”.

The way this Output class is setup is that you pass it a series of kwargs like (stuff=OutputClass()). Then at any point in your program you can call “paradrop.out.stuff(‘This is a string


This way we can easily support different levels of verbosity without the need to use some kind of bitmask or anything else. On-the-fly output creation is no longer supported due to the metadata and special processing added. It is still possible, but not implemented.

This is done by the __getattr__ function below, basically in __init__ we set any attributes you pass as args, and anything else not defined gets sent to __getattr__ so that it doesn’t error out.


Ask the printing thread to flush and end, then return.

getLogsSince(target, purge=False)[source]

Reads all logs and returns their contents. The current log file is not touched. Removes old log files if ‘purge’ is set (though this is a topic for debate…)

The server will be most interested in this call, but it needs to register for new logs first, else there’s a good chance to see duplicates.

NOTE: don’t open all log files, check to open only the ones that might be relevant. This is certainly a bug and can cause memory issues.

  • target (float.) – seconds since the GMT epoch. Method returns logs that have timestamps later than this.
  • purge (bool.) – deletes the old log files (except today’s) if set

a list of dictionaries containing log information. Not ordered.


All printing objects return their messages. These messages are routed to this method for handling.

Send the messages to the printer. Optionally display the messages. Decorate the print messages with metadata.

Parameters:logDict – a dictionary representing this log item. Must contain keys

message and type. :type logDict: dict.


Converts message dicts to a format suitable for printing based on the conversion rules laid out in in that class’s implementation.

Parameters:message (dict.) – the dict to convert to string
startLogging(filePath=None, stealStdio=False, printToConsole=True)[source]

Begin logging. The output class is ready to go out of the box, but in order to prevent mere imports from stealing stdio or console logging to vanish these must be manually turned on.

  • filePath (str) – if provided, begin logging to the given directory. If not provided, do not write out logs.
  • stealStdio (bool.) – choose to intercept stdio (including vanilla print statements) or allow it to passthrough
  • printToConsole (bool.) – output the results of all logging to the console. This is primarily a performance consideration when running in production
class OutputRedirect(output, contentAppearedCallback, logType)[source]

Bases: object

Intercepts passed output object (either stdout and stderr), calling the provided callback method when input appears.

Retains the original mappings so writing can still happen. Performs no formatting.


Someone really does want to output


Intercept output to the assigned target and callback with it. The true output is returned with the callback so the delegate can differentiate between captured outputs in the case when two redirecters are active.

class PrintLogThread(path, queue, name)[source]

Bases: threading.Thread

All file printing access from one thread.

Receives information when its placed on the passed queue. Called from one location: Output.handlePrint.

Does not close the file: this happens in Output.endLogging. This simplifies the operation of this class, since it only has to concern itself with the queue.

The path must exist before DailyLog runs for the first time.


Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class TwistedException(logType)[source]

Bases: paradrop.base.output.BaseOutput

class TwistedOutput(logType)[source]

Bases: paradrop.base.output.BaseOutput

blacklist = ['Starting factory', 'Stopping factory', 'Log opened']

Takes a traceback returned by ‘extract_tb’ and returns the package, module, and line number


logPrefix v2– gets caller information silently (without caller intervention) The single parameter reflects how far up the stack to go to find the caller and depends how deep the direct caller to this method is wrt to the target caller

NOTE: Some calls cannot be silently prefixed (getting into the twisted code is a great example)

Parameters:stepsUp – the number of steps to move up the stack for the caller

paradrop.base.pdutils module

lib.utils.output. Helper for formatting output from Paradrop.

class Timer(key='', verbose=True)[source]

Bases: object

A timer object for simple benchmarking.

with Timer(key=’Name of this test’) as t:

Once the code finishes executing the time is output.

check(pkt, pktType, keyMatches=None, **valMatches)[source]

This function takes an object that was expected to come from a packet (after it has been JSONized) and compares it against the arg requirements so you don’t have to have 10 if() statements to look for keys in a dict, etc..


@pkt : object to look at @pktType : object type expected (dict, list, etc..) @keyMatches : a list of minimum keys found in parent level of dict, expected to be an array @valMatches : a dict of key:value pairs expected to be found in the parent level of dict

the value can be data (like 5) OR a type (like this value must be a @list@).
None if everything matches, otherwise it returns a string as to why it failed.

Converts all unicode strings back into UTF-8 (str) so everything works. Call this function like:

json.loads(s, object_hook=convertUnicode)
class dict2obj(aDict=None, **kwargs)[source]

Bases: object

explode(pkt, *args)[source]

This function takes a dict object and explodes it into the tuple requested.

It returns None for any value it doesn’t find.

The only error it throws is if args is not defined.

pkt = {‘a’:0, ‘b’:1} 0, 1, None = pdcomm.explode(pkt, ‘a’, ‘b’, ‘c’)

Returns a string of a JSON object in ‘pretty print’ format fully indented, and sorted.


Print consistent string format of seconds passed. Example: 300 = ‘5 mins’ Example: 86400 = ‘1 day’ Example: 86705 = ‘1 day, 5 mins, 5 sec’


Converts any values that would cause JSON parsing to fail into URL percent encoding equivalents. This function can be used for any valid JSON type including str, dict, list. Returns:

Same element properly decoded.
urlEncodeMe(elem, safe=' ')[source]

Converts any values that would cause JSON parsing to fail into URL percent encoding equivalents. This function can be used for any valid JSON type including str, dict, list. Returns:

Same element properly encoded.

paradrop.base.settings module

This file contains any settings required by ANY and ALL modules of the paradrop system. They are defaulted to some particular value and can be called by any module in the paradrop system with the following code:

from paradrop import settings print(settings.STUFF)

These settings can be overriden by a KYE:VALUE array

If settings need to be changed, they should be done so by the initialization code (such as pdfcd, pdfc_config, etc…)

This is done by calling the following function:

Iterate over the attributes in a module.

This is a generator function.

Returns (name, value) tuples.

loadSettings(mode='local', slist=[])[source]

Take a list of key:value pairs, and replace any setting defined. Also search through the settings module and see if any matching environment variables exist to replace as well.

Parameters:slist (array.) – the list of key:val settings

Load settings from an INI file.

This will check the configuration file for a lowercase version of all of the settings in this module. It will look in a section called “base”.

The example below will set PORTAL_SERVER_PORT.

[base] portal_server_port = 4444

Attempts to parse the key value, so if the string is ‘False’ it will parse a boolean false.

Parameters:key (string) – the key to parse
Returns:the parsed key.
updatePaths(configHomeDir, runtimeHomeDir='/var/run/paradrop')[source]

Module contents