Commit 6ede0d09 authored by davebshow's avatar davebshow
Browse files

added rebindings, test agains GA

parent 8180e4ca
# [aiogremlin 0.0.11](https://pypi.python.org/pypi/aiogremlin/0.0.11)
# [aiogremlin 0.0.12](https://pypi.python.org/pypi/aiogremlin/0.0.11)
## [Official Documentation](http://aiogremlin.readthedocs.org/en/latest/)
......
......@@ -4,4 +4,4 @@ from .exceptions import *
from .connector import *
from .subprotocol import *
__version__ = "0.0.11"
__version__ = "0.0.12"
......@@ -104,7 +104,7 @@ class GremlinClient:
self._connector = None
@asyncio.coroutine
def submit(self, gremlin, *, bindings=None, lang=None,
def submit(self, gremlin, *, bindings=None, lang=None, rebindings=None,
op=None, processor=None, binary=True, session=None,
timeout=None):
"""
......@@ -116,6 +116,8 @@ class GremlinClient:
:param dict bindings: A mapping of bindings for Gremlin script.
:param str lang: Language of scripts submitted to the server.
"gremlin-groovy" by default
:param dict rebindings: Rebind ``Graph`` and ``TraversalSource``
objects to different variable names in the current request
:param str op: Gremlin Server op argument. "eval" by default.
:param str processor: Gremlin Server processor argument. "" by default.
:param float timeout: timeout for establishing connection (optional).
......@@ -139,15 +141,17 @@ class GremlinClient:
writer = GremlinWriter(ws)
ws = writer.write(gremlin, bindings=bindings, lang=lang, op=op,
ws = writer.write(gremlin, bindings=bindings, lang=lang,
rebindings=rebindings, op=op,
processor=processor, binary=binary,
session=session)
return GremlinResponse(ws, session=session, loop=self._loop)
@asyncio.coroutine
def execute(self, gremlin, *, bindings=None, lang=None, session=None,
op=None, processor=None, binary=True, timeout=None):
def execute(self, gremlin, *, bindings=None, lang=None, rebindings=None,
session=None, op=None, processor=None, binary=True,
timeout=None):
"""
:ref:`coroutine<coroutine>` method.
......@@ -172,9 +176,9 @@ class GremlinClient:
op = op or self.op
processor = processor or self.processor
resp = yield from self.submit(gremlin, bindings=bindings, lang=lang,
op=op, processor=processor,
binary=binary, session=session,
timeout=timeout)
rebindings=rebindings, op=op,
processor=processor, binary=binary,
session=session, timeout=timeout)
return (yield from resp.get())
......
......@@ -6,7 +6,7 @@ __all__ = ("RequestError", "GremlinServerError")
class StatusException(IOError):
def __init__(self, value, result):
"""Handle all exceptions returned from the Gremlin Server as per:
"""Handle all exceptions returned from the Gremlin Server.
"""
self.value = value
self.response = {
......
......@@ -46,16 +46,18 @@ class GremlinWriter:
def __init__(self, ws):
self.ws = ws
def write(self, gremlin, bindings=None, lang="gremlin-groovy", op="eval",
processor="", session=None, binary=True,
mime_type="application/json"):
message = self._prepare_message(
gremlin,
bindings=bindings,
lang=lang,
op=op,
processor=processor,
session=session)
def write(self, gremlin, bindings=None, lang="gremlin-groovy",
rebindings=None, op="eval", processor="", session=None,
binary=True, mime_type="application/json"):
if rebindings is None:
rebindings = {}
message = self._prepare_message(gremlin,
bindings,
lang,
rebindings,
op,
processor,
session)
message = json.dumps(message)
if binary:
message = self._set_message_header(message, mime_type)
......@@ -72,8 +74,8 @@ class GremlinWriter:
return b"".join([mime_len, mime_type, bytes(message, "utf-8")])
@staticmethod
def _prepare_message(gremlin, bindings=None, lang="gremlin-groovy",
op="eval", processor="", session=None):
def _prepare_message(gremlin, bindings, lang, rebindings, op, processor,
session):
message = {
"requestId": str(uuid.uuid4()),
"op": op,
......@@ -81,7 +83,8 @@ class GremlinWriter:
"args": {
"gremlin": gremlin,
"bindings": bindings,
"language": lang
"language": lang,
"rebindings": rebindings
}
}
if session is None:
......
......@@ -79,7 +79,7 @@ ARGS.add_argument(
help='message count (default: `%(default)s`)')
ARGS.add_argument(
'-c', '--concurrency', action="store",
nargs='?', type=int, default=8,
nargs='?', type=int, default=16,
help='count of parallel requests (default: `%(default)s`)')
ARGS.add_argument(
'-p', '--poolsize', action="store",
......
......@@ -12,14 +12,14 @@ based on the `asyncio`_ and `aiohttp`_ libraries.
Releases
========
The latest release of :py:mod:`aiogremlin` is **0.0.11**.
The latest release of :py:mod:`aiogremlin` is **0.0.12**.
Requirements
============
- Python 3.4
- Tinkerpop 3 Gremlin Server 3.0.0.M9
- Tinkerpop 3 Gremlin Server 3.0.0
Dependencies
......
......@@ -3,7 +3,7 @@ from setuptools import setup
setup(
name="aiogremlin",
version="0.0.11",
version="0.0.12",
url="",
license="MIT",
author="davebshow",
......
......@@ -96,6 +96,24 @@ class GremlinClientTest(unittest.TestCase):
error = True
self.assertTrue(error)
def test_rebinding(self):
execute = self.gc.execute("graph2.addVertex()")
try:
self.loop.run_until_complete(execute)
error = False
except:
error = True
self.assertTrue(error)
@asyncio.coroutine
def go():
result = yield from self.gc.execute(
"graph2.addVertex()", rebindings={"graph2": "graph"})
self.assertEqual(len(result), 1)
self.loop.run_until_complete(go())
class GremlinClientSessionTest(unittest.TestCase):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment