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

Class Attr

source code

object --+
         |
        Attr
Known Subclasses:

Encapsulates information about an attribute in the JSON encoding of the object. It identifies properties of the attribute such as whether it's read-only, its type, etc.

Instance Methods [hide private]
 
__init__(self, atype=None, rw=True, is_api_list=False)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
to_json(self, value, preserve_ro)
Returns the JSON encoding of the given attribute value.
source code
 
from_json(self, resource_root, data)
Parses the given JSON value into an appropriate python object.
source code

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

Class Variables [hide private]
  DATE_FMT = '%Y-%m-%dT%H:%M:%S.%fZ'
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, atype=None, rw=True, is_api_list=False)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

to_json(self, value, preserve_ro)

source code 

Returns the JSON encoding of the given attribute value.

If the value has a 'to_json_dict' object, that method is called. Otherwise, the following values are returned for each input type:

  • datetime.datetime: string with the API representation of a date.
  • dictionary: if 'atype' is ApiConfig, a list of ApiConfig objects.
  • python list: python list (or ApiList) with JSON encoding of items
  • the raw value otherwise

from_json(self, resource_root, data)

source code 

Parses the given JSON value into an appropriate python object.

This means:

  • a datetime.datetime if 'atype' is datetime.datetime
  • a converted config dictionary or config list if 'atype' is ApiConfig
  • if the attr is an API list, an ApiList with instances of 'atype'
  • an instance of 'atype' if it has a 'from_json_dict' method
  • a python list with decoded versions of the member objects if the input is a python list.
  • the raw value otherwise