Skip to content

Commit 3dcc614

Browse files
committed
Removed simplejson dependency
See ej2#358
1 parent 9de4c9e commit 3dcc614

File tree

6 files changed

+199
-289
lines changed

6 files changed

+199
-289
lines changed

Pipfile

-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ pytest-cov = "*"
1313
urllib3 = ">=2.1.0"
1414
intuit-oauth = "==1.2.5"
1515
requests = ">=2.31.0"
16-
simplejson = ">=3.19.1"
1716
requests_oauthlib = ">=1.3.1"

Pipfile.lock

+181-276
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickbooks/client.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import http.client as httplib
22
import textwrap
3-
import simplejson as json
3+
import json
44
import base64
55
import hashlib
66
import hmac
7+
import decimal
78

89
from . import exceptions
910
from requests_oauthlib import OAuth2Session
1011

11-
to_bytes = lambda value, *args, **kwargs: bytes(value, "utf-8", *args, **kwargs)
12+
def to_bytes(value, *args, **kwargs):
13+
return bytes(value, "utf-8", *args, **kwargs)
1214

1315

1416
class Environments(object):
@@ -206,7 +208,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
206208
"Application authentication failed", error_code=req.status_code, detail=req.text)
207209

208210
try:
209-
result = json.loads(req.text, use_decimal=True)
211+
result = json.loads(req.text, parse_float=decimal.Decimal)
210212
except:
211213
raise exceptions.QuickbooksException("Error reading json response: {0}".format(req.text), 10000)
212214

quickbooks/mixins.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
import decimal
2+
import json
13
from urllib.parse import quote
24

3-
import simplejson as json
4-
5-
from .utils import build_where_clause, build_choose_clause
65
from .client import QuickBooks
76
from .exceptions import QuickbooksException
7+
from .utils import build_choose_clause, build_where_clause
8+
9+
class DecimalEncoder(json.JSONEncoder):
10+
def default(self, obj):
11+
if isinstance(obj, decimal.Decimal):
12+
return str(obj)
13+
return super(DecimalEncoder, self).default(obj)
814

915
class ToJsonMixin(object):
1016
def to_json(self):
11-
return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4, use_decimal=True)
17+
return json.dumps(self, cls=DecimalEncoder, default=self.json_filter(), sort_keys=True, indent=4)
1218

1319
def json_filter(self):
1420
"""
@@ -176,7 +182,7 @@ def void(self, qb=None):
176182

177183
data = self.get_void_data()
178184
params = self.get_void_params()
179-
results = qb.post(url, json.dumps(data, use_decimal=True), params=params)
185+
results = qb.post(url, json.dumps(data, cls=DecimalEncoder), params=params)
180186

181187
return results
182188

@@ -230,7 +236,7 @@ def delete(self, qb=None, request_id=None):
230236
'Id': self.Id,
231237
'SyncToken': self.SyncToken,
232238
}
233-
return qb.delete_object(self.qbo_object_name, json.dumps(data, use_decimal=True), request_id=request_id)
239+
return qb.delete_object(self.qbo_object_name, json.dumps(data, cls=DecimalEncoder), request_id=request_id)
234240

235241

236242
class DeleteNoIdMixin(object):

requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
intuit-oauth==1.2.4
22
requests_oauthlib>=1.3.1
3-
requests>=2.31.0
4-
simplejson>=3.19.1
3+
requests>=2.31.0

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def read(*parts):
3434
'intuit-oauth==1.2.5',
3535
'requests_oauthlib>=1.3.1',
3636
'requests>=2.31.0',
37-
'simplejson>=3.19.1',
3837
'python-dateutil',
3938
],
4039

0 commit comments

Comments
 (0)