mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
pylightning: remove 0.6.2 JSON compat wedge.
The next commit breaks it: `if b' }\n' not in buff:` is always true since we're about to clean up our JSON so there won't be a space. I could have hacked the space in our JSON, but 6 months is long enough anyway. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
bb7bbd03c5
commit
adc4bf1817
@ -46,6 +46,7 @@ changes.
|
||||
### Removed
|
||||
|
||||
- JSON RPC: `global_features` and `local_features` fields and `listchannels`' `flags` field. (Deprecated since 0.6.2).
|
||||
- pylightning: Remove RPC support for c-lightning before 0.6.3.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
@ -4,7 +4,7 @@ import logging
|
||||
from math import floor, log10
|
||||
import socket
|
||||
|
||||
__version__ = "0.0.7.2"
|
||||
__version__ = "0.0.7.3"
|
||||
|
||||
|
||||
class RpcError(ValueError):
|
||||
@ -165,40 +165,12 @@ class UnixDomainSocketRpc(object):
|
||||
self.executor = executor
|
||||
self.logger = logger
|
||||
|
||||
# Do we require the compatibility mode?
|
||||
self._compat = True
|
||||
self.next_id = 0
|
||||
|
||||
def _writeobj(self, sock, obj):
|
||||
s = json.dumps(obj, cls=self.encoder_cls)
|
||||
sock.sendall(bytearray(s, 'UTF-8'))
|
||||
|
||||
def _readobj_compat(self, sock, buff=b''):
|
||||
if not self._compat:
|
||||
return self._readobj(sock, buff)
|
||||
while True:
|
||||
try:
|
||||
b = sock.recv(max(1024, len(buff)))
|
||||
buff += b
|
||||
|
||||
if b'\n\n' in buff:
|
||||
# The next read will use the non-compatible read instead
|
||||
self._compat = False
|
||||
|
||||
if len(b) == 0:
|
||||
return {'error': 'Connection to RPC server lost.'}
|
||||
if b' }\n' not in buff:
|
||||
continue
|
||||
# Convert late to UTF-8 so glyphs split across recvs do not
|
||||
# impact us
|
||||
buff = buff.decode("UTF-8")
|
||||
objs, len_used = self.decoder.raw_decode(buff)
|
||||
buff = buff[len_used:].lstrip().encode("UTF-8")
|
||||
return objs, buff
|
||||
except ValueError:
|
||||
# Probably didn't read enough
|
||||
buff = buff.lstrip().encode("UTF-8")
|
||||
|
||||
def _readobj(self, sock, buff=b''):
|
||||
"""Read a JSON object, starting with buff; returns object and any buffer left over"""
|
||||
while True:
|
||||
@ -249,7 +221,7 @@ class UnixDomainSocketRpc(object):
|
||||
"id": self.next_id,
|
||||
})
|
||||
self.next_id += 1
|
||||
resp, _ = self._readobj_compat(sock)
|
||||
resp, _ = self._readobj(sock)
|
||||
sock.close()
|
||||
|
||||
self.logger.debug("Received response for %s call: %r", method, resp)
|
||||
|
Loading…
Reference in New Issue
Block a user