changeset 39:83fc83e919e5

more type errors. Ignore-this: 96fb564723d0661eb687d483f1640b62
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 26 May 2019 00:36:32 +0000
parents b3ae192c05e4
children 195779114472
files rdfdb/patch.py rdfdb/patchsender.py rdfdb/service.py
diffstat 3 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rdfdb/patch.py	Sat May 25 23:55:15 2019 +0000
+++ b/rdfdb/patch.py	Sun May 26 00:36:32 2019 +0000
@@ -110,12 +110,12 @@
         return self._delGraph
 
     @property
-    def jsonRepr(self):
+    def jsonRepr(self) -> bytes:
         if self._jsonRepr is None:
             self._jsonRepr = self.makeJsonRepr()
         return self._jsonRepr
 
-    def makeJsonRepr(self, extraAttrs={}):
+    def makeJsonRepr(self, extraAttrs={}) -> bytes:
         d = {"patch" : {
             'adds' : serializeQuad(self.addGraph),
             'deletes' : serializeQuad(self.delGraph),
@@ -126,7 +126,7 @@
         if '[<' in d['patch']['adds']:
             raise ValueError("[< found in %s" % d['patch']['adds'])
         d.update(extraAttrs)
-        return json.dumps(d)
+        return json.dumps(d).encode('utf8')
 
     def simplify(self):
         adds = set(self.addQuads)
--- a/rdfdb/patchsender.py	Sat May 25 23:55:15 2019 +0000
+++ b/rdfdb/patchsender.py	Sun May 26 00:36:32 2019 +0000
@@ -3,6 +3,7 @@
 import cyclone.httpclient
 from twisted.internet import defer
 from rdfdb.patch import Patch
+
 log = logging.getLogger('syncedgraph')
 
 class PatchSender(object):
@@ -92,7 +93,7 @@
         log.error(e)
         self._continueSending()
 
-def sendPatch(putUri, patch, **kw):
+def sendPatch(putUri, patch, **kw) -> defer.Deferred:
     """
     PUT a patch as json to an http server. Returns deferred.
     
@@ -101,7 +102,7 @@
     t1 = time.time()
     body = patch.makeJsonRepr(kw)
     jsonTime = time.time() - t1
-    intro = body[:200]
+    intro = body[:200].decode('utf8')
     if len(body) > 200:
         intro = intro + "..."
     log.debug("send body (rendered %.1fkB in %.1fms): %s", len(body) / 1024, jsonTime * 1000, intro)
--- a/rdfdb/service.py	Sat May 25 23:55:15 2019 +0000
+++ b/rdfdb/service.py	Sun May 26 00:36:32 2019 +0000
@@ -5,7 +5,7 @@
 from twisted.internet.inotify import IN_CREATE
 import sys, optparse, logging, json, os
 import cyclone.web, cyclone.httpclient, cyclone.websocket
-from typing import Dict, List, Set
+from typing import Dict, List, Set, Optional
 
 from rdflib import ConjunctiveGraph, URIRef, Graph
 from rdfdb.graphfile import GraphFile
@@ -96,13 +96,13 @@
 
     def dirChange(self, watch, path, mask):
         if mask & IN_CREATE:
-            if path.path.endswith(('~', '.swp', 'swx', '.rdfdb-temp')):
+            if path.path.endswith((b'~', b'.swp', b'swx', b'.rdfdb-temp')):
                 return
                 
             log.debug("%s created; consider adding a watch", path)
             self.watchFile(path.path)
             
-    def watchFile(self, inFile):
+    def watchFile(self, inFile: bytes):
         """
         consider adding a GraphFile to self.graphFiles
 
@@ -322,6 +322,7 @@
 _wsClientSerial = 0
 class WebsocketClient(cyclone.websocket.WebSocketHandler):
 
+    wsClient: Optional[WsClient] = None
     def connectionMade(self, *args, **kwargs):
         global _wsClientSerial
         connectionId = 'connection-%s' % _wsClientSerial