UID-Related Extras¶
-
class
properties.extras.
HasUID
(**kwargs)[source]¶ HasUID is a HasProperties class that includes unique ID
Adding a UID to HasProperties allows serialization of more complex structures, including recursive self-references. They are serialized to a flat dictionary of UID/HasUID key/value pairs.Required Properties:
- uid (
String
): Unique identifier, a unicode string, Default: new instance of str
-
classmethod
deserialize
(value, trusted=False, strict=False, assert_valid=False, **kwargs)[source]¶ Deserialize nested HasUID instance from flat pointer dictionary
Parameters
- value - Flat pointer dictionary produced by
serialize
with UID/HasUID key/value pairs. It also includes a__root__
key to specify the root HasUID instance. - trusted - If True (and if the input dictionaries have
'__class__'
keyword and this class is in the registry), the new HasProperties class will come from the dictionary. If False (the default), only the HasProperties class this method is called on will be constructed. - strict - Requires
'__class__'
, if present on the input dictionary, to match the deserialized instance’s class. Also disallows unused properties in the input dictionary. Default is False. - assert_valid - Require deserialized instance to be valid. Default is False.
- You may also specify an alternative root - This allows a different
HasUID root instance to be specified. It overrides
__root__
in the input dictionary. - Any other keyword arguments will be passed through to the Property deserializers.
Note
HasUID instances are constructed with no input arguments (ie
cls()
is called). This means deserialization will fail if the init method has been overridden to require input parameters.- value - Flat pointer dictionary produced by
-
classmethod
load
(uid)[source]¶ Load an instance given a UID
This is used by Pointer properties to retrieve instances from UIDs.
-
serialize
(include_class=True, save_dynamic=False, **kwargs)[source]¶ Serialize nested HasUID instances to a flat dictionary
Parameters:
- include_class - If True (the default), the name of the class
will also be saved to the serialized dictionary under key
'__class__'
- save_dynamic - If True, dynamic properties are written to the serialized dict (default: False).
- You may also specify a registry - This is the flat dictionary where UID/HasUID pairs are stored. By default, no registry need be provided; a new dictionary will be created.
- Any other keyword arguments will be passed through to the Property serializers.
- include_class - If True (the default), the name of the class
will also be saved to the serialized dictionary under key
- uid (
-
class
properties.extras.
Pointer
(doc, instance_class, **kwargs)[source]¶ Property for HasUID instances where string UID pointer may be used
Available keywords (in addition to those inherited from Instance):
- load - Attempt to load instances from UID on validation
If True, when the Pointer property is assigned a valid UID,
it will then attempt to call
self.instance_class.load(uid)
If this method is defined, it must return a valid instance which will replace the UID as the Pointer value. If this method is not defined or if it returns None, the Pointer property maintains the UID value. Default is False, meaning there is no attempt to load the instance. - uid_prop - Property or attribute name of the UID property on instance_class. The default is ‘uid’.
- load - Attempt to load instances from UID on validation
If True, when the Pointer property is assigned a valid UID,
it will then attempt to call