Commits

Jan Brohl  committed 78b90a0

__repr__ für REST
objecthook anpassbar gemacht
ver 0.1.2

  • Participants
  • Parent commits a975d88
  • Tags 0.1.2

Comments (0)

Files changed (3)

 '''
 from distutils.core import setup
 
-ver = "0.1.1"
+ver = "0.1.2"
 name = "SimpleREST"
 url = "https://bitbucket.org/janbrohl/" + name.lower()
 

File src/simplerest/rest.py

         return CallableVirtualPath(oncall=(lambda path, query_args:
                                    self.get("/".join(path), **query_args)))
 
+    def __repr__(self):
+        return "%s(%r,%r)" % (self.__class__.__name__, self.basispfad, self.media_types)
+
 
 class JSON_REST(REST):
     def __init__(self, basispfad, object_hook=default_hook):
     def get(self, objektpfad, **query_args):
         return REST.get(self, objektpfad,
                         **dict((k, dumps(v)) for k, v in query_args.items()))
+
+    def __repr__(self):
+        return "%s(%r,%r)" % (self.__class__.__name__, self.basispfad, self.object_hook)

File src/simplerest/util.py

     return s
 
 
-def default_hook(obj):
-    """
-    for use as object_hook in json.loads    
-    """
-    stuff = dict()
-    for k, v in obj.items():
-        if v is not None:
+class ObjectHook(object):
+
+    def __init__(self, string_hook=convert, key_hook=convert):
+        self.string_hook = string_hook
+        self.key_hook = key_hook
+
+    def __call__(self, obj):
+        """
+        for use as object_hook in json.loads
+        """
+        sh = self.string_hook
+        kh = self.key_hook
+        stuff = dict()
+        for k, v in obj.items():
             if isinstance(v, basestring):
-                v = convert(v)
+                v = sh(v)
             elif isinstance(v, dict):
-                v = default_hook(v)
-        stuff[convert(k)] = v
-    return stuff
+                v = self(v)
+            stuff[kh(k)] = v
+        return stuff
+
+default_hook = ObjectHook()
 
 
 def _to_ints(m):