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
=== added file 'storm/compat.py'
--- storm/compat.py 1970-01-01 00:00:00 +0000
+++ storm/compat.py 2011-09-07 14:06:25 +0000
@@ -0,0 +1,32 @@
1#
2# Copyright (c) 2011 Canonical
3#
4# Written by Gustavo Niemeyer <gustavo@niemeyer.net>
5#
6# This file is part of Storm Object Relational Mapper.
7#
8# Storm is free software; you can redistribute it and/or modify
9# it under the terms of the GNU Lesser General Public License as
10# published by the Free Software Foundation; either version 2.1 of
11# the License, or (at your option) any later version.
12#
13# Storm is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21
22__all__ = [
23 "json",
24 ]
25
26try:
27 import json
28except ImportError:
29 try:
30 import simplejson as json
31 except ImportError:
32 json = None
033
=== modified file 'storm/locals.py'
--- storm/locals.py 2011-09-07 14:06:25 +0000
+++ storm/locals.py 2011-09-07 14:06:25 +0000
@@ -18,15 +18,9 @@
18# You should have received a copy of the GNU Lesser General Public License18# You should have received a copy of the GNU Lesser General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#20#
21<<<<<<< TREE21from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode
22from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode, Pickle
23from storm.properties import List, Decimal, DateTime, Date, Time, Enum, UUID22from storm.properties import List, Decimal, DateTime, Date, Time, Enum, UUID
24from storm.properties import TimeDelta
25=======
26from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode
27from storm.properties import List, Decimal, DateTime, Date, Time, Enum
28from storm.properties import TimeDelta, Pickle, JSON23from storm.properties import TimeDelta, Pickle, JSON
29>>>>>>> MERGE-SOURCE
30from storm.references import Reference, ReferenceSet, Proxy24from storm.references import Reference, ReferenceSet, Proxy
31from storm.database import create_database25from storm.database import create_database
32from storm.exceptions import StormError26from storm.exceptions import StormError
3327
=== modified file 'storm/variables.py'
--- storm/variables.py 2011-09-07 14:06:25 +0000
+++ storm/variables.py 2011-09-07 14:06:25 +0000
@@ -21,13 +21,13 @@
21from datetime import datetime, date, time, timedelta21from datetime import datetime, date, time, timedelta
22from decimal import Decimal22from decimal import Decimal
23import cPickle as pickle23import cPickle as pickle
24import json
25import re24import re
26try:25try:
27 import uuid26 import uuid
28except ImportError:27except ImportError:
29 uuid = None28 uuid = None
3029
30from storm.compat import json
31from storm.exceptions import NoneError31from storm.exceptions import NoneError
32from storm import Undef, has_cextensions32from storm import Undef, has_cextensions
3333
@@ -625,6 +625,13 @@
625625
626class JSONVariable(EncodedValueVariable):626class JSONVariable(EncodedValueVariable):
627627
628 __slots__ = ()
629
630 def __init__(self, *args, **kwargs):
631 assert json is not None, (
632 "Neither the json nor the simplejson module was found.")
633 super(JSONVariable, self).__init__(*args, **kwargs)
634
628 def _loads(self, value):635 def _loads(self, value):
629 return json.loads(value)636 return json.loads(value)
630637
631638
=== modified file 'tests/properties.py'
--- tests/properties.py 2011-09-07 14:06:25 +0000
+++ tests/properties.py 2011-09-07 14:06:25 +0000
@@ -26,6 +26,7 @@
26except ImportError:26except ImportError:
27 uuid = None27 uuid = None
2828
29from storm.compat import json
29from storm.exceptions import NoneError, PropertyPathError30from storm.exceptions import NoneError, PropertyPathError
30from storm.properties import PropertyPublisherMeta31from storm.properties import PropertyPublisherMeta
31from storm.properties import *32from storm.properties import *
@@ -694,6 +695,10 @@
694 self.assertEquals(changes, [(self.variable1, None, ["a"], False)])695 self.assertEquals(changes, [(self.variable1, None, ["a"], False)])
695696
696 def test_json(self):697 def test_json(self):
698 # Skip test if json support is not available.
699 if json is None:
700 return
701
697 self.setup(JSON, default_factory=dict, allow_none=False)702 self.setup(JSON, default_factory=dict, allow_none=False)
698703
699 self.assertTrue(isinstance(self.column1, Column))704 self.assertTrue(isinstance(self.column1, Column))
@@ -716,6 +721,10 @@
716 self.assertEquals(self.obj.prop1, ["a"])721 self.assertEquals(self.obj.prop1, ["a"])
717722
718 def test_json_events(self):723 def test_json_events(self):
724 # Skip test if json support is not available.
725 if json is None:
726 return
727
719 self.setup(JSON, default_factory=list, allow_none=False)728 self.setup(JSON, default_factory=list, allow_none=False)
720729
721 changes = []730 changes = []
722731
=== modified file 'tests/variables.py'
--- tests/variables.py 2011-09-07 14:06:25 +0000
+++ tests/variables.py 2011-09-07 14:06:25 +0000
@@ -22,13 +22,13 @@
22from decimal import Decimal22from decimal import Decimal
23import cPickle as pickle23import cPickle as pickle
24import gc24import gc
25import json
26import weakref25import weakref
27try:26try:
28 import uuid27 import uuid
29except ImportError:28except ImportError:
30 uuid = None29 uuid = None
3130
31from storm.compat import json
32from storm.exceptions import NoneError32from storm.exceptions import NoneError
33from storm.variables import *33from storm.variables import *
34from storm.event import EventSystem34from storm.event import EventSystem
@@ -902,6 +902,9 @@
902 encoding = json902 encoding = json
903 variable_type = JSONVariable903 variable_type = JSONVariable
904904
905 def is_supported(self):
906 return json is not None
907
905908
906class ListVariableTest(TestHelper):909class ListVariableTest(TestHelper):
907910

Subscribers

People subscribed via source and target branches

to status/vote changes: