Skip to content

Commit 8863bcb

Browse files
committed
Renamed internal "json" module to "streamingjson" to avoid conflicts with the standard python module
Fixes #18
1 parent dbb90d3 commit 8863bcb

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

bridge/mailbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from tcp import TCPJSONServer
2929
from collections import deque
30-
import json
30+
import streamingjson
3131

3232
json_server = TCPJSONServer('127.0.0.1', 5700)
3333

@@ -115,7 +115,7 @@ def run(self, data):
115115
class SEND_JSON_Command:
116116
def run(self, data):
117117
try:
118-
obj, i = json.read(data)
118+
obj, i = streamingjson.read(data)
119119
mailbox.send(obj)
120120
except:
121121
mailbox.send(data)

bridge/json.py renamed to bridge/streamingjson.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
## Copyright (C) 2005 Patrick D. Logan
66
## Contact mailto:[email protected]
77
##
8+
## streamingjson.py adds support for streaming.
9+
## Copyright (C) 2014 Arduino
10+
##
811
## This library is free software; you can redistribute it and/or
912
## modify it under the terms of the GNU Lesser General Public
1013
## License as published by the Free Software Foundation; either
@@ -38,7 +41,7 @@ def next(self):
3841
raise StopIteration
3942
def all(self):
4043
return self.string
41-
44+
4245
def pos(self):
4346
return self.index
4447

@@ -65,7 +68,7 @@ def _read(self):
6568
if peek == '{':
6669
return self._readObject()
6770
elif peek == '[':
68-
return self._readArray()
71+
return self._readArray()
6972
elif peek == '"':
7073
return self._readString()
7174
elif peek == '-' or peek.isdigit():
@@ -248,7 +251,7 @@ def _next(self):
248251
return self._generator.next()
249252

250253
class JsonWriter(object):
251-
254+
252255
def _append(self, s):
253256
self._results.append(s)
254257

bridge/tcp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from socket import socket, AF_INET, SOCK_STREAM, SOL_SOCKET, SO_REUSEADDR, gethostname
2929
from select import select
3030
from collections import deque
31-
import json
31+
import streamingjson
3232
import utils
3333

3434

@@ -57,7 +57,7 @@ def close(self):
5757

5858
class TCPJSONSender(TCPClient):
5959
def send(self, obj):
60-
data = json.write(obj)
60+
data = streamingjson.write(obj)
6161
TCPClient.send(self, data)
6262

6363
class TCPJSONClient(TCPJSONSender):
@@ -70,7 +70,7 @@ def recv(self):
7070
# try to stream-decode received data
7171
try:
7272
if len(self.recvbuff) > 0:
73-
res, i = json.read(self.recvbuff)
73+
res, i = streamingjson.read(self.recvbuff)
7474
self.recvbuff = self.recvbuff[i:].lstrip()
7575
return res
7676
except:
@@ -162,7 +162,7 @@ def recv(self, data):
162162
# try to stream-decode received data
163163
try:
164164
while len(data) > 0:
165-
res, i = json.read(data)
165+
res, i = streamingjson.read(data)
166166
self.recv_queue.append(res)
167167
data = data[i:].lstrip()
168168
except:
@@ -180,7 +180,7 @@ def read(self):
180180
return None
181181

182182
def write(self, obj):
183-
data = json.write(obj)
183+
data = streamingjson.write(obj)
184184
self.send(data)
185185

186186
# Test

0 commit comments

Comments
 (0)