Mercurial > code > home > repos > rdfdb
changeset 40:195779114472
str/bytes fixes
Ignore-this: 593bc7bc1a1aa999a8dea48369471862
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sun, 26 May 2019 19:29:59 +0000 |
parents | 83fc83e919e5 |
children | 3ee7386327c2 |
files | rdfdb/patch.py rdfdb/service.py |
diffstat | 2 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/rdfdb/patch.py Sun May 26 00:36:32 2019 +0000 +++ b/rdfdb/patch.py Sun May 26 19:29:59 2019 +0000 @@ -1,5 +1,6 @@ import json, unittest from rdflib import ConjunctiveGraph, Graph, URIRef, URIRef as U, Literal, Namespace +from typing import Optional XSD = Namespace("http://www.w3.org/2001/XMLSchema#") @@ -27,7 +28,8 @@ the json representation includes the {"patch":...} wrapper """ - def __init__(self, jsonRepr=None, addQuads=None, delQuads=None, + def __init__(self, jsonRepr: Optional[str]=None, + addQuads=None, delQuads=None, addGraph=None, delGraph=None): """ addQuads/delQuads can be lists or sets, but if we make them internally, @@ -110,12 +112,12 @@ return self._delGraph @property - def jsonRepr(self) -> bytes: + def jsonRepr(self) -> str: if self._jsonRepr is None: self._jsonRepr = self.makeJsonRepr() return self._jsonRepr - def makeJsonRepr(self, extraAttrs={}) -> bytes: + def makeJsonRepr(self, extraAttrs={}) -> str: d = {"patch" : { 'adds' : serializeQuad(self.addGraph), 'deletes' : serializeQuad(self.delGraph), @@ -126,7 +128,7 @@ if '[<' in d['patch']['adds']: raise ValueError("[< found in %s" % d['patch']['adds']) d.update(extraAttrs) - return json.dumps(d).encode('utf8') + return json.dumps(d) def simplify(self): adds = set(self.addQuads)
--- a/rdfdb/service.py Sun May 26 00:36:32 2019 +0000 +++ b/rdfdb/service.py Sun May 26 19:29:59 2019 +0000 @@ -53,7 +53,7 @@ return sendPatch(self.updateUri, p) class WsClient(object): - def __init__(self, connectionId, sendMessage): + def __init__(self, connectionId: bytes, sendMessage): self.updateUri = connectionId self.sendMessage = sendMessage @@ -325,7 +325,7 @@ wsClient: Optional[WsClient] = None def connectionMade(self, *args, **kwargs): global _wsClientSerial - connectionId = 'connection-%s' % _wsClientSerial + connectionId = ('connection-%s' % _wsClientSerial).encode('utf8') _wsClientSerial += 1 self.wsClient = WsClient(connectionId, self.sendMessage) @@ -337,12 +337,12 @@ self.settings.db.clientErrored( Failure(WebsocketDisconnect(reason)), self.wsClient) - def messageReceived(self, message): - if message == 'PING': + def messageReceived(self, message: bytes): + if message == b'PING': self.sendMessage('PONG') return log.info("got message from %r: %s", self.wsClient, message) - p = Patch(jsonRepr=message) + p = Patch(jsonRepr=message.decode('utf8')) p.senderUpdateUri = self.wsClient.updateUri self.settings.db.patch(p)