TASSELpy.utils package

Submodules

TASSELpy.utils.DocInherit module

doc_inherit decorator

Usage:

class Foo(object):
def foo(self):
“Frobber” pass
class Bar(Foo):

@doc_inherit def foo(self):

pass

Now, Bar.foo.__doc__ == Bar().foo.__doc__ == Foo.foo.__doc__ == “Frobber”

class TASSELpy.utils.DocInherit.DocInherit(mthd)[source]

Bases: object

Docstring inheriting method descriptor

The class itself is also used as a decorator

Methods

get_no_inst(cls)
get_with_inst(obj, cls)
use_parent_doc(func, source)
__init__(mthd)[source]
get_no_inst(cls)[source]
get_with_inst(obj, cls)[source]
use_parent_doc(func, source)[source]
TASSELpy.utils.DocInherit.doc_inherit

alias of DocInherit

TASSELpy.utils.OrderedSet module

class TASSELpy.utils.OrderedSet.OrderedSet(iterable=None)[source]

Bases: _abcoll.MutableSet

Set that remembers original insertion order

Based on the following code: http://code.activestate.com/recipes/576694/

Methods

add(key)
clear() This is slow (creates N new iterators!) but effective.
discard(key)
isdisjoint(other) Return True if two sets have a null intersection.
pop([last])
remove(value) Remove an element.
__init__(iterable=None)[source]
add(key)[source]
discard(key)[source]
pop(last=True)[source]
class TASSELpy.utils.OrderedSet.lruOrderedSet(maxSize=1000, iterable=None)[source]

Bases: TASSELpy.utils.OrderedSet.OrderedSet

Methods

add(key)
clear() This is slow (creates N new iterators!) but effective.
discard(key)
isdisjoint(other) Return True if two sets have a null intersection.
pop([last])
remove(value) Remove an element.
__init__(maxSize=1000, iterable=None)[source]
add(key)[source]

TASSELpy.utils.Overloading module

class TASSELpy.utils.Overloading.bidirectional_dict(*args)[source]

Bases: dict

Methods

clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
setdefault((k[,d]) -> D.get(k,d), ...)
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)
__init__(*args)[source]
class TASSELpy.utils.Overloading.javaConstructorOverload(class_name, *args)[source]

Bases: object

Creates a function decorator for a javabridge function that is a constructor for an instantiated class

Arguments:

class_name – The name of the java class, as in path/to/class args – tuples of form (java signature,(python arg types))

e.g. (“(I)V”,(int,))

Methods

__call__(f)
__init__(class_name, *args)[source]

Creates a function decorator for a javabridge function that is a constructor for an instantiated class

Arguments:

class_name – The name of the java class, as in path/to/class args – tuples of form (java signature,(python arg types))

e.g. (“(I)V”,(int,))
class TASSELpy.utils.Overloading.javaGenericOverload(func_name, *args)[source]

Bases: object

Creates a function decorator for a javabridge function that is the member of a class and returns and/or accepts a generic type

Arguments:

func_name – The name of the java function args – tuples of form (java_signature, (python arg types),post_process_func)

Java signatures should have java/lang/Object where generic types go.

In the Python arg types, a generic types specified as, say (type1,type2) in the generic argument of the constructor should be specified as a string “/@1/” or “/@2/”, corresponding to type1 and type2 respectively.

In the post_process_func, you can specify None or a function as usual in order to deal with pre-specified types. Alternatively, you can put in the string “/@1/” or whatever the corresponding string is for a given type in order to send the return object through the constructor of that type (e.g. type1(obj=x)). In the case of types that should receive generic arguments, you can specify a dictionary with ‘type’ and ‘generic’ keys. For instance, to send the return object to a wrapper class named MyClass that should receive type1 as its one and only generic type argument, you can put in the following dictionary:

dict(type=MyClass, generic=(“/@1/”,))

Methods

__call__(f)
__init__(func_name, *args)[source]

Creates a function decorator for a javabridge function that is the member of a class

Arguments:

func_name – The name of the java function args – tuples of form (java_signature, (python arg types or None),post_process_func)

