aboutsummaryrefslogtreecommitdiffstats
path: root/github3/helpers.py
diff options
context:
space:
mode:
authorAntti Kaihola <akaihol+github@ambitone.com>2011-11-09 13:04:48 +0200
committerAntti Kaihola <akaihol+github@ambitone.com>2011-11-09 13:04:48 +0200
commitf1a03e9fc8ce87ca1beeae5a92082bb32d342df3 (patch)
tree6bca689287379b249aff19fbae075182dc22f95a /github3/helpers.py
parentAdded create_gist() example to readme (diff)
parentFixing bugs. Crazy night :S (diff)
downloadpython-github3-f1a03e9fc8ce87ca1beeae5a92082bb32d342df3.tar.xz
python-github3-f1a03e9fc8ce87ca1beeae5a92082bb32d342df3.zip
Merged create_gist() into current HEAD of copitux/develop
Diffstat (limited to 'github3/helpers.py')
-rw-r--r--github3/helpers.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/github3/helpers.py b/github3/helpers.py
index abdeb4a..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
@@ -166,4 +185,4 @@ def get_scope(f, args=None):
# scrub readability.models namespace
scope = scope.replace('readability.api.', '')
- return scope \ No newline at end of file
+ return scope