:py:mod:`gnome.persist.base_schema` =================================== .. py:module:: gnome.persist.base_schema Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: gnome.persist.base_schema.ObjType gnome.persist.base_schema.CollectionItemMap gnome.persist.base_schema.CollectionItemsList gnome.persist.base_schema.LongLat gnome.persist.base_schema.LongLatBounds gnome.persist.base_schema.WorldPoint gnome.persist.base_schema.WorldPointNumpy gnome.persist.base_schema.ImageSize Functions ~~~~~~~~~ .. autoapisummary:: gnome.persist.base_schema.now gnome.persist.base_schema.get_file_name_ext gnome.persist.base_schema.sanitize_string gnome.persist.base_schema.gen_unique_filename Attributes ~~~~~~~~~~ .. autoapisummary:: gnome.persist.base_schema.log gnome.persist.base_schema.Polygon .. py:data:: log .. py:function:: now(node, kw) Used by TimeseriesValueSchema - assume it defers the calculation of datetime.datetime.now to when it is called in Schema .. py:class:: ObjType(unknown='ignore') Bases: :py:obj:`colander.SchemaType` Base class for all schema types .. py:attribute:: unknown .. py:method:: _set_unknown(value) .. py:method:: _get_unknown() .. py:method:: cstruct_children(node, cstruct) .. py:method:: _impl(node, value, callback) .. py:method:: _ser(node, value, options=None) .. py:method:: serialize(node, appstruct, options=None) .. py:method:: _deser(node, value, refs) .. py:method:: deserialize(node, cstruct, refs) .. py:method:: flatten(node, appstruct, prefix='', listitem=False) .. py:method:: unflatten(node, paths, fstruct) .. py:method:: set_value(node, appstruct, path, value) .. py:method:: get_value(node, appstruct, path) .. py:method:: _prepare_save(node, raw_object, saveloc, refs) .. py:method:: _save(node, json_, zipfile_, refs) .. py:method:: save(node, appstruct, zipfile_, refs) .. py:method:: _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 .. py:method:: load(node, cstruct, saveloc, refs) .. py:method:: hydrate_json(node, cstruct, saveloc, refs) .. py:method:: _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 .. py:method:: _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 .. py:class:: CollectionItemMap(*arg, **kw) Bases: :py:obj:`colander.MappingSchema` This stores the obj_type and obj_index .. py:attribute:: obj_type .. py:attribute:: id .. py:class:: CollectionItemsList(*args, **kw) Bases: :py:obj:`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 :class:`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 :attr:`colander.drop`, the node will be dropped from schema serialization. If not provided, the node will be serialized to :attr:`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 :attr:`colander.required`, indicating that it is considered 'required'. When ``missing`` is :attr:`colander.required`, the ``required`` computed attribute will be ``True``. When ``missing`` is :attr:`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 :class:`colander.interfaces.Preparer` interface. - ``validator``: Optional validator for this node. It should be an object that implements the :class:`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. .. py:attribute:: item .. py:class:: LongLat(*arg, **kw) Bases: :py:obj:`colander.TupleSchema` Only contains 2D (long, lat) positions .. py:attribute:: long .. py:attribute:: lat .. py:class:: LongLatBounds(*args, **kw) Bases: :py:obj:`colander.SequenceSchema` Used to define bounds on a map .. py:attribute:: bounds .. py:data:: Polygon .. py:class:: WorldPoint(*arg, **kw) Bases: :py:obj:`LongLat` Used to define reference points. 3D positions (long,lat,z) .. py:attribute:: z .. py:class:: WorldPointNumpy(*arg, **kw) Bases: :py:obj:`gnome.persist.extend_colander.NumpyFixedLenSchema` Define same schema as WorldPoint; however, the base class NumpyFixedLenSchema serializes/deserializes it from/to a numpy array .. py:attribute:: long .. py:attribute:: lat .. py:attribute:: z .. py:class:: ImageSize(*arg, **kw) Bases: :py:obj:`colander.TupleSchema` Only contains 2D (long, lat) positions .. py:attribute:: width .. py:attribute:: height .. py:function:: get_file_name_ext(filename_in) .. py:function:: sanitize_string(s) .. py:function:: 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