diff service/reasoning/actions.py @ 756:f3f667769aef

python 3! and some types and cleanups Ignore-this: 3453a547ee745fa83668f36956c835cd
author drewp@bigasterisk.com
date Fri, 14 Feb 2020 00:07:23 -0800
parents e157afd642b5
children 3c18b4b3b72c
line wrap: on
line diff
--- a/service/reasoning/actions.py	Thu Feb 13 23:00:06 2020 -0800
+++ b/service/reasoning/actions.py	Fri Feb 14 00:07:23 2020 -0800
@@ -7,6 +7,7 @@
 import treq
 
 from httpputoutputs import HttpPutOutputs
+from inputgraph import InputGraph
 
 log = logging.getLogger('output')
 
@@ -28,7 +29,7 @@
 
 
 class Actions(object):
-    def __init__(self, inputGraph, sendToLiveClients, mockOutput=False):
+    def __init__(self, inputGraph: InputGraph, sendToLiveClients, mockOutput=False):
         self.inputGraph = inputGraph
         self.mockOutput = mockOutput
         self.putOutputs = HttpPutOutputs(mockOutput=mockOutput)
@@ -68,7 +69,7 @@
             if putUrl and matchPred == stmt[1]:
                 log.debug('putDevices: stmt %s leads to putting at %s',
                           ntStatement(stmt), putUrl.n3())
-                self._put(putUrl + '?' + urllib.urlencode([
+                self._put(putUrl + '?' + urllib.parse.urlencode([
                     ('s', str(stmt[0])),
                     ('p', str(putPred))]),
                           str(stmt[2].toPython()),
@@ -146,6 +147,8 @@
                                        default=Literal('30s'))#.map(secsFromLiteral)
 
     def _put(self, url, payload, refreshSecs, agent=None):
+        if isinstance(payload, str):
+            payload = payload.encode('utf8')
         assert isinstance(payload, bytes)
         self.putOutputs.put(url, payload, agent, refreshSecs)