Extend various (python/c++) objects by new methods/properties on them, or modify existing ones. This approach is called monkey patching, whence the module name.

This module is imported automatically by Woo at startup and should not be used directly.


Define IO routines for arbitrary objects.

woo._monkey.io.Master_load(o, *args, **kw)[source]
woo._monkey.io.Master_loadTmp(o, name='', quiet=None)[source]

Load scene from temporary storage, assign to it woo.master.scene and return it.

woo._monkey.io.Master_pause(o, *args, **kw)[source]
woo._monkey.io.Master_reload(o, quiet=None, *args, **kw)[source]

Reload master scene, using its woo.core.Scene.lastSave; assigns woo.master.scene and returns the new scene object

woo._monkey.io.Master_run(o, *args, **kw)[source]
woo._monkey.io.Master_save(o, *args, **kw)[source]
woo._monkey.io.Master_saveTmp(o, name='', quiet=False)[source]
woo._monkey.io.Master_step(o, *args, **kw)[source]
woo._monkey.io.Master_wait(o, *args, **kw)[source]
woo._monkey.io.Object_deepcopy(obj, **kw)[source]

Make object deepcopy by serializing to memory and deserializing.

woo._monkey.io.Object_dump(obj, out, format='auto', fallbackFormat=None, overwrite=True, fragment=False, width=80, noMagic=False, showDoc=False, hideWooExtra=False)[source]

Dump an object in specified format; out can be a str (filename) or a file object. Supported formats are: auto (auto-detected from out extension; raises exception when out is an object), html, expr.

woo._monkey.io.Object_dumps(obj, format, fragment=False, width=80, noMagic=False, stream=True, showDoc=False, hideWooExtra=False)[source]

Return list of all trait objects for this instance, recursively including all parent classes.


Return list of (trait,klass) relevant for obj, where klass is class (type object) to which each trait belongs.

woo._monkey.io.Object_load(typ, inFile, format='auto', overrideHashPercent={})[source]
woo._monkey.io.Object_loadTmp(typ, name='')[source]
woo._monkey.io.Object_loads(typ, data, format='auto', overrideHashPercent={})[source]

Load object from file, with format auto-detection; when typ is None, no type-checking is performed.

woo._monkey.io.Object_saveTmp(obj, name='', quiet=False)[source]
class woo._monkey.io.SerializerToExpr(indent='\t', maxWd=120, noMagic=True)[source]

Represent given object as python expression. Do not use this class directly, say object.dump(format="expr") instead.

unbreakableTypes = (<class '_wooEigen11.Vector2i'>, <class '_wooEigen11.Vector2'>, <class '_wooEigen11.Vector3i'>, <class '_wooEigen11.Vector3'>)

alias of woo._monkey.io.SerializerToHtmlTableGenshi

class woo._monkey.io.SerializerToHtmlTableGenshi(showDoc=False, maxDepth=8, hideNoGui=False, hideWooExtra=False)[source]

Dump given object to HTML table, using the Genshi templating engine; the produced serialization is XHTML-compliant. Do not use this class directly, say object.dump(format="html") instead.

htmlSeq(s, insideTable)[source]
padding = {'cellpadding': '2px'}
splitFloatSeq = 5
splitIntSeq = 5
splitStrSeq = 1
class woo._monkey.io.WooJSONDecoder(onError='error')[source]

Reconstruct JSON object, possibly containing specially-denoted Woo object (WooJSONEncoder). Do not use this class directly, say object.loads(format="json") instead.

The onError ctor parameter determines what to do with a dictionary defining ‘__class__’, which nevertheless cannot be reconstructed properly: this happens when class attributes changed inthe meantime, or the class does not exist anymore. Possible values are:

  • error: raise exception (default)

  • warn: log warning and return dictionary

  • ignore: just return dictionary, without any notification

object_hook, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given dict. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting).

object_pairs_hook, if specified will be called with the result of every JSON object decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

parse_float, if specified, will be called with the string of every JSON float to be decoded. By default this is equivalent to float(num_str). This can be used to use another datatype or parser for JSON floats (e.g. decimal.Decimal).

parse_int, if specified, will be called with the string of every JSON int to be decoded. By default this is equivalent to int(num_str). This can be used to use another datatype or parser for JSON integers (e.g. float).

parse_constant, if specified, will be called with one of the following strings: -Infinity, Infinity, NaN. This can be used to raise an exception if invalid JSON numbers are encountered.

If strict is false (true is the default), then control characters will be allowed inside strings. Control characters in this context are those with character codes in the 0-31 range, including '\t' (tab), '\n', '\r' and '\0'.

class woo._monkey.io.WooJSONEncoder(indent=3, sort_keys=True, oneway=False)[source]

Represent given object as JSON object. Do not use this class directly, say object.dump(format="json") instead.

oneway: allow serialization of objects which won’t be properly deserialized. They are: numpy.ndarray, h5py.Dataset.


Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
        iterable = iter(o)
    except TypeError:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
woo._monkey.io.wooExprEval(__e, __f, __overrideHashPercent={})[source]

Evaluate expression created with SerializerToExpr. Comments starting with #% and #: are executed as python code before the evaluation happens, which is in particular useful for importing necessary modules. The rule is the following:

  1. Lines starting with #% are executed in the local context.

  2. Values passed through __overrideHashPercent override variable values created in the preceding steps (it is an error if some variable is not defined).

  3. Lines starting with %: are evaluated in the local context.

The rationale for the 2-step evaluation is that variables defined in #% can be externally overridden in a controlled manner (if by mistake a non-existent variable is assigned externally, it is an error; if nothing is overridden externally, the default is used); and only after this override, #: lines can use those variables.

  • __e – expression to be evaluated

  • __f – filename (if any) where the expression was stored

  • __overrideHashPercent – dictionary which will change local variables (defined in #% lines) before the expression itself is evaluated.


This module reimplements the gts.read function in python, since it is stragenly broken under windows, and replaces the original one by monkey-patching.


Pure-python implementation of the pygts._gts.read function; it hangs under Windows when using woo.gts (not pure pygts), in gts-0.7.6/src/misc.c:173 in next_char, where fgetc is waiting for the next character indefinitely (why?); when fgetc was replaced by lower-level read(fileno,buf,1), GTS was complaining about not seeing the first integer (number of vertices) at the beginning of the file.

Since there seemed little point digging into GTS any further, this monkey-patch replaces that function with a pure-python implementation, which is perhaps not as efficient, but works reliably under Windows.

The patch is only applied under Windows, and if ‘gts’ is in woo.config.features (i.e. the module woo.gts exists, and is also exposed as gts).



Update docstrings which are not practical to be written in the c++ source code, such as woo.dem.Cg2_Sphere_Sphere_L6Geom.

Don’t forget to #. provide at least brief description of the class in the c++ code (for those who read the c++ code it); #. write something like Full documentation of this class is in py/_monkey/extraDocs.py.

Set the new docstring like this:

 Complicated documentation.


The c++ documentation will be overwritten by the new docstring.


Define various convenience attributes, such as Node.dem for accessing DEM data of a node (equivalent to node->getData<DemData>() in c++).

class woo._monkey.aliases.LabelMapperProxy(mapper, prefix='')[source]

Proxy for attribute-like access to woo.core.LabelMapper.

woo._monkey.aliases.deprecWrapper(self, _oldName, _newName, _newFunc, *args, **kw)[source]

Inject decprecated classes into woo modules as needed.


Report issues or inclarities to github.