Mercurial > code > home > repos > homeauto
diff service/reasoning/httpputoutputs.py @ 1556:d36d3b9ae516
python 3! and some types and cleanups
Ignore-this: 3453a547ee745fa83668f36956c835cd
darcs-hash:d9bd8e8a584681078c5de1b6e06c894995400f1f
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Fri, 14 Feb 2020 00:07:23 -0800 |
parents | ff7339ac8191 |
children | 3c18b4b3b72c |
line wrap: on
line diff
--- a/service/reasoning/httpputoutputs.py Thu Feb 13 23:00:06 2020 -0800 +++ b/service/reasoning/httpputoutputs.py Fri Feb 14 00:07:23 2020 -0800 @@ -1,24 +1,31 @@ import logging import time +from rdflib import URIRef from rx.subjects import BehaviorSubject from twisted.internet import reactor +from twisted.python.failure import Failure +from twisted.internet.interfaces import IDelayedCall import treq +from typing import Optional log = logging.getLogger('httpputoutputs') + class HttpPutOutput(object): - def __init__(self, url, - refreshSecs,#: BehaviorSubject, + lastChangeTime: float + + def __init__(self, url: str, + refreshSecs: BehaviorSubject, mockOutput=False): self.url = url self.mockOutput = mockOutput - self.payload = None - self.foafAgent = None - self.nextCall = None - self.lastErr = None - self.numRequests = 0 - self.refreshSecs = refreshSecs + self.payload: Optional[str] = None + self.foafAgent: Optional[URIRef] = None + self.nextCall: IDelayedCall = None + self.lastErr: Optional[Failure] = None + self.numRequests: int = 0 + self.refreshSecs: float = refreshSecs def report(self): return { @@ -33,7 +40,7 @@ 'lastErr': str(self.lastErr) if self.lastErr is not None else None, } - def setPayload(self, payload, foafAgent): + def setPayload(self, payload: str, foafAgent: URIRef): if self.numRequests > 0 and (self.payload == payload and self.foafAgent == foafAgent): return @@ -101,6 +108,7 @@ self.nextCall = reactor.callLater(self.currentRefreshSecs(), self.makeRequest) + class HttpPutOutputs(object): """these grow forever""" def __init__(self, mockOutput=False): @@ -108,6 +116,7 @@ self.state = {} # url: HttpPutOutput def put(self, url, payload, foafAgent, refreshSecs): + assert isinstance(url, str) if url not in self.state: self.state[url] = HttpPutOutput(url, mockOutput=self.mockOutput, refreshSecs=refreshSecs)