changeset 55:54664942cc61

str/bytes type fixes Ignore-this: 7e33fb057b748685ba980a537635f62e
author Drew Perttula <drewp@bigasterisk.com>
date Thu, 30 May 2019 08:17:11 +0000
parents a47c135b58b8
children 7293dbfe54a4
files rdfdb/patch.py rdfdb/patchreceiver.py rdfdb/service.py
diffstat 3 files changed, 15 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rdfdb/patch.py	Thu May 30 08:15:58 2019 +0000
+++ b/rdfdb/patch.py	Thu May 30 08:17:11 2019 +0000
@@ -42,6 +42,7 @@
 
         4th element of a quad must be a URIRef
         """
+        assert jsonRepr is None or isinstance(jsonRepr, str), repr(jsonRepr)
         self._jsonRepr = jsonRepr
         self._addQuads, self._delQuads = addQuads, delQuads
         self._addGraph, self._delGraph = addGraph, delGraph
@@ -138,7 +139,9 @@
         if '[<' in d['patch']['adds']:
             raise ValueError("[< found in %s" % d['patch']['adds'])
         d.update(extraAttrs)
-        return json.dumps(d)
+        s = json.dumps(d)
+        assert isinstance(s, str), repr(s)
+        return s
 
     def simplify(self):
         adds = set(self.addQuads)
--- a/rdfdb/patchreceiver.py	Thu May 30 08:15:58 2019 +0000
+++ b/rdfdb/patchreceiver.py	Thu May 30 08:17:11 2019 +0000
@@ -56,9 +56,10 @@
 
 def makePatchEndpointPutMethod(cb):
 
-    def put(self):
+    def put(self) -> None:
+        assert isinstance(self, cyclone.web.RequestHandler)
         try:
-            p = Patch(jsonRepr=self.request.body)
+            p = Patch(jsonRepr=self.request.body.decode('utf8'))
             log.debug("received patch -%d +%d" %
                       (len(p.delGraph), len(p.addGraph)))
             cb(p)
--- a/rdfdb/service.py	Thu May 30 08:15:58 2019 +0000
+++ b/rdfdb/service.py	Thu May 30 08:17:11 2019 +0000
@@ -1,5 +1,5 @@
-import sys, optparse, logging, json, os, time
-from typing import Dict, List, Set, Optional, Union
+import sys, optparse, logging, json, os, time, itertools
+from typing import Callable, Dict, List, Set, Optional, Union
 
 from greplin.scales.cyclonehandler import StatsHandler
 from greplin import scales
@@ -71,7 +71,7 @@
 
 class WsClient(object):
 
-    def __init__(self, connectionId: str, sendMessage):
+    def __init__(self, connectionId: str, sendMessage: Callable[[str], None]):
         self.updateUri = URIRef(connectionId)
         self.sendMessage = sendMessage
 
@@ -429,12 +429,13 @@
 
 
 liveClients: Set[Live] = set()
-stats.websocketClients = len(liveClients)
+stats.liveClients = len(liveClients)
 
-def sendToLiveClients(d=None, asJson=None):
-    j = asJson or json.dumps(d)
+def sendToLiveClients(d: Optional[Dict]=None, asJson: Optional[str]=None):
+    msg: str = asJson or json.dumps(d)
+    assert isinstance(msg, str), repr(msg)
     for c in liveClients:
-        c.sendMessage(j)
+        c.sendMessage(msg)
 
 
 class NoExts(cyclone.web.StaticFileHandler):