Skip to content

Commit

Permalink
ujson import fixed
Browse files Browse the repository at this point in the history
not sure how to get ciso8601 to work #122
  • Loading branch information
liampauling committed Sep 7, 2017
1 parent 7904acb commit ec28625
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
12 changes: 12 additions & 0 deletions betfairlightweight/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import datetime


_ver = sys.version_info
Expand All @@ -25,3 +26,14 @@ class FileNotFoundError(OSError):
basestring = (str, bytes)
numeric_types = (int, float)
integer_types = (int,)

try:
import ujson as json
except ImportError:
import json

try: # todo
import ciso8601
parse_datetime = ciso8601.parse_datetime_unaware
except ImportError:
parse_datetime = datetime.datetime.strptime(None, "%Y-%m-%dT%H:%M:%S.%fZ")
2 changes: 1 addition & 1 deletion betfairlightweight/endpoints/baseendpoint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import requests
import datetime
import ujson as json
from requests import ConnectionError

from ..exceptions import APIError
from ..utils import check_status_code
from ..compat import json

# monkeypatching requests
# https://github.com/kennethreitz/requests/issues/1595
Expand Down
2 changes: 0 additions & 2 deletions betfairlightweight/endpoints/scores.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from .baseendpoint import BaseEndpoint
from .. import resources
from ..utils import clean_locals
Expand Down
2 changes: 1 addition & 1 deletion betfairlightweight/resources/baseresource.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import datetime
import ciso8601
import ujson as json

from ..compat import (
basestring,
integer_types,
json,
)


Expand Down
6 changes: 4 additions & 2 deletions betfairlightweight/streaming/betfairstream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ujson as json
import threading
import socket
import ssl
Expand All @@ -9,7 +8,10 @@
SocketError,
ListenerError,
)
from ..compat import is_py3
from ..compat import (
is_py3,
json,
)


class BetfairStream(object):
Expand Down
2 changes: 1 addition & 1 deletion betfairlightweight/streaming/listener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json
import json # ujson causes issues
import logging

from .stream import (
Expand Down

0 comments on commit ec28625

Please sign in to comment.