aboutsummaryrefslogtreecommitdiffstats
path: root/github3/helpers.py
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2011-11-01 12:30:25 +0100
committerDavid Medina <davidmedina9@gmail.com>2011-11-01 12:30:25 +0100
commitb17dbea56f59aa5403e5722e12878c7183742551 (patch)
treeea02535e78ae2c59d9099850e5ab2d4b1d044f10 /github3/helpers.py
parentWip on handlers (diff)
downloadpython-github3-b17dbea56f59aa5403e5722e12878c7183742551.tar.xz
python-github3-b17dbea56f59aa5403e5722e12878c7183742551.zip
Decouple Handlers and Models
Handler User complete
Diffstat (limited to 'github3/helpers.py')
-rw-r--r--github3/helpers.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/github3/helpers.py b/github3/helpers.py
index 498a005..205e097 100644
--- a/github3/helpers.py
+++ b/github3/helpers.py
@@ -57,6 +57,7 @@ def to_python(obj,
date_keys=None,
int_keys=None,
object_map=None,
+ list_map=None,
bool_keys=None, **kwargs):
"""Extends a given object for API Consumption.
@@ -96,14 +97,32 @@ def to_python(obj,
if object_map:
for (k, v) in object_map.items():
if in_dict.get(k):
+ if v == 'self':
+ v = obj.__class__
d[k] = v.new_from_dict(in_dict.get(k))
+ if list_map:
+ for k, model in list_map.items():
+ nested_map = in_dict.get(k)
+ if nested_map:
+ if getattr(nested_map, 'items', False):
+ map_dict = {}
+ for nested_item, nested_dict in nested_map.items():
+ map_dict[nested_item] = model.new_from_dict(nested_dict)
+ d[k] = map_dict
+ else:
+ map_list = []
+ for item_map in nested_map:
+ map_list.append(model.new_from_dict(item_map))
+ d[k] = map_list
+
obj.__dict__.update(d)
obj.__dict__.update(kwargs)
# Save the dictionary, for write comparisons.
obj._cache = d
obj.__cache = in_dict
+ obj.post_map()
return obj