diff options
author | 2012-02-18 12:07:52 +0100 | |
---|---|---|
committer | 2012-02-18 12:07:52 +0100 | |
commit | 37a9c5dd5d5d693b177b263c40624b671baee045 (patch) | |
tree | 7c146bdff5913389d58e6f07175fbcf55d3e25a3 /pygithub3/resources/base.py | |
parent | Small refactor to building requests in services (diff) | |
download | python-github3-37a9c5dd5d5d693b177b263c40624b671baee045.tar.xz python-github3-37a9c5dd5d5d693b177b263c40624b671baee045.zip |
Support to resources-self-nested into collections
Diffstat (limited to 'pygithub3/resources/base.py')
-rw-r--r-- | pygithub3/resources/base.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pygithub3/resources/base.py b/pygithub3/resources/base.py index 183c9eb..255f4c1 100644 --- a/pygithub3/resources/base.py +++ b/pygithub3/resources/base.py @@ -39,6 +39,13 @@ class Resource(object): @classmethod def __load(self, raw_resource): + def self_resource(func): + def wrapper(resource, raw_resource): + if resource == 'self': + resource = self + return func(resource, raw_resource) + return wrapper + def parse_date(string_date): from datetime import datetime try: @@ -47,12 +54,12 @@ class Resource(object): date = None return date + @self_resource def parse_map(resource, raw_resource): - if resource == 'self': - return self.__load(raw_resource) if hasattr(raw_resource, 'items'): return resource.__load(raw_resource) + @self_resource def parse_collection_map(resource, raw_resources): # Dict of resources (Ex: Gist file) if hasattr(raw_resources, 'items'): |