For java signature, put /@/ sign where the actual type of the generic should be placed. For python args/return type put None where it should be Note that if the returned type is the generic, the post-process function will cast to the specified type unless otherwise specified e.g. (“(/@/)I”,(None,),None) or (“(/@/)[L”,(None,),lambda x: javabridge.get_env().get_long_array_elements(x))
class TASSELpy.utils.Overloading.javaOverload(func_name, *args)[source]

Bases: object

Creates a function decorator for a javabridge function that is the member of a class

Arguments:

func_name – The name of the java function args – tuples of form (java_signature, (python arg types),post_process_func)

e.g. (“(I)I”,(int,),None) or (“(I)[L”,(int,),lambda x: javabridge.get_env().get_long_array_elements(x))

Methods

__call__(f)
__init__(func_name, *args)[source]

Creates a function decorator for a javabridge function that is the member of a class

Arguments:

func_name – The name of the java function args – tuples of form (java_signature, (python arg types),post_process_func)

e.g. (“(I)I”,(int,),None) or (“(I)[L”,(int,),lambda x: javabridge.get_env().get_long_array_elements(x))
class TASSELpy.utils.Overloading.javaStaticOverload(class_name, func_name, *args)[source]

Bases: object

Creates a function decorator for a javabridge static function

Arguments:

class_name – The name of the java class containing the method, as in path/to/class func_name – The name of the java function args – tuples of form (java signature, (python arg types), post process function)

e.g. (“(I)I”,(int,),None) or (“(I)[L”,(int,),lambda x: javabridge.get_env().get_long_array_elements(x))

Methods

__call__(f)
__init__(class_name, func_name, *args)[source]

Creates a function decorator for a javabridge static function

Arguments:

class_name – The name of the java class containing the method, as in path/to/class func_name – The name of the java function args – tuples of form (java signature, (python arg types), post process function)

e.g. (“(I)I”,(int,),None) or (“(I)[L”,(int,),lambda x: javabridge.get_env().get_long_array_elements(x))
TASSELpy.utils.Overloading.make_string_array(arr)[source]
class TASSELpy.utils.Overloading.signature_dict[source]

Bases: dict

Methods

clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
setdefault((k[,d]) -> D.get(k,d), ...)
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)
TASSELpy.utils.Overloading.to_java_string(x)

TASSELpy.utils.caching module

class TASSELpy.utils.caching.LRUcache(retrieveFunc, maxsize=1000, *args, **kwargs)[source]

Bases: dict

A least recently used cache

Methods

clear(() -> None.  Remove all items from D.)
copy(() -> a shallow copy of D)
fromkeys(...) v defaults to None.
get((k[,d]) -> D[k] if k in D, ...)
has_key((k) -> True if D has a key k, else False)
items(() -> list of D’s (key, value) pairs, ...)
iteritems(() -> an iterator over the (key, ...)
iterkeys(() -> an iterator over the keys of D)
itervalues(...)
keys(() -> list of D’s keys)
pop((k[,d]) -> v, ...) If key is not found, d is returned if given, otherwise KeyError is raised
popitem(() -> (k, v), ...) 2-tuple; but raise KeyError if D is empty.
setdefault((k[,d]) -> D.get(k,d), ...)
update(([E, ...) If E present and has a .keys() method, does: for k in E: D[k] = E[k]
values(() -> list of D’s values)
viewitems(...)
viewkeys(...)
viewvalues(...)
__init__(retrieveFunc, maxsize=1000, *args, **kwargs)[source]

Instantiates the LRUcache

Parameters:

retrieveFunc : callable

Function that takes a key as an argument and returns the value corresponding to that key

maxsize : int

The maximum size the cache can keep before kicking keys out

class TASSELpy.utils.caching.doubleLinkedList[source]

Bases: object

A list of items that have pointers to previous and succeeding items

Methods

append(element) Appends an element to the linked list
getFirst() Gets the first element in the linked list
getLast() Gets the last element in the linked list
pop() Gets and removes the last element in the linked list
popleft() Gets and removes the first element in the linked list
removeNode(node) Removes a node from the linked list
__init__()[source]

Instantiates a doubleLinkedList

append(element)[source]

Appends an element to the linked list

Parameters:

element : object

The element to place at the rear of the list. If this is a doubleLinkedListNode, it will be added directly instead of being put into another doubleLinkedListNode first

getFirst()[source]

Gets the first element in the linked list

Returns:The first element in the list
getLast()[source]

Gets the last element in the linked list

Returns:The last element in the linked list
pop()[source]

Gets and removes the last element in the linked list

Returns:The last element in the list
popleft()[source]

Gets and removes the first element in the linked list

The first element in the list

removeNode(node)[source]

Removes a node from the linked list

Parameters:

node : doubleLinkedListNode object

The node to be removed

class TASSELpy.utils.caching.doubleLinkedListNode[source]

Bases: object

A node in a double linked list

Methods

getElement() Gets the element for this node
getPredecessor() Gets the predecessor of the node
getSuccessor() Gets the successor node
setElement(element) Sets the element in this node
setPredecessor(predecessor) Sets the predecessor of the node
setSuccessor(successor) Sets the successor of the node
__init__()[source]

Instantiates a double linked list node

getElement()[source]

Gets the element for this node

Returns:The element for this node
getPredecessor()[source]

Gets the predecessor of the node

Returns:The predecessor node
getSuccessor()[source]

Gets the successor node

Returns:The successor node
setElement(element)[source]

Sets the element in this node

Parameters:

element : object

The element to go in this node

setPredecessor(predecessor)[source]

Sets the predecessor of the node

Parameters:

predecessor : doubleLinkedListNode or None

The predecessor node

setSuccessor(successor)[source]

Sets the successor of the node

Parameters:

successor : doubleLinkedListNode or None

The successor node

TASSELpy.utils.helper module

TASSELpy.utils.helper.make_constructor_sig(args)[source]

Constructs the signature needed by javabridge for a function

Arguments:

args – A list of argument types for the function. If an array is specified, the class name
should end with []. The beginning L and end ; will be added if not already present. Otherwise, just put in the primative name (i.e. int char, etc)

Returns:

The signature for the java constructor

TASSELpy.utils.helper.make_sig(args, return_type)[source]

Constructs the signature needed by javabridge for a function

Arguments:

args – A list of argument types for the function. If an array is specified, the class name
should end with []. The beginning L and end ; will be added if not already present. Otherwise, just put in the primative name (i.e. int char, etc)

return_type – The return type of the function, specified in the same way as the arguments

Returns:

The signature for the java method

TASSELpy.utils.helper.send_to_java(prim_val)[source]

TASSELpy.utils.primativeArray module

class TASSELpy.utils.primativeArray.javaPrimativeArray[source]

Bases: TASSELpy.javaObj.javaArray

Wraps arrays of primative types

Methods

getArray(size) Gets an empty wrapped java array that can accept the type of the wrapped
getDblArray(rows[, cols]) Gets an empty wrapped java array that can accept the type of other wrapped java arrays: i.e.
get_array_type(primative_name)
make_array(primative_name, length) Makes a wrapped java array for some java primative
make_array_from_obj(primative_name, obj) Sends a returned java object of a wrapped java array
make_dbl_array(primative_name, rows[, cols]) Makes an empty wrapped java array that can accept the type of other wrapped java arrays of a primative type: e.g.
to_numpy_array() Makes a numpy array copy of the Java primative array
to_wrapped_array(arr_instance, pyType) Wraps a current array
wrap_existing_array(arr_instance) Wraps a java array of this class’s type
static get_array_type(primative_name)[source]
static make_array(primative_name, length)[source]

Makes a wrapped java array for some java primative

Arguments:

primative_name – The name of the java primative (e.g. ‘int’) length – The length of the array

Returns:

The wrapped java array

static make_array_from_obj(primative_name, obj)[source]

Sends a returned java object of a wrapped java array

Arguments:

primative_name – The name of the java primative (e.g. ‘int’) obj – The java object

Returns:

The wrapped java array

static make_dbl_array(primative_name, rows, cols=None)[source]

Makes an empty wrapped java array that can accept the type of other wrapped java arrays of a primative type: e.g. double[][]

Arguments:

rows – The number of rows that should be in the array (the first dimension) cols – The number of columns that should be in the array (if not specified, the

array objects will not be instantiated at these locations)

Returns:

An instance of an array of arrays

to_numpy_array()[source]

Makes a numpy array copy of the Java primative array

Returns:

Numpy array containing data

static to_wrapped_array(arr_instance, pyType)[source]

Wraps a current array

Arguments:

arr_instance – A java object containing the array pyType – The type of the javaObj

Returns:

The wrapped java array

classmethod wrap_existing_array(arr_instance)[source]

Wraps a java array of this class’s type

Arguments:

arr_instance – The java array

Returns:

The wrapped java array

class TASSELpy.utils.primativeArray.meta_byte_array[source]

Bases: object

Attributes

java_arr_type  
java_arr_type = None
class TASSELpy.utils.primativeArray.meta_double_array[source]

Bases: object

Attributes

java_arr_type  
java_arr_type = None
class TASSELpy.utils.primativeArray.meta_float_array[source]

Bases: object

Attributes

java_arr_type  
java_arr_type = None
class TASSELpy.utils.primativeArray.meta_int_array[source]

Bases: object

Attributes

java_arr_type  
java_arr_type = None
class TASSELpy.utils.primativeArray.meta_long_array[source]

Bases: object

Attributes

java_arr_type  
java_arr_type = None

Module contents