# HG changeset patch # User Drew Perttula # Date 2019-05-27 10:46:29 # Node ID bee1c0747242c3c4280bc474cb177580b7002705 # Parent d01e21621975ae6fe90a27db78f8466059768de1 switch from cyclone.httpclient to treq everywhere Ignore-this: 60dbd235b745a1198b14c90be9d4abe2 diff --git a/light9/curvecalc/curveedit.py b/light9/curvecalc/curveedit.py --- a/light9/curvecalc/curveedit.py +++ b/light9/curvecalc/curveedit.py @@ -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): diff --git a/light9/effect/edit.py b/light9/effect/edit.py --- a/light9/effect/edit.py +++ b/light9/effect/edit.py @@ -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 @@ def clamp(x, lo, hi): @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 diff --git a/light9/effecteval/effectloop.py b/light9/effecteval/effectloop.py --- a/light9/effecteval/effectloop.py +++ b/light9/effecteval/effectloop.py @@ -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 @@ class EffectLoop(object): 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: diff --git a/light9/greplin_cyclone.py b/light9/greplin_cyclone.py --- a/light9/greplin_cyclone.py +++ b/light9/greplin_cyclone.py @@ -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 diff --git a/light9/networking.py b/light9/networking.py --- a/light9/networking.py +++ b/light9/networking.py @@ -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 @@ class ServiceAddress(object): 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']) diff --git a/light9/subcomposer/subcomposerweb.py b/light9/subcomposer/subcomposerweb.py --- a/light9/subcomposer/subcomposerweb.py +++ b/light9/subcomposer/subcomposerweb.py @@ -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') diff --git a/light9/vidref/musictime.py b/light9/vidref/musictime.py --- a/light9/vidref/musictime.py +++ b/light9/vidref/musictime.py @@ -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 @@ class MusicTime(object): 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 @@ class MusicTime(object): 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"]}, ) +