Package cm_api :: Package endpoints :: Module types :: Class BaseApiObject
[hide private]
[frames] | no frames]

Class BaseApiObject

source code

object --+
         |
        BaseApiObject
Known Subclasses:

The BaseApiObject helps with (de)serialization from/to JSON.

The derived class has two ways of defining custom attributes:

It's recommended that the _get_attributes() implementation do caching to avoid computing the dictionary on every invocation.

The derived class's constructor must call the base class's init() static method. All constructor arguments (aside from self and resource_root) must be keywords arguments with default values (typically None), or from_json_dict() will not work.

Instance Methods [hide private]
 
__init__(self, resource_root, **attrs)
Initializes internal state and sets all known writable properties of the object to None.
source code
 
_set_attrs(self, attrs, allow_ro=False, from_json=True)
Sets all the attributes in the dictionary.
source code
 
__setattr__(self, name, val)
x.__setattr__('name', value) <==> x.name = value
source code
 
_check_attr(self, name, allow_ro) source code
 
_get_resource_root(self) source code
 
_update(self, api_obj)
Copy state from api_obj to this object.
source code
 
to_json_dict(self, preserve_ro=False) source code
 
__str__(self)
Default implementation of __str__.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
_get_attributes(cls)
Returns a map of property names to attr instances (or None for default attribute behavior) describing the properties of the object.
source code
 
from_json_dict(cls, dic, resource_root) source code
Static Methods [hide private]
 
init(obj, resource_root, attrs=None)
Wraper around the real constructor to avoid issues with the 'self' argument.
source code
Class Variables [hide private]
  _ATTRIBUTES = {}
  _WHITELIST = ('_resource_root', '_attributes')
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

_get_attributes(cls)
Class Method

source code 

Returns a map of property names to attr instances (or None for default attribute behavior) describing the properties of the object.

By default, this method will return the class's _ATTRIBUTES field. Classes can override this method to do custom initialization of the attributes when needed.

init(obj, resource_root, attrs=None)
Static Method

source code 

Wraper around the real constructor to avoid issues with the 'self' argument. Call like this, from a subclass's constructor:

  • BaseApiObject.init(self, locals())

__init__(self, resource_root, **attrs)
(Constructor)

source code 

Initializes internal state and sets all known writable properties of the object to None. Then initializes the properties given in the provided attributes dictionary.

Parameters:
  • resource_root - API resource object.
  • attrs - optional dictionary of attributes to set. This should only contain r/w attributes.
Overrides: object.__init__

_set_attrs(self, attrs, allow_ro=False, from_json=True)

source code 

Sets all the attributes in the dictionary. Optionally, allows setting read-only attributes (e.g. when deserializing from JSON) and skipping JSON deserialization of values.

__setattr__(self, name, val)

source code 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

Default implementation of __str__. Uses the type name and the first attribute retrieved from the attribute map to create the string.

Overrides: object.__str__