2
2
"""SparkData base-class; models Spark JSON objects as native Python objects.
3
3
4
4
The SparkData class models any JSON object passed to it as a string or Python
5
- dictionary as a native Python object; providing attribute access access using
6
- native object.attribute syntax .
5
+ dictionary as a native Python object; providing attribute access using native
6
+ dot-syntax (` object.attribute`) .
7
7
8
8
SparkData is intended to serve as a base-class, which provides inheritable
9
9
functionality, for concrete sub-classes that model specific Cisco Spark data
14
14
to objects by the Cisco Spark cloud.
15
15
16
16
Example:
17
- >>> json_obj = '{"created": "2012-06-15T20:36:48.914Z",
18
- "displayName": "Chris Lunsford (chrlunsf)",
19
- "id": "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mZjhlZTZmYi1hZm ...",
20
- "avatar": "https://1efa7a94ed216783e352-c622665287144 ...",
21
-
17
+ >>> json_obj = ''' {"created": "2012-06-15T20:36:48.914Z",
18
+ "displayName": "Chris Lunsford (chrlunsf)",
19
+ "id": "Y2lzY29zcGFyazovL3VzL1BFT1BMRS9mZjhlZTZmYi1h ...",
20
+ "avatar": "https://1efa7a94ed216783e352-c6226652871 ...",
21
+ "emails": ["[email protected] "]}'' '
22
22
>>> python_obj = SparkData(json_obj)
23
23
>>> python_obj.displayName
24
24
u'Chris Lunsford (chrlunsf)'
48
48
49
49
50
50
def _json_dict (json ):
51
- """Given a JSON dictionary or string; return a dictionary.
51
+ """Given a dictionary or JSON string; return a dictionary.
52
52
53
53
Args:
54
54
json(dict, str): Input JSON object.
@@ -74,7 +74,7 @@ class SparkData(object):
74
74
"""Model Spark JSON objects as native Python objects."""
75
75
76
76
def __init__ (self , json ):
77
- """Init a new SparkData object from a JSON dictionary or string.
77
+ """Init a new SparkData object from a dictionary or JSON string.
78
78
79
79
Args:
80
80
json(dict, str): Input JSON object.
@@ -87,7 +87,7 @@ def __init__(self, json):
87
87
self ._json = _json_dict (json )
88
88
89
89
def __getattr__ (self , item ):
90
- """Provide native attribute access to the JSON object's attributes.
90
+ """Provide native attribute access to the JSON object attributes.
91
91
92
92
This method is called when attempting to access a object attribute that
93
93
hasn't been defined for the object. For example trying to access
0 commit comments