changeset 1878:bee1c0747242

switch from cyclone.httpclient to treq everywhere Ignore-this: 60dbd235b745a1198b14c90be9d4abe2
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 27 May 2019 10:46:29 +0000
parents d01e21621975
children cb8222319cb8
files light9/curvecalc/curveedit.py light9/effect/edit.py light9/effecteval/effectloop.py light9/greplin_cyclone.py light9/networking.py light9/subcomposer/subcomposerweb.py light9/vidref/musictime.py
diffstat 7 files changed, 50 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/light9/curvecalc/curveedit.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/curvecalc/curveedit.py	Mon May 27 10:46:29 2019 +0000
@@ -2,11 +2,13 @@
 this may be split out from curvecalc someday, since it doesn't
 need to be tied to a gui """
 import cgi
-from twisted.internet import reactor
-import cyclone.web, cyclone.httpclient, cyclone.websocket
+
+from louie import dispatcher
 from rdflib import URIRef
+from twisted.internet import reactor
+import cyclone.web
+
 from cycloneerr import PrettyErrorHandler
-from louie import dispatcher
 
 
 def serveCurveEdit(port, hoverTimeResponse, curveset):
--- a/light9/effect/edit.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/effect/edit.py	Mon May 27 10:46:29 2019 +0000
@@ -1,12 +1,11 @@
-import json
-import cyclone.httpclient
+from rdflib import URIRef, Literal
 from twisted.internet.defer import inlineCallbacks, returnValue
-from rdflib import URIRef, Literal
+import treq
 
 from light9 import networking
+from light9.curvecalc.curve import CurveResource
 from light9.namespaces import L9, RDF, RDFS
 from rdfdb.patch import Patch
-from light9.curvecalc.curve import CurveResource
 
 
 def clamp(x, lo, hi):
@@ -15,10 +14,9 @@
 
 @inlineCallbacks
 def getMusicStatus():
-    returnValue(
-        json.loads(
-            (yield cyclone.httpclient.fetch(networking.musicPlayer.path('time'),
-                                            timeout=.5)).body))
+    resp = yield treq.get(networking.musicPlayer.path('time'), timeout=.5)
+    body = yield resp.json_content()
+    returnValue(body)
 
 
 @inlineCallbacks
--- a/light9/effecteval/effectloop.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/effecteval/effectloop.py	Mon May 27 10:46:29 2019 +0000
@@ -1,17 +1,20 @@
-import time, json, logging, traceback
-import numpy
-import serial
+import time, logging, traceback
+
+from rdflib import URIRef
 from twisted.internet import reactor
 from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twisted.internet.error import TimeoutError
-from rdflib import URIRef
-import cyclone.httpclient
-from light9.namespaces import L9, RDF
-from light9.effecteval.effect import EffectNode
+import numpy
+import serial
+import treq
+
 from light9 import Effects
-from light9 import networking
 from light9 import Submaster
 from light9 import dmxclient
+from light9 import networking
+from light9.effecteval.effect import EffectNode
+from light9.namespaces import L9, RDF
+
 log = logging.getLogger('effectloop')
 
 
@@ -66,8 +69,8 @@
         old = now - self.requestTime
         if old > self.coastSecs:
             try:
-                response = json.loads((yield cyclone.httpclient.fetch(
-                    networking.musicPlayer.path('time'), timeout=.5)).body)
+                r = yield treq.get(networking.musicPlayer.path('time'), timeout=.5)
+                response = yield r.json_content()
             except TimeoutError:
                 log.warning("TimeoutError: using stale time from %.1f ago", old)
             else:
--- a/light9/greplin_cyclone.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/greplin_cyclone.py	Mon May 27 10:46:29 2019 +0000
@@ -1,4 +1,4 @@
-import cyclone.web, cyclone.websocket, cyclone.httpclient
+import cyclone.web
 
 import greplin.scales.twistedweb, greplin.scales.formats
 from greplin import scales
--- a/light9/networking.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/networking.py	Mon May 27 10:46:29 2019 +0000
@@ -1,5 +1,7 @@
+from urllib.parse import urlparse
+
 from rdflib import URIRef
-from urllib.parse import urlparse
+
 from .showconfig import getGraph, showUri
 from .namespaces import L9
 
@@ -33,8 +35,8 @@
 
     value = url
 
-    def path(self, more):
-        return self.url + str(more)
+    def path(self, more: str) -> URIRef:
+        return URIRef(self.url + more)
 
 
 captureDevice = ServiceAddress(L9['captureDevice'])
--- a/light9/subcomposer/subcomposerweb.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/subcomposer/subcomposerweb.py	Mon May 27 10:46:29 2019 +0000
@@ -1,9 +1,12 @@
 import logging
-import cyclone.web, cyclone.websocket, cyclone.httpclient
+
+from rdflib import URIRef, Literal
+from twisted.internet import reactor
+import cyclone.web
+
 from cycloneerr import PrettyErrorHandler
 from light9 import networking
-from rdflib import URIRef, Literal
-from twisted.internet import reactor
+
 log = logging.getLogger('web')
 
 
--- a/light9/vidref/musictime.py	Mon May 27 07:41:09 2019 +0000
+++ b/light9/vidref/musictime.py	Mon May 27 10:46:29 2019 +0000
@@ -1,8 +1,11 @@
 import time, json, logging
-from light9 import networking
+from typing import Dict
+
 from twisted.internet import reactor
-from cyclone.httpclient import fetch
-from typing import Dict
+import treq
+
+from light9 import networking
+
 log = logging.getLogger()
 
 
@@ -80,7 +83,7 @@
             log.warn("talking to ascoltami: %s", err.getErrorMessage())
             reactor.callLater(2, self.pollMusicTime)
 
-        d = fetch(networking.musicPlayer.path("time"))
+        d = treq.get(networking.musicPlayer.path("time").toPython())
         d.addCallback(cb)
         d.addErrback(eb)  # note this includes errors in cb()
 
@@ -117,17 +120,16 @@
             self.lastHoverTime = None
             reactor.callLater(2, self.pollCurvecalcTime)
 
-        d = fetch(networking.curveCalc.path("hoverTime"))
+        d = treq.get(networking.curveCalc.path("hoverTime"))
         d.addCallback(cb)
         d.addErrback(eb)  # note this includes errors in cb()
 
     def sendTime(self, t):
         """request that the player go to this time"""
-        fetch(
-            method=b'POST',
-            url=networking.musicPlayer.path('time'),
-            postdata=json.dumps({
-                "t": t
-            }).encode('utf8'),
-            headers={b"content-type": [b"application/json"]},
+        treq.post(networking.musicPlayer.path('time'),
+                  data=json.dumps({
+                      "t": time
+                  }).encode('utf8'),
+                  headers={b"content-type": [b"application/json"]},
         )
+