i like it!

This commit is contained in:
Kenneth Reitz
2011-08-12 19:49:16 -04:00
parent 227e2fa9ec
commit f98df0422f
2 changed files with 69 additions and 1 deletions
+47 -1
View File
@@ -6,4 +6,50 @@ resources.core
This omdule provides the core resources system.
"""
"""
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 '<resource \'{0}\'>'.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)
+22
View File
@@ -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