Merge lp:~allenap/storm/json-property into lp:storm

Proposed by Gavin Panella
Status: Merged
Merged at revision: 399
Proposed branch: lp:~allenap/storm/json-property
Merge into: lp:storm
Prerequisite: lp:~jkakar/storm/json-property
Diff against target: 152 lines (+54/-9)
5 files modified
storm/compat.py (+32/-0)
storm/locals.py (+1/-7)
storm/variables.py (+8/-1)
tests/properties.py (+9/-0)
tests/variables.py (+4/-1)
To merge this branch: bzr merge lp:~allenap/storm/json-property
Reviewer Review Type Date Requested Status
Storm Developers Pending
Review via email: mp+74428@code.launchpad.net

Description of the change

This builds on Jamu's json-property branch (see the prerequisite) and fixes the things that Thomas requested.

To post a comment you must log in.
lp:~allenap/storm/json-property updated
399. By Gavin Panella

Merge lp:~jkakar/storm/json-property, resolving conflicts.

400. By Gavin Panella

Fall back to simplejson if json is not available, and degrade gracefully if no JSON support is available at all.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'storm/compat.py'
2--- storm/compat.py 1970-01-01 00:00:00 +0000
3+++ storm/compat.py 2011-09-07 14:06:25 +0000
4@@ -0,0 +1,32 @@
5+#
6+# Copyright (c) 2011 Canonical
7+#
8+# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
9+#
10+# This file is part of Storm Object Relational Mapper.
11+#
12+# Storm is free software; you can redistribute it and/or modify
13+# it under the terms of the GNU Lesser General Public License as
14+# published by the Free Software Foundation; either version 2.1 of
15+# the License, or (at your option) any later version.
16+#
17+# Storm is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Lesser General Public License for more details.
21+#
22+# You should have received a copy of the GNU Lesser General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+
26+__all__ = [
27+ "json",
28+ ]
29+
30+try:
31+ import json
32+except ImportError:
33+ try:
34+ import simplejson as json
35+ except ImportError:
36+ json = None
37
38=== modified file 'storm/locals.py'
39--- storm/locals.py 2011-09-07 14:06:25 +0000
40+++ storm/locals.py 2011-09-07 14:06:25 +0000
41@@ -18,15 +18,9 @@
42 # You should have received a copy of the GNU Lesser General Public License
43 # along with this program. If not, see <http://www.gnu.org/licenses/>.
44 #
45-<<<<<<< TREE
46-from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode, Pickle
47+from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode
48 from storm.properties import List, Decimal, DateTime, Date, Time, Enum, UUID
49-from storm.properties import TimeDelta
50-=======
51-from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode
52-from storm.properties import List, Decimal, DateTime, Date, Time, Enum
53 from storm.properties import TimeDelta, Pickle, JSON
54->>>>>>> MERGE-SOURCE
55 from storm.references import Reference, ReferenceSet, Proxy
56 from storm.database import create_database
57 from storm.exceptions import StormError
58
59=== modified file 'storm/variables.py'
60--- storm/variables.py 2011-09-07 14:06:25 +0000
61+++ storm/variables.py 2011-09-07 14:06:25 +0000
62@@ -21,13 +21,13 @@
63 from datetime import datetime, date, time, timedelta
64 from decimal import Decimal
65 import cPickle as pickle
66-import json
67 import re
68 try:
69 import uuid
70 except ImportError:
71 uuid = None
72
73+from storm.compat import json
74 from storm.exceptions import NoneError
75 from storm import Undef, has_cextensions
76
77@@ -625,6 +625,13 @@
78
79 class JSONVariable(EncodedValueVariable):
80
81+ __slots__ = ()
82+
83+ def __init__(self, *args, **kwargs):
84+ assert json is not None, (
85+ "Neither the json nor the simplejson module was found.")
86+ super(JSONVariable, self).__init__(*args, **kwargs)
87+
88 def _loads(self, value):
89 return json.loads(value)
90
91
92=== modified file 'tests/properties.py'
93--- tests/properties.py 2011-09-07 14:06:25 +0000
94+++ tests/properties.py 2011-09-07 14:06:25 +0000
95@@ -26,6 +26,7 @@
96 except ImportError:
97 uuid = None
98
99+from storm.compat import json
100 from storm.exceptions import NoneError, PropertyPathError
101 from storm.properties import PropertyPublisherMeta
102 from storm.properties import *
103@@ -694,6 +695,10 @@
104 self.assertEquals(changes, [(self.variable1, None, ["a"], False)])
105
106 def test_json(self):
107+ # Skip test if json support is not available.
108+ if json is None:
109+ return
110+
111 self.setup(JSON, default_factory=dict, allow_none=False)
112
113 self.assertTrue(isinstance(self.column1, Column))
114@@ -716,6 +721,10 @@
115 self.assertEquals(self.obj.prop1, ["a"])
116
117 def test_json_events(self):
118+ # Skip test if json support is not available.
119+ if json is None:
120+ return
121+
122 self.setup(JSON, default_factory=list, allow_none=False)
123
124 changes = []
125
126=== modified file 'tests/variables.py'
127--- tests/variables.py 2011-09-07 14:06:25 +0000
128+++ tests/variables.py 2011-09-07 14:06:25 +0000
129@@ -22,13 +22,13 @@
130 from decimal import Decimal
131 import cPickle as pickle
132 import gc
133-import json
134 import weakref
135 try:
136 import uuid
137 except ImportError:
138 uuid = None
139
140+from storm.compat import json
141 from storm.exceptions import NoneError
142 from storm.variables import *
143 from storm.event import EventSystem
144@@ -902,6 +902,9 @@
145 encoding = json
146 variable_type = JSONVariable
147
148+ def is_supported(self):
149+ return json is not None
150+
151
152 class ListVariableTest(TestHelper):
153

Subscribers

People subscribed via source and target branches

to status/vote changes: