changeset 48:7c3cd440619b

switch to treq http client Ignore-this: fde2ba73c2d74ed372a1f0be8771c5a
author Drew Perttula <drewp@bigasterisk.com>
date Mon, 27 May 2019 10:47:44 +0000
parents 9bd2a537caaa
children 101e0e455e8f
files rdfdb/patchreceiver.py rdfdb/patchsender.py rdfdb/service.py rdfdb/syncedgraph.py
diffstat 4 files changed, 26 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/rdfdb/patchreceiver.py	Mon May 27 08:54:23 2019 +0000
+++ b/rdfdb/patchreceiver.py	Mon May 27 10:47:44 2019 +0000
@@ -1,7 +1,11 @@
 import logging, traceback, urllib.request, urllib.parse, urllib.error
-import cyclone.web, cyclone.httpclient
+
 from twisted.internet import reactor
+import cyclone.web
+import treq
+
 from rdfdb.patch import Patch
+
 log = logging.getLogger('syncedgraph')
 
 
@@ -34,15 +38,12 @@
         url = (self.rdfdbRoot + 'graphClients').encode('utf8')
         body = urllib.parse.urlencode([(b'clientUpdate', self.updateResource),
                                        (b'label', label)]).encode('utf8')
-        cyclone.httpclient.fetch(
-            url=url,
-            method=b'POST',
-            headers={
-                b'Content-Type': [b'application/x-www-form-urlencoded']
-            },
-            postdata=body,
-        ).addCallbacks(
-            self._done, lambda err: self._registerError(err, url, body))
+        treq.post(url, data=body, headers={
+            b'Content-Type': [b'application/x-www-form-urlencoded']
+        }).addCallbacks(
+            self._done,
+            lambda err: self._registerError(err, url, body)
+        )
         log.info("registering with rdfdb at %s", url)
 
     def _registerError(self, err, url, body):
--- a/rdfdb/patchsender.py	Mon May 27 08:54:23 2019 +0000
+++ b/rdfdb/patchsender.py	Mon May 27 10:47:44 2019 +0000
@@ -1,8 +1,10 @@
 import logging, time
 from typing import List, Tuple, Optional
-import treq
+
 from rdflib import URIRef
 from twisted.internet import defer
+import treq
+
 from rdfdb.patch import Patch
 
 log = logging.getLogger('syncedgraph')
--- a/rdfdb/service.py	Mon May 27 08:54:23 2019 +0000
+++ b/rdfdb/service.py	Mon May 27 10:47:44 2019 +0000
@@ -5,7 +5,7 @@
 from twisted.internet.inotify import IN_CREATE, INotify
 from twisted.python.failure import Failure
 from twisted.python.filepath import FilePath
-import cyclone.web, cyclone.httpclient, cyclone.websocket
+import cyclone.web, cyclone.websocket
 from rdflib import ConjunctiveGraph, URIRef, Graph
 import twisted.internet.error
 
--- a/rdfdb/syncedgraph.py	Mon May 27 08:54:23 2019 +0000
+++ b/rdfdb/syncedgraph.py	Mon May 27 10:47:44 2019 +0000
@@ -16,26 +16,28 @@
 PatchSender - collects and transmits your graph edits
 """
 
+import json, logging, traceback
+from typing import Optional
+
 from rdflib import ConjunctiveGraph, URIRef
-import logging, cyclone.httpclient, traceback
 from twisted.internet import defer
 import socket
-import treq, json
-log = logging.getLogger('syncedgraph')
-from rdfdb.rdflibpatch import patchQuads
-from typing import Optional
+import treq
 
-from rdfdb.patchsender import PatchSender
-from rdfdb.patchreceiver import PatchReceiver
+from rdfdb.autodepgraphapi import AutoDepGraphApi
 from rdfdb.currentstategraphapi import CurrentStateGraphApi
-from rdfdb.autodepgraphapi import AutoDepGraphApi
 from rdfdb.grapheditapi import GraphEditApi
 from rdfdb.patch import Patch
+from rdfdb.patchreceiver import PatchReceiver
+from rdfdb.patchsender import PatchSender
+from rdfdb.rdflibpatch import patchQuads
 
 # everybody who writes literals needs to get this
 from rdfdb.rdflibpatch_literal import patch
 patch()
 
+log = logging.getLogger('syncedgraph')
+
 
 class SyncedGraph(CurrentStateGraphApi, AutoDepGraphApi, GraphEditApi):
     """
@@ -99,9 +101,7 @@
         log.info('resync')
         self._sender.cancelAll()
         # this should be locked so only one resync goes on at once
-        return cyclone.httpclient.fetch(
-            url=self.rdfdbRoot + "graph",
-            method=b"GET",
+        return treq.get(self.rdfdbRoot.toPython() + "graph",
             headers={
                 b'Accept': [b'x-trig']
             },