From f98df0422f51d3c67b8ef0d6161aaee6560927ae Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 12 Aug 2011 19:49:16 -0400 Subject: [PATCH] i like it! --- resources/core.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++- toy.py | 22 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 toy.py diff --git a/resources/core.py b/resources/core.py index e6b51c6..363aa42 100644 --- a/resources/core.py +++ b/resources/core.py @@ -6,4 +6,50 @@ resources.core This omdule provides the core resources system. -""" \ No newline at end of file +""" + + +class Resource(object): + """docstring for Resource""" + def __init__(self, name=None, interface=None): + + self.name = name + self.interface = interface + + super(Resource, self).__init__() + + def __repr__(self): + return ''.format(self.name) + + + +class Interface(object): + """docstring for API""" + + resource = Resource() + + def __init__(self): + self.resources = dict() + + def __getattribute__(self, key): + if key not in ['resources']: + try: + return object.__getattribute__(self, key) + except AttributeError: + pass + + if key in self.resources: + return self.resources.get(key) + + return object.__getattribute__(self, key) + + + def map(self, resource, key): + self.resources[key] = resource(interface=self, name=key) + + + + + + + diff --git a/toy.py b/toy.py new file mode 100644 index 0000000..52c632d --- /dev/null +++ b/toy.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +import resources +from resources import Interface, Resource + + +# built in verbs +# + +api = Interface() + + +class Bookmarks(Resource): + """docstring for Bookmarks""" + pass + + +api.map(Bookmarks, 'bookmarks') + +# print api +print api.bookmarks +# print api.resources \ No newline at end of file