tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davebs...@apache.org
Subject [02/12] tinkerpop git commit: allow user to pass graphson reader/writer
Date Tue, 28 Feb 2017 15:48:28 GMT
allow user to pass graphson reader/writer


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d2a50d8c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d2a50d8c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d2a50d8c

Branch: refs/heads/tp32
Commit: d2a50d8c9fad756a1481fd176b842f67f097e3aa
Parents: 3a14da2
Author: davebshow <davebshow@gmail.com>
Authored: Wed Feb 15 16:27:46 2017 -0500
Committer: davebshow <davebshow@gmail.com>
Committed: Tue Feb 28 10:30:48 2017 -0500

----------------------------------------------------------------------
 .../main/jython/gremlin_python/driver/client.py |  6 +-
 .../driver/driver_remote_connection.py          | 20 +++--
 .../jython/gremlin_python/driver/protocol.py    |  9 +-
 .../jython/gremlin_python/driver/serializer.py  | 86 ++++++++++----------
 .../src/main/jython/tests/conftest.py           |  2 +
 5 files changed, 70 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d2a50d8c/gremlin-python/src/main/jython/gremlin_python/driver/client.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/client.py b/gremlin-python/src/main/jython/gremlin_python/driver/client.py
index fcbdf07..0314a44 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/client.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/client.py
@@ -23,7 +23,7 @@ from concurrent.futures import ThreadPoolExecutor
 
 from six.moves import queue
 
-from gremlin_python.driver import connection, protocol, request
+from gremlin_python.driver import connection, protocol, request, serializer
 from gremlin_python.process import traversal
 
 # This is until concurrent.futures backport 3.1.0 release
@@ -44,6 +44,8 @@ class Client:
                  message_serializer=None, username="", password=""):
         self._url = url
         self._traversal_source = traversal_source
+        if message_serializer is None:
+            message_serializer = serializer.GraphSONMessageSerializer()
         self._message_serializer = message_serializer
         self._username = username
         self._password = password
@@ -59,7 +61,7 @@ class Client:
         self._transport_factory = transport_factory
         if protocol_factory is None:
             protocol_factory = lambda: protocol.GremlinServerWSProtocol(
-                message_serializer=self._message_serializer,
+                self._message_serializer,
                 username=self._username,
                 password=self._password)
         self._protocol_factory = protocol_factory

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d2a50d8c/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
index fb0e4ba..1f08e2b 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/driver_remote_connection.py
@@ -18,7 +18,7 @@ under the License.
 """
 from concurrent.futures import Future
 
-from gremlin_python.driver import client
+from gremlin_python.driver import client, serializer
 from gremlin_python.driver.remote_connection import (
     RemoteConnection, RemoteTraversal, RemoteTraversalSideEffects)
 
@@ -29,10 +29,20 @@ class DriverRemoteConnection(RemoteConnection):
 
     def __init__(self, url, traversal_source, protocol_factory=None,
                  transport_factory=None, pool_size=None, max_workers=None,
-                 username="", password=""):
-        self._client = client.Client(url, traversal_source, protocol_factory,
-                                     transport_factory, pool_size, max_workers,
-                                     None, username, password)
+                 username="", password="", message_serializer=None,
+                 graphson_reader=None, graphson_writer=None):
+        if message_serializer is None:
+            message_serializer = serializer.GraphSONMessageSerializer(
+                reader=graphson_reader,
+                writer=graphson_writer)
+        self._client = client.Client(url, traversal_source,
+                                     protocol_factory=protocol_factory,
+                                     transport_factory=transport_factory,
+                                     pool_size=pool_size,
+                                     max_workers=max_workers,
+                                     message_serializer=message_serializer,
+                                     username=username,
+                                     password=password)
         self._url = self._client._url
         self._traversal_source = self._client._traversal_source
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d2a50d8c/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py b/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py
index 279a8f5..33b4419 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/protocol.py
@@ -19,10 +19,13 @@ under the License.
 import abc
 import base64
 import collections
-import json
 import uuid
 
 import six
+try:
+    import ujson as json
+except ImportError:
+    import json
 
 from gremlin_python.driver import serializer, request
 
@@ -51,9 +54,7 @@ class AbstractBaseProtocol:
 
 class GremlinServerWSProtocol(AbstractBaseProtocol):
 
-    def __init__(self, message_serializer=None, username='', password=''):
-        if message_serializer is None:
-            message_serializer = serializer.GraphSONMessageSerializer()
+    def __init__(self, message_serializer, username='', password=''):
         self._message_serializer = message_serializer
         self._username = username
         self._password = password

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d2a50d8c/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py b/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
index 2db7374..a29d4dc 100644
--- a/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
+++ b/gremlin-python/src/main/jython/gremlin_python/driver/serializer.py
@@ -29,72 +29,74 @@ __author__ = 'David M. Brown (davebshow@gmail.com)'
 class Processor:
     """Base class for OpProcessor serialization system."""
 
-    _graphson_writer = graphson.GraphSONWriter()
-
-    def __init__(self, default_args):
-        self._default_args = default_args
+    def __init__(self, writer):
+        self._graphson_writer = writer
 
     def get_op_args(self, op, args):
         op_method = getattr(self, op, None)
         if not op_method:
             raise Exception("Processor does not support op: {}".format(op))
-        args_ = self._default_args.get(op, dict()).copy()
-        args_.update(args)
-        return op_method(args_)
-
+        return op_method(args)
 
-class GraphSONMessageSerializer:
-    """Message serializer for GraphSON"""
 
-    _graphson_reader = graphson.GraphSONReader()
+class Standard(Processor):
 
+    def authentication(self, args):
+        return args
 
-    class standard(Processor):
+    def eval(self, args):
+        return args
 
-        def authentication(self, args):
-            return args
 
-        def eval(self, args):
-            return args
+class Traversal(Processor):
 
+    def authentication(self, args):
+        return args
 
-    class traversal(Processor):
+    def bytecode(self, args):
+        gremlin = args['gremlin']
+        args['gremlin'] = self._graphson_writer.toDict(gremlin)
+        aliases = args.get('aliases', '')
+        if not aliases:
+            aliases = {'g': 'g'}
+        args['aliases'] = aliases
+        return args
 
-        def authentication(self, args):
-            return args
+    def close(self, args):
+        return self.keys(args)
 
-        def bytecode(self, args):
-            gremlin = args['gremlin']
-            args['gremlin'] = self._graphson_writer.toDict(gremlin)
-            aliases = args.get('aliases', '')
-            if not aliases:
-                aliases = {'g': 'g'}
-            args['aliases'] = aliases
-            return args
+    def gather(self, args):
+        side_effect = args['sideEffect']
+        args['sideEffect'] = {'@type': 'g:UUID', '@value': side_effect}
+        aliases = args.get('aliases', '')
+        if not aliases:
+            aliases = {'g': 'g'}
+        args['aliases'] = aliases
+        return args
 
-        def close(self, args):
-            return self.keys(args)
+    def keys(self, args):
+        side_effect = args['sideEffect']
+        args['sideEffect'] = {'@type': 'g:UUID', '@value': side_effect}
+        return args
 
-        def gather(self, args):
-            side_effect = args['sideEffect']
-            args['sideEffect'] = {'@type': 'g:UUID', '@value': side_effect}
-            aliases = args.get('aliases', '')
-            if not aliases:
-                aliases = {'g': 'g'}
-            args['aliases'] = aliases
-            return args
 
-        def keys(self, args):
-            side_effect = args['sideEffect']
-            args['sideEffect'] = {'@type': 'g:UUID', '@value': side_effect}
-            return args
+class GraphSONMessageSerializer:
+    """Message serializer for GraphSON"""
 
+    def __init__(self, reader=None, writer=None):
+        if not reader:
+            reader = graphson.GraphSONReader()
+        self._graphson_reader = reader
+        if not writer:
+            writer = graphson.GraphSONWriter()
+        self.standard = Standard(writer)
+        self.traversal = Traversal(writer)
 
     def get_processor(self, processor):
         processor = getattr(self, processor, None)
         if not processor:
             raise Exception("Unknown processor")
-        return processor({})
+        return processor
 
     def serialize_message(self, request_id, request_message):
         processor = request_message.processor

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d2a50d8c/gremlin-python/src/main/jython/tests/conftest.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/conftest.py b/gremlin-python/src/main/jython/tests/conftest.py
index 3425266..2cd4282 100644
--- a/gremlin-python/src/main/jython/tests/conftest.py
+++ b/gremlin-python/src/main/jython/tests/conftest.py
@@ -26,12 +26,14 @@ from gremlin_python.driver.connection import Connection
 from gremlin_python.driver.driver_remote_connection import (
     DriverRemoteConnection)
 from gremlin_python.driver.protocol import GremlinServerWSProtocol
+from gremlin_python.driver.serializer import GraphSONMessageSerializer
 from gremlin_python.driver.tornado.transport import TornadoTransport
 
 
 @pytest.fixture
 def connection(request):
     protocol = GremlinServerWSProtocol(
+        GraphSONMessageSerializer(),
         username='stephen', password='password')
     executor = concurrent.futures.ThreadPoolExecutor(5)
     pool = queue.Queue()


Mime
View raw message