Skip to content

Commit 61667e3

Browse files
author
Kenneth Reitz
committed
omnijson
1 parent fbcbac3 commit 61667e3

File tree

10 files changed

+1684
-143
lines changed

10 files changed

+1684
-143
lines changed

NOTICE

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
python-github3 includes some vendorized python libraries: ordereddict and anyjson.
1+
python-github3 includes some vendorized python libraries: ordereddict, omijson, and simplejson.
22

33

44
OrderedDict License
@@ -28,37 +28,38 @@ subject to the following conditions:
2828

2929

3030

31-
AnyJSON License
31+
OmniJSON License
3232
==================
3333

34-
This software is licensed under the ``New BSD License``:
34+
Copyright (c) 2011 Kenneth Reitz
3535

36-
Copyright (c) 2009, by the authors
37-
All rights reserved.
36+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3837

39-
Redistribution and use in source and binary forms, with or without
40-
modification, are permitted provided that the following conditions are met:
38+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
4139

42-
* Redistributions of source code must retain the above copyright notice,
43-
this list of conditions and the following disclaimer.
44-
* Redistributions in binary form must reproduce the above copyright
45-
notice, this list of conditions and the following disclaimer in the
46-
documentation and/or other materials provided with the distribution.
40+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4741

48-
Neither the name of the authors nor the names of its contributors may be used
49-
to endorse or promote products derived from this software without specific
50-
prior written permission.
5142

52-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
53-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
54-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
55-
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
56-
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
57-
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
58-
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
59-
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
60-
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
61-
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
62-
POSSIBILITY OF SUCH DAMAGE.
43+
SimpleJSON License
44+
==================
45+
46+
47+
Copyright (c) 2006 Bob Ippolito
48+
49+
Permission is hereby granted, free of charge, to any person obtaining a copy of
50+
this software and associated documentation files (the "Software"), to deal in
51+
the Software without restriction, including without limitation the rights to
52+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
53+
of the Software, and to permit persons to whom the Software is furnished to do
54+
so, subject to the following conditions:
6355

56+
The above copyright notice and this permission notice shall be included in all
57+
copies or substantial portions of the Software.
6458

59+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65+
SOFTWARE.

github3/packages/anyjson.py

Lines changed: 0 additions & 117 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import absolute_import
4+
5+
from .core import loads, dumps, JSONError
6+
7+
8+
__all__ = ('loads', 'dumps', 'JSONError')
9+
10+
11+
__version__ = '0.1.2'
12+
__author__ = 'Kenneth Reitz'
13+
__license__ = 'MIT'

github3/packages/omnijson/core.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
omijson.core
5+
~~~~~~~~~~~~
6+
7+
This module provides the core omnijson functionality.
8+
9+
"""
10+
11+
import sys
12+
13+
engine = None
14+
_engine = None
15+
16+
17+
options = [
18+
['ujson', 'loads', 'dumps', (ValueError,)],
19+
['yajl', 'loads', 'dumps', (TypeError, ValueError)],
20+
['jsonlib2', 'read', 'write', (ValueError,)],
21+
['jsonlib', 'read', 'write', (ValueError,)],
22+
['simplejson', 'loads', 'dumps', (TypeError, ValueError)],
23+
['json', 'loads', 'dumps', (TypeError, ValueError)],
24+
['simplejson_from_packages', 'loads', 'dumps', (ValueError,)],
25+
]
26+
27+
28+
def _import(engine):
29+
try:
30+
if '_from_' in engine:
31+
engine, package = engine.split('_from_')
32+
m = __import__(package, globals(), locals(), [engine], -1)
33+
return getattr(m, engine)
34+
35+
return __import__(engine)
36+
37+
except ImportError:
38+
return False
39+
40+
41+
def loads(s, **kwargs):
42+
"""Loads JSON object."""
43+
44+
try:
45+
return _engine[0](s)
46+
47+
except:
48+
# crazy 2/3 exception hack
49+
# http://www.voidspace.org.uk/python/weblog/arch_d7_2010_03_20.shtml
50+
51+
ExceptionClass, why = sys.exc_info()[:2]
52+
53+
if any([(issubclass(ExceptionClass, e)) for e in _engine[2]]):
54+
raise JSONError(why)
55+
else:
56+
raise why
57+
58+
59+
def dumps(o, **kwargs):
60+
"""Dumps JSON object."""
61+
62+
try:
63+
return _engine[1](o)
64+
65+
except:
66+
ExceptionClass, why = sys.exc_info()[:2]
67+
68+
if any([(issubclass(ExceptionClass, e)) for e in _engine[2]]):
69+
raise JSONError(why)
70+
else:
71+
raise why
72+
73+
74+
class JSONError(ValueError):
75+
"""JSON Failed."""
76+
77+
78+
# ------
79+
# Magic!
80+
# ------
81+
82+
83+
for e in options:
84+
85+
__engine = _import(e[0])
86+
87+
if __engine:
88+
engine, _engine = e[0], e[1:4]
89+
90+
for i in (0, 1):
91+
_engine[i] = getattr(__engine, _engine[i])
92+
93+
break

github3/packages/omnijson/packages/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)