rpms/python-turbojson/devel python-turbojson-SAfix-r3749.patch, NONE, 1.1

Toshio くらとみ (toshio) fedora-extras-commits at redhat.com
Sat Feb 2 17:48:42 UTC 2008


Author: toshio

Update of /cvs/pkgs/rpms/python-turbojson/devel
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv27874

Added Files:
	python-turbojson-SAfix-r3749.patch 
Log Message:
Remember to add the patch.


python-turbojson-SAfix-r3749.patch:

--- NEW FILE python-turbojson-SAfix-r3749.patch ---
Index: turbojson/jsonify.py
===================================================================
--- turbojson/jsonify.py.orig
+++ turbojson/jsonify.py
@@ -75,7 +75,7 @@ try:
             result[name] = getattr(obj, name)
         return result
     jsonify_sqlobject = jsonify.when(
-            'isinstance(obj, sqlobject.SQLObject)')(jsonify_sqlobject)
+            'isinstance(obj, sqlobject.SQLObject) and not hasattr(obj, "__json__")')(jsonify_sqlobject)
 
     def jsonify_select_results(obj):
         return list(obj)
@@ -95,7 +95,7 @@ try:
            props[key] = getattr(obj, key)
        return props
     jsonify_saobject = jsonify.when(
-            "hasattr(obj, 'c') and isinstance(obj.c,sqlalchemy.util.OrderedProperties)")(jsonify_saobject)
+            "hasattr(obj, 'c') and isinstance(obj.c,sqlalchemy.util.OrderedProperties) and not hasattr(obj, '__json__')")(jsonify_saobject)
 
 except ImportError:
     pass
Index: turbojson/tests/test_jsonify.py
===================================================================
--- turbojson/tests/test_jsonify.py.orig
+++ turbojson/tests/test_jsonify.py
@@ -37,6 +37,7 @@ def test_so():
     except ImportError:
         return
     so.sqlhub.processConnection = so.connectionForURI('sqlite:/:memory:')
+
     class Person(so.SQLObject):
         fname = so.StringCol()
         mi = so.StringCol(length=1, default=None)
@@ -44,20 +45,40 @@ def test_so():
     Person.createTable()
     p = Person(fname="Peter", mi="P", lname="Pasulke")
     pj = jsonify.jsonify(p)
+    print pj
     assert pj == {'fname' : "Peter", 'mi' : "P", 'lname' : "Pasulke", 'id' : 1}
+
+    class ExplicitPerson(so.SQLObject):
+        fname = so.StringCol()
+        def __json__(self):
+            return {'customized': True}
+    ExplicitPerson.createTable()
+    ep = ExplicitPerson(fname="Peter")
+    epj = jsonify.jsonify(ep)
+    print epj
+    assert epj == {'customized': True}
+
     class A(InheritableSQLObject):
         foo = so.StringCol()
-
     A.createTable()
+
     class B(A):
         bar = so.StringCol()
-
     B.createTable()
 
+    class C(A):
+        baz = so.StringCol()
+        def __json__(self):
+            return {'customized': True}
+    C.createTable()
+
     
     b = B(foo="foo", bar="bar")
     bj = jsonify.jsonify(b)
     print bj
     assert bj == {'foo' : "foo", 'bar' : "bar", 'id' : b.id, 'childName' : None}
 
-
+    c = C(foo="foo", baz="baz")
+    cj = jsonify.jsonify(c)
+    print cj
+    assert cj == {'customized': True}




More information about the fedora-extras-commits mailing list