sanskrit_data.schema.common¶
A module containing some data container base classes.
-
class
sanskrit_data.schema.common.
JsonObject
[source]¶ Bases:
object
The base class of all Json-serializable data container classes, with many utility methods.
-
classmethod
make_from_dict
(input_dict)[source]¶ Defines our canonical way of constructing a JSON object from a dict.
All other deserialization methods should use this.
Note that this assumes that json_class_index is populated properly!
from sanskrit_data.schema import *
before using this should take care of it.
Parameters: input_dict – Returns: A subclass of JsonObject
-
schema
= {'required': ['jsonClass'], 'type': 'object', 'properties': {'jsonClass': {'type': 'string'}}}¶
-
to_json_map
()[source]¶ One convenient way of ‘serializing’ the object.
So, the type must be properly set. Many functions accept such json maps, just as they accept strings.
-
validate
(db_interface=None)[source]¶ Validate the JSON serialization of this object using the schema member. Called before database writes.
Parameters: db_interface – Potentially useful in subclasses to perform validations (eg. is the target_id valid). This value may not be available: for example when called from the from_details methods. Returns: a boolean.
-
classmethod
-
class
sanskrit_data.schema.common.
JsonObjectNode
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
Represents a tree (not a general Directed Acyclic Graph) of JsonObjectWithTargets.
-
schema
= {'required': ['jsonClass'], 'type': 'object', 'properties': {'content': {'required': ['jsonClass'], 'type': 'object', 'properties': {'jsonClass': {'type': 'string'}}}, 'children': {'items': {'type': 'object', '$ref': 'JsonObjectNode'}, 'type': 'array'}, 'jsonClass': {'enum': ['JsonObjectNode'], 'type': 'string'}}, 'id': 'JsonObjectNode'}¶ Recursively valdiate target-types.
-
-
class
sanskrit_data.schema.common.
JsonObjectWithTarget
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
A JsonObject with a target field.
-
schema
= {'required': ['jsonClass'], 'type': 'object', 'description': 'A JsonObject with a target field.', 'properties': {'targets': {'items': {'required': ['container_id', 'jsonClass'], 'type': 'object', 'properties': {'container_id': {'type': 'string'}, 'jsonClass': {'enum': ['Target'], 'type': 'string'}}}, 'type': 'array', 'description': 'This field lets us define a directed graph involving JsonObjects stored in a database.'}, 'jsonClass': {'type': 'string'}}}¶
-
-
class
sanskrit_data.schema.common.
ScriptRendering
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
schema
= {'required': ['text', 'jsonClass'], 'type': 'object', 'properties': {'encoding_scheme': {'type': 'string'}, 'text': {'type': 'string'}, 'jsonClass': {'enum': ['ScriptRendering'], 'type': 'string'}}}¶
-
-
class
sanskrit_data.schema.common.
Target
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
schema
= {'required': ['container_id', 'jsonClass'], 'type': 'object', 'properties': {'container_id': {'type': 'string'}, 'jsonClass': {'enum': ['Target'], 'type': 'string'}}}¶
-
-
exception
sanskrit_data.schema.common.
TargetValidationError
(allowed_types, target_obj, targetting_obj)[source]¶ Bases:
exceptions.Exception
-
class
sanskrit_data.schema.common.
Text
[source]¶ Bases:
sanskrit_data.schema.common.JsonObject
-
schema
= {'required': ['jsonClass'], 'type': 'object', 'properties': {'jsonClass': {'enum': ['Text'], 'type': 'string'}, 'script_renderings': {'items': {'type': {'required': ['text', 'jsonClass'], 'type': 'object', 'properties': {'encoding_scheme': {'type': 'string'}, 'text': {'type': 'string'}, 'jsonClass': {'enum': ['ScriptRendering'], 'type': 'string'}}}}, 'type': 'array'}, 'language_code': {'type': 'string'}}}¶
-
-
sanskrit_data.schema.common.
json_class_index
= {'JsonObjectWithTarget': <class 'sanskrit_data.schema.common.JsonObjectWithTarget'>, 'Target': <class 'sanskrit_data.schema.common.Target'>, 'JsonObject': <class 'sanskrit_data.schema.common.JsonObject'>, 'BookMetadata': <class 'sanskrit_data.schema.books.BookMetadata'>, 'TargetValidationError': <class 'sanskrit_data.schema.common.TargetValidationError'>, 'BookPortion': <class 'sanskrit_data.schema.books.BookPortion'>, 'ScriptRendering': <class 'sanskrit_data.schema.common.ScriptRendering'>, 'JsonObjectNode': <class 'sanskrit_data.schema.common.JsonObjectNode'>, 'Text': <class 'sanskrit_data.schema.common.Text'>, 'PublicationDetails': <class 'sanskrit_data.schema.books.PublicationDetails'>, 'BookPositionTarget': <class 'sanskrit_data.schema.books.BookPositionTarget'>}¶ Maps jsonClass values to the containing Python module object. Useful for (de)serialization. Updated using
update_json_class_index()
calls at the end of each module file (such as this one) whose classes may be serialized.