Created
October 7, 2015 23:30
-
-
Save davebshow/539cd4c838934a7d2375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuid | |
from tornado.concurrent import Future | |
from tornado.websocket import websocket_connect | |
class GremlinResponseStream: | |
def __init__(self, conn): | |
self._conn = conn | |
@asyncio.coroutine | |
def read(self): | |
pass | |
@asyncio.coroutine | |
def submit(gremlin, *, | |
url='http://localhost:8182/', | |
bindings=None, | |
lang="gremlin-groovy", | |
rebindings=None, | |
op="eval", | |
processor="", | |
timeout=None, | |
session=None, | |
loop=None, | |
username="", | |
password=""): | |
message = { | |
"requestId": str(uuid.uuid4()), | |
"op": op, | |
"processor": processor, | |
"args": { | |
"gremlin": gremlin, | |
"bindings": bindings, | |
"language": lang, | |
"rebindings": rebindings | |
} | |
} | |
future = Future() | |
future_conn = websocket_connect(url) | |
def send_message(conn): | |
conn.write_message(message, callback=lambda: future.set_result(conn)) | |
future_conn.add_done_callback(send_message) | |
return future |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment