gnome.persist.base_schema

Module Contents

Classes

ObjType

Base class for all schema types

CollectionItemMap

This stores the obj_type and obj_index

CollectionItemsList

Fundamental building block of schemas.

LongLat

Only contains 2D (long, lat) positions

LongLatBounds

Used to define bounds on a map

WorldPoint

Used to define reference points. 3D positions (long,lat,z)

WorldPointNumpy

Define same schema as WorldPoint; however, the base class

ImageSize

Only contains 2D (long, lat) positions

Functions

now(node, kw)

Used by TimeseriesValueSchema - assume it defers the calculation of

get_file_name_ext(filename_in)

sanitize_string(s)

gen_unique_filename(filename_in, zipfile_)

add a trailing number to the file name in case the user accidentally

Attributes

log

Polygon

gnome.persist.base_schema.log
gnome.persist.base_schema.now(node, kw)
Used by TimeseriesValueSchema - assume it defers the calculation of

datetime.datetime.now to when it is called in Schema

class gnome.persist.base_schema.ObjType(unknown='ignore')

Bases: colander.SchemaType

Base class for all schema types

unknown
_set_unknown(value)
_get_unknown()
cstruct_children(node, cstruct)
_impl(node, value, callback)
_ser(node, value, options=None)
serialize(node, appstruct, options=None)
_deser(node, value, refs)
deserialize(node, cstruct, refs)
flatten(node, appstruct, prefix='', listitem=False)
unflatten(node, paths, fstruct)
set_value(node, appstruct, path, value)
get_value(node, appstruct, path)
_prepare_save(node, raw_object, saveloc, refs)
_save(node, json_, zipfile_, refs)
save(node, appstruct, zipfile_, refs)
_process_supporting_file(raw_path, zipfile_)

raw_path is the filename stored on the object zipfile is an open zipfile.Zipfile in append mode returns the name of the file in the archive

load(node, cstruct, saveloc, refs)
hydrate_json(node, cstruct, saveloc, refs)
_load_supporting_file(filename, saveloc, tmpdir)

filename is the name of the file in the zip saveloc can be a folder or open zipfile.ZipFile object if saveloc is a folder and the filename exists inside, this does not return an altered name, nor does it extract to the temporary directory. An altered filename is returned if it cannot find the filename directly or if saveloc is an open zipfile in a temporary directory

_load_json_from_file(fname, saveloc)

filename is the name of the file in the zip saveloc can be a folder or open zipfile.ZipFile object

class gnome.persist.base_schema.CollectionItemMap(*arg, **kw)

Bases: colander.MappingSchema

This stores the obj_type and obj_index

obj_type
id
class gnome.persist.base_schema.CollectionItemsList(*args, **kw)

Bases: colander.SequenceSchema

Fundamental building block of schemas.

The constructor accepts these positional arguments:

  • typ: The ‘type’ for this node. It should be an instance of a class that implements the colander.interfaces.Type interface. If typ is not passed, a call to the schema_type() method on this class is made to get a default type. (When subclassing, schema_type() should be overridden to provide a reasonable default type).

  • *children: a sequence of subnodes. If the subnodes of this node are not known at construction time, they can later be added via the add method.

The constructor accepts these keyword arguments:

  • name: The name of this node.

  • typ: The ‘type’ for this node can optionally be passed in as a keyword argument. See the documentation for the positional arg above.

  • default: The default serialization value for this node when not set. If default is colander.drop, the node will be dropped from schema serialization. If not provided, the node will be serialized to colander.null.

  • missing: The default deserialization value for this node. If it is not provided, the missing value of this node will be the special marker value colander.required, indicating that it is considered ‘required’. When missing is colander.required, the required computed attribute will be True. When missing is colander.drop, the node is dropped from the schema if it isn’t set during deserialization.

  • missing_msg: Optional error message to be used if the value is required and missing.

  • preparer: Optional preparer for this node. It should be an object that implements the colander.interfaces.Preparer interface.

  • validator: Optional validator for this node. It should be an object that implements the colander.interfaces.Validator interface.

  • after_bind: A callback which is called after a clone of this node has ‘bound’ all of its values successfully. This callback is useful for performing arbitrary actions to the cloned node, or direct children of the cloned node (such as removing or adding children) at bind time. A ‘binding’ is the result of an execution of the bind method of the clone’s prototype node, or one of the parents of the clone’s prototype nodes. The deepest nodes in the node tree are bound first, so the after_bind methods of the deepest nodes are called before the shallowest. The after_bind callback should accept two values: node and kw. node will be a clone of the bound node object, kw will be the set of keywords passed to the bind method.

  • title: The title of this node. Defaults to a titleization of the name (underscores replaced with empty strings and the first letter of every resulting word capitalized). The title is used by higher-level systems (not by Colander itself).

  • description: The description for this node. Defaults to '' (the empty string). The description is used by higher-level systems (not by Colander itself).

  • widget: The ‘widget’ for this node. Defaults to None. The widget attribute is not interpreted by Colander itself, it is only meaningful to higher-level systems such as Deform.

  • insert_before: if supplied, it names a sibling defined by a superclass for its parent node; the current node will be inserted before the named node. It is not useful unless a mapping schema is inherited from another mapping schema, and you need to control the ordering of the resulting nodes.

Arbitrary keyword arguments remaining will be attached to the node object unmolested.

item
class gnome.persist.base_schema.LongLat(*arg, **kw)

Bases: colander.TupleSchema

Only contains 2D (long, lat) positions

long
lat
class gnome.persist.base_schema.LongLatBounds(*args, **kw)

Bases: colander.SequenceSchema

Used to define bounds on a map

bounds
gnome.persist.base_schema.Polygon
class gnome.persist.base_schema.WorldPoint(*arg, **kw)

Bases: LongLat

Used to define reference points. 3D positions (long,lat,z)

z
class gnome.persist.base_schema.WorldPointNumpy(*arg, **kw)

Bases: gnome.persist.extend_colander.NumpyFixedLenSchema

Define same schema as WorldPoint; however, the base class NumpyFixedLenSchema serializes/deserializes it from/to a numpy array

long
lat
z
class gnome.persist.base_schema.ImageSize(*arg, **kw)

Bases: colander.TupleSchema

Only contains 2D (long, lat) positions

width
height
gnome.persist.base_schema.get_file_name_ext(filename_in)
gnome.persist.base_schema.sanitize_string(s)
gnome.persist.base_schema.gen_unique_filename(filename_in, zipfile_)

add a trailing number to the file name in case the user accidentally uploads multiple files with the same name for different objects. also sanitizes out illegal characters