You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/10/12 20:53:28 UTC

[01/10] tinkerpop git commit: gremlinpython: more simplification of graphson routines

Repository: tinkerpop
Updated Branches:
  refs/heads/master ce41db1d2 -> e70a509a3


gremlinpython: more simplification of graphson routines


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

Branch: refs/heads/master
Commit: 697e24f1c1eba594fa238483e15854e5a148502f
Parents: 6931f12
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Fri Sep 23 15:04:04 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 15:30:43 2016 -0500

----------------------------------------------------------------------
 .../gremlin_python/structure/io/graphson.py     | 63 ++++++++------------
 1 file changed, 24 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/697e24f1/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 4676539..2f81827 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -92,28 +92,22 @@ class GraphSONSerializer(object):
 
 
 class BytecodeSerializer(GraphSONSerializer):
+    def _dictify_instructions(self, instructions):
+        out = []
+        for instruction in instructions:
+            inst = [instruction[0]]
+            inst.extend(GraphSONWriter._dictify(arg) for arg in instruction[1:])
+            out.append(inst)
+        return out
+
     def _dictify(self, bytecode):
         if isinstance(bytecode, Traversal):
             bytecode = bytecode.bytecode
         out = {}
-        sources = []
-        for instruction in bytecode.source_instructions:
-            inst = []
-            inst.append(instruction[0])
-            for arg in instruction[1:]:
-                inst.append(GraphSONWriter._dictify(arg))
-            sources.append(inst)
-        steps = []
-        for instruction in bytecode.step_instructions:
-            inst = []
-            inst.append(instruction[0])
-            for arg in instruction[1:]:
-                inst.append(GraphSONWriter._dictify(arg))
-            steps.append(inst)
-        if len(sources) > 0:
-            out["source"] = sources
-        if len(steps) > 0:
-            out["step"] = steps
+        if bytecode.source_instructions:
+            out["source"] = self._dictify_instructions(bytecode.source_instructions)
+        if bytecode.step_instructions:
+            out["step"] = self._dictify_instructions(bytecode.step_instructions)
         return _SymbolHelper.objectify("Bytecode", out)
 
 
@@ -136,31 +130,26 @@ class EnumSerializer(GraphSONSerializer):
 
 class PSerializer(GraphSONSerializer):
     def _dictify(self, p):
-        out = {}
-        out["predicate"] = p.operator
-        if p.other is None:
-            out["value"] = GraphSONWriter._dictify(p.value)
-        else:
-            out["value"] = [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)]
+        out = {"predicate": p.operator,
+               "value": [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)] if p.other is not None else
+                        GraphSONWriter._dictify(p.value)}
         return _SymbolHelper.objectify("P", out)
 
 
 class BindingSerializer(GraphSONSerializer):
     def _dictify(self, binding):
-        out = {}
-        out["key"] = binding.key
-        out["value"] = GraphSONWriter._dictify(binding.value)
+        out = {"key": binding.key,
+               "value": GraphSONWriter._dictify(binding.value)}
         return _SymbolHelper.objectify("Binding", out)
 
 
 class LambdaSerializer(GraphSONSerializer):
     def _dictify(self, lambda_object):
         lambda_result = lambda_object()
-        out = {}
         script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
         language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
-        out["script"] = script
-        out["language"] = language
+        out = {"script": script,
+               "language": language}
         if language == "gremlin-jython" or language == "gremlin-python":
             if not script.strip().startswith("lambda"):
                 script = "lambda " + script
@@ -223,7 +212,7 @@ class NumberDeserializer(GraphSONDeserializer):
 class VertexDeserializer(GraphSONDeserializer):
     def _objectify(self, d):
         value = d[_SymbolHelper._VALUE]
-        return Vertex(GraphSONReader._objectify(value["id"]), value["label"] if "label" in value else "")
+        return Vertex(GraphSONReader._objectify(value["id"]), value.get("label", ""))
 
 
 class EdgeDeserializer(GraphSONDeserializer):
@@ -231,7 +220,7 @@ class EdgeDeserializer(GraphSONDeserializer):
         value = d[_SymbolHelper._VALUE]
         return Edge(GraphSONReader._objectify(value["id"]),
                     Vertex(GraphSONReader._objectify(value["outV"]), ""),
-                    value["label"] if "label" in value else "vertex",
+                    value.get("label", "vertex"),
                     Vertex(GraphSONReader._objectify(value["inV"]), ""))
 
 
@@ -251,12 +240,8 @@ class PropertyDeserializer(GraphSONDeserializer):
 class PathDeserializer(GraphSONDeserializer):
     def _objectify(self, d):
         value = d[_SymbolHelper._VALUE]
-        labels = []
-        objects = []
-        for label in value["labels"]:
-            labels.append(set(label))
-        for object in value["objects"]:
-            objects.append(GraphSONReader._objectify(object))
+        labels = [set(label) for label in value["labels"]]
+        objects = [GraphSONReader._objectify(o) for o in value["objects"]]
         return Path(labels, objects)
 
 
@@ -270,7 +255,7 @@ class _SymbolHelper(object):
 
     @staticmethod
     def toGremlin(symbol):
-        return _SymbolHelper.symbolMap[symbol] if symbol in _SymbolHelper.symbolMap else symbol
+        return _SymbolHelper.symbolMap.get(symbol, symbol)
 
     @staticmethod
     def objectify(type, value=None, prefix="g"):


[09/10] tinkerpop git commit: Merge branch 'python-glv-graphson-update' of https://github.com/aholmberg/tinkerpop

Posted by ok...@apache.org.
Merge branch 'python-glv-graphson-update' of https://github.com/aholmberg/tinkerpop


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

Branch: refs/heads/master
Commit: c5b088310c617d037b9af6e95d6be064f07133af
Parents: ce41db1 0e211d6
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 12 14:02:48 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 12 14:02:48 2016 -0600

----------------------------------------------------------------------
 .../driver/driver_remote_connection.py          |  16 +-
 .../gremlin_python/structure/io/graphson.py     | 518 ++++++++++---------
 .../driver/test_driver_remote_connection.py     |   4 +-
 .../jython/tests/structure/io/test_graphson.py  | 104 +++-
 .../python/jsr223/JythonScriptEngineSetup.java  |   5 +-
 .../jsr223/PythonGraphSONJavaTranslator.java    |   2 +-
 .../io/graphson/GraphSONReaderTest.java         |  68 +--
 .../io/graphson/GraphSONWriterTest.java         |  56 +-
 8 files changed, 427 insertions(+), 346 deletions(-)
----------------------------------------------------------------------



[08/10] tinkerpop git commit: Split GraphSONIO into reader writer

Posted by ok...@apache.org.
Split GraphSONIO into reader writer

not an ideal design by itself, but follows the Java API precedence, which has
other requirements


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

Branch: refs/heads/master
Commit: 0e211d6b763df2ee6260759c91b57b57770fc02b
Parents: d296eb7
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Tue Oct 11 14:15:07 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Tue Oct 11 14:15:07 2016 -0500

----------------------------------------------------------------------
 .../driver/driver_remote_connection.py          |  17 +-
 .../gremlin_python/structure/io/graphson.py     | 154 +++++++++----------
 .../jython/tests/structure/io/test_graphson.py  | 113 ++++++++------
 .../python/jsr223/JythonScriptEngineSetup.java  |   5 +-
 .../jsr223/PythonGraphSONJavaTranslator.java    |   2 +-
 .../io/graphson/GraphSONReaderTest.java         |  68 ++++----
 .../io/graphson/GraphSONWriterTest.java         |  54 +++----
 7 files changed, 219 insertions(+), 194 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/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 20129e9..eab06f1 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
@@ -23,7 +23,7 @@ from tornado import gen
 from tornado import ioloop
 from tornado import websocket
 
-from gremlin_python.structure.io.graphson import GraphSONIO
+from gremlin_python.structure.io.graphson import GraphSONReader, GraphSONWriter
 from .remote_connection import RemoteConnection
 from .remote_connection import RemoteTraversal
 from .remote_connection import RemoteTraversalSideEffects
@@ -34,14 +34,15 @@ class GremlinServerError(Exception):
 
 
 class DriverRemoteConnection(RemoteConnection):
-    def __init__(self, url, traversal_source, username="", password="", loop=None, graphson_io=None):
+    def __init__(self, url, traversal_source, username="", password="", loop=None, graphson_reader=None, graphson_writer=None):
         super(DriverRemoteConnection, self).__init__(url, traversal_source)
         self._url = url
         self._username = username
         self._password = password
         if loop is None: self._loop = ioloop.IOLoop.current()
         self._websocket = self._loop.run_sync(lambda: websocket.websocket_connect(self.url))
-        self._graphson_io = graphson_io or GraphSONIO()
+        self._graphson_reader = graphson_reader or GraphSONReader()
+        self._graphson_writer = graphson_writer or GraphSONWriter()
 
     def submit(self, bytecode):
         '''
@@ -65,7 +66,7 @@ class DriverRemoteConnection(RemoteConnection):
             "op": "bytecode",
             "processor": "traversal",
             "args": {
-                "gremlin": self._graphson_io.writeObject(bytecode),
+                "gremlin": self._graphson_writer.writeObject(bytecode),
                 "aliases": {"g": self.traversal_source}
             }
         }
@@ -142,7 +143,7 @@ class DriverRemoteConnection(RemoteConnection):
         if self._websocket.protocol is None:
             self._websocket = yield websocket.websocket_connect(self.url)
         self._websocket.write_message(send_message, binary=True)
-        response = Response(self._websocket, self._username, self._password, self._graphson_io)
+        response = Response(self._websocket, self._username, self._password, self._graphson_reader)
         results = None
         while True:
             recv_message = yield response.receive()
@@ -183,12 +184,12 @@ class DriverRemoteConnection(RemoteConnection):
 
 
 class Response:
-    def __init__(self, websocket, username, password, graphson_io):
+    def __init__(self, websocket, username, password, graphson_reader):
         self._websocket = websocket
         self._username = username
         self._password = password
         self._closed = False
-        self._graphson_io = graphson_io
+        self._graphson_reader = graphson_reader
 
     @gen.coroutine
     def receive(self):
@@ -225,7 +226,7 @@ class Response:
         elif status_code in [200, 206]:
             results = []
             for item in recv_message["result"]["data"]:
-                results.append(self._graphson_io.toObject(item))
+                results.append(self._graphson_reader.toObject(item))
             if status_code == 200:
                 self._closed = True
             raise gen.Return((aggregateTo, results))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 50db7cb..45aec9d 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -16,24 +16,14 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 '''
-import json
 from aenum import Enum
-
+import json
 import six
 
 from gremlin_python import statics
 from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType
-from gremlin_python.process.traversal import Binding
-from gremlin_python.process.traversal import Bytecode
-from gremlin_python.process.traversal import P
-from gremlin_python.process.traversal import Traversal
-from gremlin_python.process.traversal import Traverser
-from gremlin_python.process.traversal import TraversalStrategy
-from gremlin_python.structure.graph import Edge
-from gremlin_python.structure.graph import Property
-from gremlin_python.structure.graph import Vertex
-from gremlin_python.structure.graph import VertexProperty
-from gremlin_python.structure.graph import Path
+from gremlin_python.process.traversal import Binding, Bytecode, P, Traversal, Traverser, TraversalStrategy
+from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path
 
 
 _serializers = {}
@@ -51,32 +41,33 @@ class GraphSONTypeType(type):
         return cls
 
 
-class GraphSONIO(object):
+class _GraphSONIO(object):
+    TYPE_KEY = "@type"
+    VALUE_KEY = "@value"
+
+    @classmethod
+    def typedValue(cls, type_name, value, prefix="g"):
+        out = {cls.TYPE_KEY: prefix + ":" + type_name}
+        if value is not None:
+            out[cls.VALUE_KEY] = value
+        return out
 
-    _TYPE_KEY = "@type"
-    _VALUE_KEY = "@value"
 
-    def __init__(self, serializer_map=None, deserializer_map=None):
+# Read/Write classes split to follow precedence of the Java API
+class GraphSONWriter(object):
+
+    def __init__(self, serializer_map=None):
         """
         :param serializer_map: map from Python type to serializer instance implementing `dictify`
-        :param deserializer_map: map from GraphSON type tag to deserializer instance implementing `objectify`
         """
         self.serializers = _serializers.copy()
         if serializer_map:
             self.serializers.update(serializer_map)
 
-        self.deserializers = _deserializers.copy()
-        if deserializer_map:
-            self.deserializers.update(deserializer_map)
-
     def writeObject(self, objectData):
         # to JSON
         return json.dumps(self.toDict(objectData), separators=(',', ':'))
 
-    def readObject(self, jsonData):
-        # from JSON
-        return self.toObject(json.loads(jsonData))
-
     def toDict(self, obj):
         """
         Encodes python objects in GraphSON type-tagged dict values
@@ -92,13 +83,28 @@ class GraphSONIO(object):
         else:
             return obj
 
+
+class GraphSONReader(object):
+
+    def __init__(self, deserializer_map=None):
+        """
+        :param deserializer_map: map from GraphSON type tag to deserializer instance implementing `objectify`
+        """
+        self.deserializers = _deserializers.copy()
+        if deserializer_map:
+            self.deserializers.update(deserializer_map)
+
+    def readObject(self, jsonData):
+        # from JSON
+        return self.toObject(json.loads(jsonData))
+
     def toObject(self, obj):
         """
         Unpacks GraphSON type-tagged dict values into objects mapped in self.deserializers
         """
         if isinstance(obj, dict):
             try:
-                return self.deserializers[obj[self._TYPE_KEY]].objectify(obj[self._VALUE_KEY], self)
+                return self.deserializers[obj[_GraphSONIO.TYPE_KEY]].objectify(obj[_GraphSONIO.VALUE_KEY], self)
             except KeyError:
                 pass
             # list and map are treated as normal json objs (could be isolated deserializers)
@@ -108,12 +114,6 @@ class GraphSONIO(object):
         else:
             return obj
 
-    def typedValue(self, type_name, value, prefix="g"):
-        out = {self._TYPE_KEY: prefix + ":" + type_name}
-        if value is not None:
-            out[self._VALUE_KEY] = value
-        return out
-
 
 @six.add_metaclass(GraphSONTypeType)
 class _GraphSONTypeIO(object):
@@ -128,34 +128,34 @@ class _GraphSONTypeIO(object):
     def unmangleKeyword(cls, symbol):
         return cls.symbolMap.get(symbol, symbol)
 
-    def dictify(self, obj, graphson_io):
+    def dictify(self, obj, writer):
         raise NotImplementedError()
 
-    def objectify(self, d, graphson_io):
+    def objectify(self, d, reader):
         raise NotImplementedError()
 
 
 class _BytecodeSerializer(_GraphSONTypeIO):
 
     @classmethod
-    def _dictify_instructions(cls, instructions, graphson_io):
+    def _dictify_instructions(cls, instructions, writer):
         out = []
         for instruction in instructions:
             inst = [instruction[0]]
-            inst.extend(graphson_io.toDict(arg) for arg in instruction[1:])
+            inst.extend(writer.toDict(arg) for arg in instruction[1:])
             out.append(inst)
         return out
 
     @classmethod
-    def dictify(cls, bytecode, graphson_io):
+    def dictify(cls, bytecode, writer):
         if isinstance(bytecode, Traversal):
             bytecode = bytecode.bytecode
         out = {}
         if bytecode.source_instructions:
-            out["source"] = cls._dictify_instructions(bytecode.source_instructions, graphson_io)
+            out["source"] = cls._dictify_instructions(bytecode.source_instructions, writer)
         if bytecode.step_instructions:
-            out["step"] = cls._dictify_instructions(bytecode.step_instructions, graphson_io)
-        return graphson_io.typedValue("Bytecode", out)
+            out["step"] = cls._dictify_instructions(bytecode.step_instructions, writer)
+        return _GraphSONIO.typedValue("Bytecode", out)
 
 
 class TraversalSerializer(_BytecodeSerializer):
@@ -170,8 +170,8 @@ class TraversalStrategySerializer(_GraphSONTypeIO):
     python_type = TraversalStrategy
 
     @classmethod
-    def dictify(cls, strategy, graphson_io):
-        return graphson_io.typedValue(strategy.strategy_name, graphson_io.toDict(strategy.configuration))
+    def dictify(cls, strategy, writer):
+        return _GraphSONIO.typedValue(strategy.strategy_name, writer.toDict(strategy.configuration))
 
 
 class TraverserIO(_GraphSONTypeIO):
@@ -179,22 +179,22 @@ class TraverserIO(_GraphSONTypeIO):
     graphson_type = "g:Traverser"
 
     @classmethod
-    def dictify(cls, traverser, graphson_io):
-        return graphson_io.typedValue("Traverser", {"value": graphson_io.toDict(traverser.object),
-                                                     "bulk": graphson_io.toDict(traverser.bulk)})
+    def dictify(cls, traverser, writer):
+        return _GraphSONIO.typedValue("Traverser", {"value": writer.toDict(traverser.object),
+                                                     "bulk": writer.toDict(traverser.bulk)})
 
     @classmethod
-    def objectify(cls, d, graphson_io):
-        return Traverser(graphson_io.toObject(d["value"]),
-                         graphson_io.toObject(d["bulk"]))
+    def objectify(cls, d, reader):
+        return Traverser(reader.toObject(d["value"]),
+                         reader.toObject(d["bulk"]))
 
 
 class EnumSerializer(_GraphSONTypeIO):
     python_type = Enum
 
     @classmethod
-    def dictify(cls, enum, graphson_io):
-        return graphson_io.typedValue(cls.unmangleKeyword(type(enum).__name__),
+    def dictify(cls, enum, _):
+        return _GraphSONIO.typedValue(cls.unmangleKeyword(type(enum).__name__),
                                       cls.unmangleKeyword(str(enum.name)))
 
 
@@ -202,28 +202,28 @@ class PSerializer(_GraphSONTypeIO):
     python_type = P
 
     @classmethod
-    def dictify(cls, p, graphson_io):
+    def dictify(cls, p, writer):
         out = {"predicate": p.operator,
-               "value": [graphson_io.toDict(p.value), graphson_io.toDict(p.other)] if p.other is not None else
-                        graphson_io.toDict(p.value)}
-        return graphson_io.typedValue("P", out)
+               "value": [writer.toDict(p.value), writer.toDict(p.other)] if p.other is not None else
+                        writer.toDict(p.value)}
+        return _GraphSONIO.typedValue("P", out)
 
 
 class BindingSerializer(_GraphSONTypeIO):
     python_type = Binding
 
     @classmethod
-    def dictify(cls, binding, graphson_io):
+    def dictify(cls, binding, writer):
         out = {"key": binding.key,
-               "value": graphson_io.toDict(binding.value)}
-        return graphson_io.typedValue("Binding", out)
+               "value": writer.toDict(binding.value)}
+        return _GraphSONIO.typedValue("Binding", out)
 
 
 class LambdaSerializer(_GraphSONTypeIO):
     python_type = FunctionType
 
     @classmethod
-    def dictify(cls, lambda_object, graphson_io):
+    def dictify(cls, lambda_object, writer):
         lambda_result = lambda_object()
         script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
         language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
@@ -236,24 +236,24 @@ class LambdaSerializer(_GraphSONTypeIO):
             out["arguments"] = six.get_function_code(eval(out["script"])).co_argcount
         else:
             out["arguments"] = -1
-        return graphson_io.typedValue("Lambda", out)
+        return _GraphSONIO.typedValue("Lambda", out)
 
 
 class TypeSerializer(_GraphSONTypeIO):
     python_type = TypeType
 
     @classmethod
-    def dictify(cls, typ, graphson_io):
-        return graphson_io.toDict(typ())
+    def dictify(cls, typ, writer):
+        return writer.toDict(typ())
 
 
 class _NumberIO(_GraphSONTypeIO):
 
     @classmethod
-    def dictify(cls, n, graphson_io):
+    def dictify(cls, n, writer):
         if isinstance(n, bool):  # because isinstance(False, int) and isinstance(True, int)
             return n
-        return graphson_io.typedValue(cls.graphson_base_type, n)
+        return _GraphSONIO.typedValue(cls.graphson_base_type, n)
 
     @classmethod
     def objectify(cls, v, _):
@@ -287,43 +287,43 @@ class VertexDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Vertex"
 
     @classmethod
-    def objectify(cls, d, graphson_io):
-        return Vertex(graphson_io.toObject(d["id"]), d.get("label", ""))
+    def objectify(cls, d, reader):
+        return Vertex(reader.toObject(d["id"]), d.get("label", ""))
 
 
 class EdgeDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Edge"
 
     @classmethod
-    def objectify(cls, d, graphson_io):
-        return Edge(graphson_io.toObject(d["id"]),
-                    Vertex(graphson_io.toObject(d["outV"]), ""),
+    def objectify(cls, d, reader):
+        return Edge(reader.toObject(d["id"]),
+                    Vertex(reader.toObject(d["outV"]), ""),
                     d.get("label", "vertex"),
-                    Vertex(graphson_io.toObject(d["inV"]), ""))
+                    Vertex(reader.toObject(d["inV"]), ""))
 
 
 class VertexPropertyDeserializer(_GraphSONTypeIO):
     graphson_type = "g:VertexProperty"
 
     @classmethod
-    def objectify(cls, d, graphson_io):
-        return VertexProperty(graphson_io.toObject(d["id"]), d["label"],
-                              graphson_io.toObject(d["value"]))
+    def objectify(cls, d, reader):
+        return VertexProperty(reader.toObject(d["id"]), d["label"],
+                              reader.toObject(d["value"]))
 
 
 class PropertyDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Property"
 
     @classmethod
-    def objectify(cls, d, graphson_io):
-        return Property(d["key"], graphson_io.toObject(d["value"]))
+    def objectify(cls, d, reader):
+        return Property(d["key"], reader.toObject(d["value"]))
 
 
 class PathDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Path"
 
     @classmethod
-    def objectify(cls, d, graphson_io):
+    def objectify(cls, d, reader):
         labels = [set(label) for label in d["labels"]]
-        objects = [graphson_io.toObject(o) for o in d["objects"]]
+        objects = [reader.toObject(o) for o in d["objects"]]
         return Path(labels, objects)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index 90866aa..a192cd2 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -29,39 +29,39 @@ import six
 from gremlin_python.statics import *
 from gremlin_python.structure.graph import Vertex
 from gremlin_python.structure.graph import Path
-from gremlin_python.structure.io.graphson import GraphSONIO
+from gremlin_python.structure.io.graphson import GraphSONWriter, GraphSONReader, _GraphSONIO
 import gremlin_python.structure.io.graphson
 from gremlin_python.process.traversal import P
 from gremlin_python.process.strategies import SubgraphStrategy
 from gremlin_python.process.graph_traversal import __
 
-graphson_io = GraphSONIO()
 
+class TestGraphSONReader(TestCase):
+    graphson_reader = GraphSONReader()
 
-class TestGraphSONIO(TestCase):
     def test_number_input(self):
-        x = graphson_io.readObject(json.dumps({
+        x = self.graphson_reader.readObject(json.dumps({
             "@type": "g:Int32",
             "@value": 31
         }))
         assert isinstance(x, int)
         assert 31 == x
         ##
-        x = graphson_io.readObject(json.dumps({
+        x = self.graphson_reader.readObject(json.dumps({
             "@type": "g:Int64",
             "@value": 31
         }))
         assert isinstance(x, long)
         assert long(31) == x
         ##
-        x = graphson_io.readObject(json.dumps({
+        x = self.graphson_reader.readObject(json.dumps({
             "@type": "g:Float",
             "@value": 31.3
         }))
         assert isinstance(x, float)
         assert 31.3 == x
         ##
-        x = graphson_io.readObject(json.dumps({
+        x = self.graphson_reader.readObject(json.dumps({
             "@type": "g:Double",
             "@value": 31.2
         }))
@@ -69,7 +69,7 @@ class TestGraphSONIO(TestCase):
         assert 31.2 == x
 
     def test_graph(self):
-        vertex = graphson_io.readObject(
+        vertex = self.graphson_reader.readObject(
             """{"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}""")
         assert isinstance(vertex, Vertex)
         assert "person" == vertex.label
@@ -78,7 +78,7 @@ class TestGraphSONIO(TestCase):
         assert vertex == Vertex(1)
 
     def test_path(self):
-        path = graphson_io.readObject(
+        path = self.graphson_reader.readObject(
             """{"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}"""
         )
         assert isinstance(path, Path)
@@ -91,28 +91,65 @@ class TestGraphSONIO(TestCase):
         assert "lop" == path[2]
         assert 3 == len(path)
 
+    def test_custom_mapping(self):
+
+        # extended mapping
+        class X(object):
+            pass
+
+        type_string = "test:Xtype"
+        override_string = "g:Int64"
+        serdes = Mock()
+
+        reader = GraphSONReader(deserializer_map={type_string: serdes})
+        assert type_string in reader.deserializers
+
+        # base dicts are not modified
+        assert type_string not in gremlin_python.structure.io.graphson._deserializers
+
+        x = X()
+        o = reader.toObject({_GraphSONIO.TYPE_KEY: type_string, _GraphSONIO.VALUE_KEY: x})
+        serdes.objectify.assert_called_once_with(x, reader)
+        assert o is serdes.objectify()
+
+        # overridden mapping
+        type_string = "g:Int64"
+        serdes = Mock()
+        reader = GraphSONReader(deserializer_map={type_string: serdes, override_string: serdes})
+        assert gremlin_python.structure.io.graphson._deserializers[type_string] is not reader.deserializers[type_string]
+
+        value = 3
+        o = reader.toObject({_GraphSONIO.TYPE_KEY: type_string, _GraphSONIO.VALUE_KEY: value})
+        serdes.objectify.assert_called_once_with(value, reader)
+        assert o is serdes.objectify()
+
+
+class TestGraphSONWriter(TestCase):
+
+    graphson_writer = GraphSONWriter()
+
     def test_number_output(self):
-        assert {"@type":"g:Int64","@value":2} == json.loads(graphson_io.writeObject(long(2)))
-        assert {"@type":"g:Int32","@value":1} == json.loads(graphson_io.writeObject(1))
-        assert {"@type":"g:Double","@value":3.2} == json.loads(graphson_io.writeObject(3.2))
-        assert """true""" == graphson_io.writeObject(True)
+        assert {"@type":"g:Int64","@value":2} == json.loads(self.graphson_writer.writeObject(long(2)))
+        assert {"@type":"g:Int32","@value":1} == json.loads(self.graphson_writer.writeObject(1))
+        assert {"@type":"g:Double","@value":3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+        assert """true""" == self.graphson_writer.writeObject(True)
 
     def test_numbers(self):
-        assert {"@type": "g:Int64", "@value": 2} == json.loads(graphson_io.writeObject(long(2)))
-        assert {"@type": "g:Int32", "@value": 1} == json.loads(graphson_io.writeObject(1))
-        assert {"@type": "g:Double", "@value": 3.2} == json.loads(graphson_io.writeObject(3.2))
-        assert """true""" == graphson_io.writeObject(True)
+        assert {"@type": "g:Int64", "@value": 2} == json.loads(self.graphson_writer.writeObject(long(2)))
+        assert {"@type": "g:Int32", "@value": 1} == json.loads(self.graphson_writer.writeObject(1))
+        assert {"@type": "g:Double", "@value": 3.2} == json.loads(self.graphson_writer.writeObject(3.2))
+        assert """true""" == self.graphson_writer.writeObject(True)
 
     def test_P(self):
-        assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == graphson_io.writeObject(
+        assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == self.graphson_writer.writeObject(
             P.lt("b").or_(P.gt("c")).and_(P.neq("d")))
 
     def test_strategies(self):
         # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
-        assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(graphson_io.writeObject(SubgraphStrategy))
+        assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(self.graphson_writer.writeObject(SubgraphStrategy))
         assert {"@type": "g:SubgraphStrategy", "@value": {
             "vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
-            graphson_io.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
+            self.graphson_writer.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
 
     def test_custom_mapping(self):
 
@@ -120,42 +157,28 @@ class TestGraphSONIO(TestCase):
         class X(object):
             pass
 
-        type_string = "test:Xtype"
-        override_string = "g:Int64"
         serdes = Mock()
-
-        gio = GraphSONIO(serializer_map={X: serdes}, deserializer_map={type_string: serdes, })
-        self.assertIn(X, gio.serializers)
-        self.assertIn(type_string, gio.deserializers)
+        writer = GraphSONWriter(serializer_map={X: serdes})
+        assert X in writer.serializers
 
         # base dicts are not modified
-        self.assertNotIn(X, gremlin_python.structure.io.graphson._serializers)
-        self.assertNotIn(type_string, gremlin_python.structure.io.graphson._deserializers)
+        assert X not in gremlin_python.structure.io.graphson._serializers
 
         obj = X()
-        d = gio.toDict(obj)
-        serdes.dictify.assert_called_once_with(obj, gio)
-        self.assertIs(d, serdes.dictify())
-
-        o = gio.toObject({GraphSONIO._TYPE_KEY: type_string, GraphSONIO._VALUE_KEY: obj})
-        serdes.objectify.assert_called_once_with(obj, gio)
-        self.assertIs(o, serdes.objectify())
+        d = writer.toDict(obj)
+        serdes.dictify.assert_called_once_with(obj, writer)
+        assert d is serdes.dictify()
 
         # overridden mapping
-        type_string = "g:Int64"
         serdes = Mock()
-        gio = GraphSONIO(serializer_map={int: serdes}, deserializer_map={type_string: serdes, override_string: serdes})
-        self.assertIsNot(gremlin_python.structure.io.graphson._serializers[int], gio.serializers[int])
-        self.assertIsNot(gremlin_python.structure.io.graphson._deserializers[type_string], gio.deserializers[type_string])
+        writer = GraphSONWriter(serializer_map={int: serdes})
+        assert gremlin_python.structure.io.graphson._serializers[int] is not writer.serializers[int]
 
         value = 3
-        d = gio.toDict(value)
-        serdes.dictify.assert_called_once_with(value, gio)
-        self.assertIs(d, serdes.dictify())
+        d = writer.toDict(value)
+        serdes.dictify.assert_called_once_with(value, writer)
+        assert d is serdes.dictify()
 
-        o = gio.toObject({GraphSONIO._TYPE_KEY: type_string, GraphSONIO._VALUE_KEY: value})
-        serdes.objectify.assert_called_once_with(value, gio)
-        self.assertIs(o, serdes.objectify())
 
 if __name__ == '__main__':
     unittest.main()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
index d5305dc..a16ce30 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
@@ -49,8 +49,9 @@ public class JythonScriptEngineSetup {
             jythonEngine.eval("from gremlin_python.structure.graph import Edge");
             jythonEngine.eval("from gremlin_python.structure.graph import VertexProperty");
             jythonEngine.eval("from gremlin_python.structure.graph import Property");
-            jythonEngine.eval("from gremlin_python.structure.io.graphson import GraphSONIO");
-            jythonEngine.eval("graphson_io = GraphSONIO()");
+            jythonEngine.eval("from gremlin_python.structure.io.graphson import GraphSONReader, GraphSONWriter");
+            jythonEngine.eval("graphson_reader = GraphSONReader()");
+            jythonEngine.eval("graphson_writer = GraphSONWriter()");
             return jythonEngine;
         } catch (final ScriptException e) {
             throw new IllegalStateException(e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
index e57afd2..cdeb407 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
@@ -69,7 +69,7 @@ final class PythonGraphSONJavaTranslator<S extends TraversalSource, T extends Tr
             bindings.putAll(jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE));
             bindings.put(this.pythonTranslator.getTraversalSource(), jythonEngine.eval("Graph().traversal()"));
             bindings.putAll(bytecode.getBindings());
-            final String graphsonBytecode = jythonEngine.eval("graphson_io.writeObject(" + this.pythonTranslator.translate(bytecode) + ")", bindings).toString();
+            final String graphsonBytecode = jythonEngine.eval("graphson_writer.writeObject(" + this.pythonTranslator.translate(bytecode) + ")", bindings).toString();
             // System.out.println(graphsonBytecode);
             return this.javaTranslator.translate(this.reader.readObject(new ByteArrayInputStream(graphsonBytecode.getBytes()), Bytecode.class));
         } catch (final Exception e) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
index 7bbf364..86bdd21 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
@@ -60,49 +60,49 @@ public class GraphSONReaderTest {
     public void shouldDeserializeGraphObjects() throws Exception {
         final Vertex vertex = g.V(1).next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(vertex));
-        assertEquals(vertex.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Vertex)"));
+        assertEquals(vertex.toString(), jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),Vertex)"));
         //
         final Edge edge = g.V(1).outE("created").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(edge));
-        assertEquals(edge.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Edge)"));
+        assertEquals(edge.toString(), jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),Edge)"));
         //
         final VertexProperty vertexProperty = (VertexProperty) g.V(1).properties("name").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(vertexProperty));
-        assertEquals(vertexProperty.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),VertexProperty)"));
+        assertEquals(vertexProperty.toString(), jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),VertexProperty)"));
         //
         final Property property = g.V(1).outE("created").properties("weight").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(property));
-        assertEquals(property.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Property)"));
+        assertEquals(property.toString(), jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),Property)"));
         //
         final Traverser<Vertex> traverser = new DefaultRemoteTraverser<>(vertex, 3L);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(traverser));
-        assertEquals(traverser.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertEquals(BigInteger.valueOf(3L), jythonEngine.eval("graphson_io.readObject(x).bulk")); // jython uses big integer in Java
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x).object,Vertex)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Traverser)"));
+        assertEquals(traverser.toString(), jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertEquals(BigInteger.valueOf(3L), jythonEngine.eval("graphson_reader.readObject(x).bulk")); // jython uses big integer in Java
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x).object,Vertex)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),Traverser)"));
     }
 
     @Test
     public void shouldDeserializeNumbers() throws Exception {
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1));
-        assertEquals("1", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),int)"));
+        assertEquals("1", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),int)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1L));
-        assertEquals("1", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),long)"));
+        assertEquals("1", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),long)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1.2f));
-        assertEquals("1.2", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),float)"));
+        assertEquals("1.2", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),float)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1.3d));
-        assertEquals("1.3", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),float)"));
+        assertEquals("1.3", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x),float)"));
     }
 
     @Test
@@ -111,23 +111,23 @@ public class GraphSONReaderTest {
         map.put("a", 2);
         map.put("b", 2.3d);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(map));
-        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertEquals(2, jythonEngine.eval("graphson_io.readObject(x)['a']"));
-        assertEquals(2.3d, jythonEngine.eval("graphson_io.readObject(x)['b']")); // jython is smart about double
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)['a'],int)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)['b'],float)"));
+        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertEquals(2, jythonEngine.eval("graphson_reader.readObject(x)['a']"));
+        assertEquals(2.3d, jythonEngine.eval("graphson_reader.readObject(x)['b']")); // jython is smart about double
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)['a'],int)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)['b'],float)"));
         //
         final List<Object> list = Arrays.asList(g.V(1).next(), "hello", map, true);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(list));
-        assertEquals("[v[1], u'hello', {u'a': 2, u'b': 2.3}, True]", jythonEngine.eval("str(graphson_io.readObject(x))"));
-        assertEquals(g.V(1).next().toString(), jythonEngine.eval("str(graphson_io.readObject(x)[0])"));
-        assertEquals("hello", jythonEngine.eval("graphson_io.readObject(x)[1]"));
-        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_io.readObject(x)[2])"));
-        assertTrue((Boolean) jythonEngine.eval("graphson_io.readObject(x)[3]"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[0],Vertex)"));
-        // assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[1],str)")); // its python unicode jython object
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[2],dict)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[3],bool)"));
+        assertEquals("[v[1], u'hello', {u'a': 2, u'b': 2.3}, True]", jythonEngine.eval("str(graphson_reader.readObject(x))"));
+        assertEquals(g.V(1).next().toString(), jythonEngine.eval("str(graphson_reader.readObject(x)[0])"));
+        assertEquals("hello", jythonEngine.eval("graphson_reader.readObject(x)[1]"));
+        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_reader.readObject(x)[2])"));
+        assertTrue((Boolean) jythonEngine.eval("graphson_reader.readObject(x)[3]"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)[0],Vertex)"));
+        // assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)[1],str)")); // its python unicode jython object
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)[2],dict)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_reader.readObject(x)[3],bool)"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0e211d6b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
index 01e8c23..58211c6 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
@@ -56,14 +56,14 @@ public class GraphSONWriterTest {
 
     @Test
     public void shouldSerializeNumbers() throws Exception {
-        assertEquals(1, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(1)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(1), jythonEngine.eval("graphson_io.writeObject(1)").toString().replace(" ", ""));
+        assertEquals(1, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(1)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(1), jythonEngine.eval("graphson_writer.writeObject(1)").toString().replace(" ", ""));
         //
-        assertEquals(2L, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(2L)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(2L), jythonEngine.eval("graphson_io.writeObject(2L)").toString().replace(" ", ""));
+        assertEquals(2L, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(2L)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(2L), jythonEngine.eval("graphson_writer.writeObject(2L)").toString().replace(" ", ""));
         //
-        assertEquals(3.4, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(3.4)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(3.4), jythonEngine.eval("graphson_io.writeObject(3.4)").toString().replace(" ", ""));
+        assertEquals(3.4, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(3.4)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(3.4), jythonEngine.eval("graphson_writer.writeObject(3.4)").toString().replace(" ", ""));
     }
 
     @Test
@@ -71,60 +71,60 @@ public class GraphSONWriterTest {
         final Map<String, Number> map = new LinkedHashMap<>();
         map.put("a", 2);
         map.put("b", 2.3);
-        assertEquals(map, mapper.readValue(jythonEngine.eval("graphson_io.writeObject({'a':2,'b':2.3})").toString(), Object.class));
+        assertEquals(map, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject({'a':2,'b':2.3})").toString(), Object.class));
         //
         final List<Object> list = Arrays.asList(new DefaultRemoteTraverser<>("hello", 3L), "hello", map, true);
         assertTrue((Boolean) jythonEngine.eval("isinstance([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True],list)"));
-        assertEquals(list, mapper.readValue(jythonEngine.eval("graphson_io.writeObject([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True])").toString(), Object.class));
+        assertEquals(list, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True])").toString(), Object.class));
     }
 
     @Test
     public void shouldSerializeTraverser() throws Exception {
         assertEquals(
                 new DefaultRemoteTraverser<>("hello", 3L),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Object.class));
-        assertEquals(3L, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Traverser.class).bulk());
-        assertEquals("hello", mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Traverser.class).get());
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Traverser('hello',3L))").toString(), Object.class));
+        assertEquals(3L, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Traverser('hello',3L))").toString(), Traverser.class).bulk());
+        assertEquals("hello", mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Traverser('hello',3L))").toString(), Traverser.class).get());
     }
 
     @Test
     public void shouldSerializeBytecode() throws Exception {
-        assertEquals(P.eq(7L), mapper.readValue(jythonEngine.eval("graphson_io.writeObject(P.eq(7L))").toString(), Object.class));
-        // TODO: assertEquals(mapper.writeValueAsString(P.between(1, 2).and(P.eq(7L))), jythonEngine.eval("graphson_io.writeObject(P.eq(7L)._and(P.between(1,2)))").toString().replace(" ",""));
-        assertEquals(AndP.class, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(P.eq(7L).and_(P.between(1,2)))").toString(), Object.class).getClass());
+        assertEquals(P.eq(7L), mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(P.eq(7L))").toString(), Object.class));
+        // TODO: assertEquals(mapper.writeValueAsString(P.between(1, 2).and(P.eq(7L))), jythonEngine.eval("graphson_writer.writeObject(P.eq(7L)._and(P.between(1,2)))").toString().replace(" ",""));
+        assertEquals(AndP.class, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(P.eq(7L).and_(P.between(1,2)))").toString(), Object.class).getClass());
         //
-        assertEquals(new Bytecode.Binding<>("a", 5L), mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Binding('a',5L))").toString(), Object.class));
+        assertEquals(new Bytecode.Binding<>("a", 5L), mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Binding('a',5L))").toString(), Object.class));
         //
         for (final Column t : Column.values()) {
-            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Column." + t.name() + ")").toString(), Object.class));
+            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Column." + t.name() + ")").toString(), Object.class));
         }
         for (final T t : T.values()) {
-            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(T." + t.name() + ")").toString(), Object.class));
+            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(T." + t.name() + ")").toString(), Object.class));
         }
-        assertEquals(Pop.first, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.first)").toString(), Object.class));
-        assertEquals(Pop.last, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.last)").toString(), Object.class));
-        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.all_)").toString(), Object.class));
-        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Scope.global_)").toString(), Object.class));
-        assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Scope.local)").toString(), Object.class));
+        assertEquals(Pop.first, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Pop.first)").toString(), Object.class));
+        assertEquals(Pop.last, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Pop.last)").toString(), Object.class));
+        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Pop.all_)").toString(), Object.class));
+        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Scope.global_)").toString(), Object.class));
+        assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(Scope.local)").toString(), Object.class));
     }
 
     @Test
     public void shouldSerializeLambda() throws Exception {
         assertEquals(
                 Lambda.function("lambda z : 1+2", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'z : 1+2')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(lambda : 'z : 1+2')").toString(), Object.class));
         assertEquals(
                 Lambda.function("lambda z : z+ 7", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z : z+ 7')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(lambda : 'lambda z : z+ 7')").toString(), Object.class));
         assertEquals(
                 Lambda.supplier("lambda : 23", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda : 23')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(lambda : 'lambda : 23')").toString(), Object.class));
         assertEquals(
                 Lambda.consumer("lambda z : z + 23", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z : z + 23')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(lambda : 'lambda z : z + 23')").toString(), Object.class));
         assertEquals(
                 Lambda.biFunction("lambda z,y : z - y + 2", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z,y : z - y + 2')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_writer.writeObject(lambda : 'lambda z,y : z - y + 2')").toString(), Object.class));
     }
 
 }


[03/10] tinkerpop git commit: gremlinpython: simplify graphson serdes functions

Posted by ok...@apache.org.
gremlinpython: simplify graphson serdes functions


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

Branch: refs/heads/master
Commit: 0846b8d7b1ab8c902938602561af130456dbea41
Parents: a6cb661
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Fri Sep 23 14:09:03 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 15:30:43 2016 -0500

----------------------------------------------------------------------
 .../gremlin_python/structure/io/graphson.py     | 62 ++++++++------------
 1 file changed, 25 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0846b8d7/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 248d319..30aa47f 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -16,9 +16,6 @@ KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
 '''
-
-__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
-
 import json
 from abc import abstractmethod
 from aenum import Enum
@@ -41,25 +38,22 @@ from gremlin_python.structure.graph import VertexProperty
 from gremlin_python.structure.graph import Path
 
 
+__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
+
+
 class GraphSONWriter(object):
     @staticmethod
-    def _dictify(object):
+    def _dictify(obj):
         for key in serializers:
-            if isinstance(object, key):
-                return serializers[key]._dictify(object)
-        # list and map are treated as normal json objects (could be isolated serializers)
-        if isinstance(object, list) or isinstance(object, set):
-            newList = []
-            for item in object:
-                newList.append(GraphSONWriter._dictify(item))
-            return newList
-        elif isinstance(object, dict):
-            newDict = {}
-            for key in object:
-                newDict[GraphSONWriter._dictify(key)] = GraphSONWriter._dictify(object[key])
-            return newDict
+            if isinstance(obj, key):
+                return serializers[key]._dictify(obj)
+        # list and map are treated as normal json objs (could be isolated serializers)
+        if isinstance(obj, (list, set)):
+            return [GraphSONWriter._dictify(o) for o in obj]
+        elif isinstance(obj, dict):
+            return dict((GraphSONWriter._dictify(k), GraphSONWriter._dictify(v)) for k, v in obj.items())
         else:
-            return object
+            return obj
 
     @staticmethod
     def writeObject(objectData):
@@ -68,24 +62,18 @@ class GraphSONWriter(object):
 
 class GraphSONReader(object):
     @staticmethod
-    def _objectify(object):
-        if isinstance(object, dict):
-            if _SymbolHelper._TYPE in object:
-                type = object[_SymbolHelper._TYPE]
+    def _objectify(obj):
+        if isinstance(obj, dict):
+            if _SymbolHelper._TYPE in obj:
+                type = obj[_SymbolHelper._TYPE]
                 if type in deserializers:
-                    return deserializers[type]._objectify(object)
-                    # list and map are treated as normal json objects (could be isolated deserializers)
-            newDict = {}
-            for key in object:
-                newDict[GraphSONReader._objectify(key)] = GraphSONReader._objectify(object[key])
-            return newDict
-        elif isinstance(object, list):
-            newList = []
-            for item in object:
-                newList.append(GraphSONReader._objectify(item))
-            return newList
+                    return deserializers[type]._objectify(obj)
+            # list and map are treated as normal json objs (could be isolated deserializers)
+            return dict((GraphSONReader._objectify(k), GraphSONReader._objectify(v)) for k, v in obj.items())
+        elif isinstance(obj, list):
+            return [GraphSONReader._objectify(o) for o in obj]
         else:
-            return object
+            return obj
 
     @staticmethod
     def readObject(jsonData):
@@ -167,10 +155,10 @@ class BindingSerializer(GraphSONSerializer):
 
 class LambdaSerializer(GraphSONSerializer):
     def _dictify(self, lambdaObject):
-        lambdaResult = lambdaObject()
+        lambda_result = lambdaObject()
         dict = {}
-        script = lambdaResult if isinstance(lambdaResult, str) else lambdaResult[0]
-        language = statics.default_lambda_language if isinstance(lambdaResult, str) else lambdaResult[1]
+        script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
+        language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
         dict["script"] = script
         dict["language"] = language
         if language == "gremlin-jython" or language == "gremlin-python":


[10/10] tinkerpop git commit: merged the Gremlin Python work from @aholmberg. Fixed up the pom.xml and setup.cfg to include mock. Fixed up init-code-blocks.awk to account for the new GraphSONWriter/Reader model. Fixed a bug in ConnectiveStrategy around c

Posted by ok...@apache.org.
merged the Gremlin Python work from @aholmberg. Fixed up the pom.xml and setup.cfg to include mock. Fixed up init-code-blocks.awk to account for the new GraphSONWriter/Reader model. Fixed a bug in ConnectiveStrategy around choose() and HasNextStep -- added test cases to confirm proper behavior. Updated CHANGELOG.


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

Branch: refs/heads/master
Commit: e70a509a3bdcc69f4bbac3ed277b0c0d3a8d2854
Parents: c5b0883
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 12 14:53:22 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 12 14:53:22 2016 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  4 +++-
 docs/preprocessor/awk/init-code-blocks.awk      |  4 ++--
 docs/src/reference/gremlin-variants.asciidoc    |  4 ++--
 .../process/traversal/step/map/HasNextStep.java |  8 +++----
 .../strategy/decoration/ConnectiveStrategy.java |  5 ++++-
 .../step/branch/GroovyChooseTest.groovy         |  5 +++++
 gremlin-python/pom.xml                          |  1 +
 .../gremlin_python/structure/io/graphson.py     | 22 ++++++++++----------
 gremlin-python/src/main/jython/setup.py         |  3 ++-
 .../driver/test_driver_remote_connection.py     |  6 +++---
 .../jython/tests/structure/io/test_graphson.py  |  6 +++---
 .../traversal/step/branch/ChooseTest.java       | 22 +++++++++++++++++++-
 12 files changed, 60 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3741e11..714abc5 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,7 +26,9 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-* Increased performance of `CredentialGraph` authentication
+* Restructured Gremlin-Python's GraphSON I/O package to make it easier for users to register serializers/deserializers. (*breaking*)
+* Fixed a bug in `ConnectiveStrategy` where infix and/or was not correctly reasoning on `choose()` `HasNextStep` injections.
+* Increased performance of `CredentialGraph` authentication.
 * Removed Java 8 stream usage from `TraversalHelper` for performance reasons.
 * Fixed a bug in `RepeatStep` where `emit().as('x')` wasn't adding the step labels to the emit-traverser.
 * Added `GraphComputing.atMaster(boolean)` to allow steps to know whether they are executing at master or distributed at workers.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index f9b020a..381c231 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -80,11 +80,11 @@ BEGIN {
     print "  jython.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval(t.replace('.toList()','')))"
     print "  if(jython.eval('isinstance(j, Traversal)')) {"
     print "    mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).create().createMapper()"
-    print "    bytecode = mapper.readValue(jython.eval('GraphSONWriter.writeObject(j)').toString(), Bytecode.class)"
+    print "    bytecode = mapper.readValue(jython.eval('GraphSONWriter().writeObject(j)').toString(), Bytecode.class)"
     print "    language = BytecodeHelper.getLambdaLanguage(bytecode).orElse('gremlin-groovy')"
     print "    result = language.equals('gremlin-groovy') ? groovy.eval(GroovyTranslator.of(\"g\").translate(bytecode) + '.toList()').toString() : jython.eval(JythonTranslator.of(\"h\").translate(bytecode) + '.toList()').toString()"
     print "    jython.getContext().getBindings(GLOBAL_SCOPE).put('json', mapper.writeValueAsString(result))"
-    print "    return jython.eval('GraphSONReader.readObject(json)').toString()"
+    print "    return jython.eval('GraphSONReader().readObject(json)').toString()"
     print "  } else {"
     print "    j = jython.getContext().getBindings(GLOBAL_SCOPE).get('j')"
     print "    return null == j ? 'null' : j.toString()"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 0716ff1..4b65ab8 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -229,7 +229,7 @@ Traversal Strategies
 ~~~~~~~~~~~~~~~~~~~~
 
 In order to add and remove <<traversalstrategy,traversal strategies>> from a traversal source, Gremlin-Python has a
-`TraversalStrategy` class along with numerous subclasses that mirror the standard, distributed strategies.
+`TraversalStrategy` class along with a collection of subclasses that mirror the standard Gremlin-Java strategies.
 
 [gremlin-python,modern]
 ----
@@ -244,7 +244,7 @@ g.V().name.toList()
 g.V().outE().valueMap(True).toList()
 ----
 
-NOTE: Many of the `TraversalStrategy` classes in Gremlin-Python are proxies to the respective strategy on the
+NOTE: Many of the `TraversalStrategy` classes in Gremlin-Python are proxies to the respective strategy on
 Apache TinkerPop's JVM-based Gremlin traversal machine. As such, their `apply(Traversal)` method does nothing. However,
 the strategy is encoded in the Gremlin-Python bytecode and transmitted to the Gremlin traversal machine for
 re-construction machine-side.

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/HasNextStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/HasNextStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/HasNextStep.java
index b1b6c6e..3f1350c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/HasNextStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/HasNextStep.java
@@ -36,10 +36,8 @@ public final class HasNextStep<S> extends AbstractStep<S, Boolean> {
 
     @Override
     protected Traverser.Admin<Boolean> processNextStart() throws NoSuchElementException {
-        if (this.starts.hasNext()) {
-            final Traverser.Admin<S> s = this.starts.next();
-            return s.split(Boolean.TRUE, this);
-        } else
-            return this.getTraversal().getTraverserGenerator().generate(Boolean.FALSE, (Step) this, 1l);
+        return this.starts.hasNext() ?
+                this.starts.next().split(Boolean.TRUE, this) :
+                this.getTraversal().getTraverserGenerator().generate(Boolean.FALSE, (Step) this, 1L);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConnectiveStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConnectiveStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConnectiveStrategy.java
index 754fb03..eb85c7b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConnectiveStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConnectiveStrategy.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.ConnectiveStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.HasNextStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep;
@@ -63,7 +64,9 @@ public final class ConnectiveStrategy extends AbstractTraversalStrategy<Traversa
     }
 
     private static boolean legalCurrentStep(final Step<?, ?> step) {
-        return !(step instanceof EmptyStep || step instanceof ProfileSideEffectStep || step instanceof ComputerAwareStep.EndStep || (step instanceof StartStep && !StartStep.isVariableStartStep(step)) || GraphStep.isStartStep(step));
+        return !(step instanceof EmptyStep || step instanceof ProfileSideEffectStep || step instanceof HasNextStep ||
+                step instanceof ComputerAwareStep.EndStep || (step instanceof StartStep && !StartStep.isVariableStartStep(step)) ||
+                GraphStep.isStartStep(step));
     }
 
     private static void processConnectiveMarker(final Traversal.Admin<?, ?> traversal) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyChooseTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyChooseTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyChooseTest.groovy
index 509340c..b92ab9b 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyChooseTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/branch/GroovyChooseTest.groovy
@@ -38,5 +38,10 @@ public abstract class GroovyChooseTest {
         public Traversal<Vertex, String> get_g_V_chooseXlabel_eqXpersonX__outXknowsX__inXcreatedXX_name() {
             new ScriptTraversal<>(g, "gremlin-groovy", "g.V.choose({it.label() == 'person'}, out('knows'), __.in('created')).name")
         }
+
+        @Override
+        public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name() {
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.choose(hasLabel('person').and().out('created'), out('knows'), identity()).name")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-python/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml
index 627b249..ac37cd6 100644
--- a/gremlin-python/pom.xml
+++ b/gremlin-python/pom.xml
@@ -313,6 +313,7 @@
                                     <libraries>
                                         <param>aenum==1.4.5</param>
                                         <param>tornado==4.4.1</param>
+                                        <param>six==1.10.0</param>
                                     </libraries>
                                 </configuration>
                             </execution>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 45aec9d..002e401 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -41,7 +41,7 @@ class GraphSONTypeType(type):
         return cls
 
 
-class _GraphSONIO(object):
+class GraphSONUtil(object):
     TYPE_KEY = "@type"
     VALUE_KEY = "@value"
 
@@ -104,7 +104,7 @@ class GraphSONReader(object):
         """
         if isinstance(obj, dict):
             try:
-                return self.deserializers[obj[_GraphSONIO.TYPE_KEY]].objectify(obj[_GraphSONIO.VALUE_KEY], self)
+                return self.deserializers[obj[GraphSONUtil.TYPE_KEY]].objectify(obj[GraphSONUtil.VALUE_KEY], self)
             except KeyError:
                 pass
             # list and map are treated as normal json objs (could be isolated deserializers)
@@ -155,7 +155,7 @@ class _BytecodeSerializer(_GraphSONTypeIO):
             out["source"] = cls._dictify_instructions(bytecode.source_instructions, writer)
         if bytecode.step_instructions:
             out["step"] = cls._dictify_instructions(bytecode.step_instructions, writer)
-        return _GraphSONIO.typedValue("Bytecode", out)
+        return GraphSONUtil.typedValue("Bytecode", out)
 
 
 class TraversalSerializer(_BytecodeSerializer):
@@ -171,7 +171,7 @@ class TraversalStrategySerializer(_GraphSONTypeIO):
 
     @classmethod
     def dictify(cls, strategy, writer):
-        return _GraphSONIO.typedValue(strategy.strategy_name, writer.toDict(strategy.configuration))
+        return GraphSONUtil.typedValue(strategy.strategy_name, writer.toDict(strategy.configuration))
 
 
 class TraverserIO(_GraphSONTypeIO):
@@ -180,7 +180,7 @@ class TraverserIO(_GraphSONTypeIO):
 
     @classmethod
     def dictify(cls, traverser, writer):
-        return _GraphSONIO.typedValue("Traverser", {"value": writer.toDict(traverser.object),
+        return GraphSONUtil.typedValue("Traverser", {"value": writer.toDict(traverser.object),
                                                      "bulk": writer.toDict(traverser.bulk)})
 
     @classmethod
@@ -194,8 +194,8 @@ class EnumSerializer(_GraphSONTypeIO):
 
     @classmethod
     def dictify(cls, enum, _):
-        return _GraphSONIO.typedValue(cls.unmangleKeyword(type(enum).__name__),
-                                      cls.unmangleKeyword(str(enum.name)))
+        return GraphSONUtil.typedValue(cls.unmangleKeyword(type(enum).__name__),
+                                       cls.unmangleKeyword(str(enum.name)))
 
 
 class PSerializer(_GraphSONTypeIO):
@@ -206,7 +206,7 @@ class PSerializer(_GraphSONTypeIO):
         out = {"predicate": p.operator,
                "value": [writer.toDict(p.value), writer.toDict(p.other)] if p.other is not None else
                         writer.toDict(p.value)}
-        return _GraphSONIO.typedValue("P", out)
+        return GraphSONUtil.typedValue("P", out)
 
 
 class BindingSerializer(_GraphSONTypeIO):
@@ -216,7 +216,7 @@ class BindingSerializer(_GraphSONTypeIO):
     def dictify(cls, binding, writer):
         out = {"key": binding.key,
                "value": writer.toDict(binding.value)}
-        return _GraphSONIO.typedValue("Binding", out)
+        return GraphSONUtil.typedValue("Binding", out)
 
 
 class LambdaSerializer(_GraphSONTypeIO):
@@ -236,7 +236,7 @@ class LambdaSerializer(_GraphSONTypeIO):
             out["arguments"] = six.get_function_code(eval(out["script"])).co_argcount
         else:
             out["arguments"] = -1
-        return _GraphSONIO.typedValue("Lambda", out)
+        return GraphSONUtil.typedValue("Lambda", out)
 
 
 class TypeSerializer(_GraphSONTypeIO):
@@ -253,7 +253,7 @@ class _NumberIO(_GraphSONTypeIO):
     def dictify(cls, n, writer):
         if isinstance(n, bool):  # because isinstance(False, int) and isinstance(True, int)
             return n
-        return _GraphSONIO.typedValue(cls.graphson_base_type, n)
+        return GraphSONUtil.typedValue(cls.graphson_base_type, n)
 
     @classmethod
     def objectify(cls, v, _):

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-python/src/main/jython/setup.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/setup.py b/gremlin-python/src/main/jython/setup.py
index 08cfe37..57374a7 100644
--- a/gremlin-python/src/main/jython/setup.py
+++ b/gremlin-python/src/main/jython/setup.py
@@ -57,7 +57,8 @@ setup(
         'pytest-runner',
     ],
     tests_require=[
-        'pytest'
+        'pytest',
+        'mock'
     ],
     install_requires=[
         'aenum==1.4.5',

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index f65255b..80cf0c5 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -21,6 +21,7 @@ __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
 
 import unittest
 from unittest import TestCase
+from gremlin_python.structure.io.graphson import GraphSONWriter
 
 import pytest
 
@@ -78,14 +79,14 @@ class TestDriverRemoteConnection(TestCase):
         #
         g = Graph().traversal().withRemote(connection). \
             withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created")))
-        print GraphSONWriter.writeObject(g.bytecode)
+        print GraphSONWriter().writeObject(g.bytecode)
         assert 4 == g.V().count().next()
         assert 0 == g.E().count().next()
         assert 1 == g.V().label().dedup().count().next()
         assert "person" == g.V().label().dedup().next()
         #
         g = g.withoutStrategies(SubgraphStrategy). \
-            withComputer({"workers": 4, "vertices": __.has("name", "marko"), "edges": __.limit(0)})
+            withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0))
         assert 1 == g.V().count().next()
         assert 0 == g.E().count().next()
         assert "person" == g.V().label().next()
@@ -150,7 +151,6 @@ class TestDriverRemoteConnection(TestCase):
             pass
         connection.close()
 
-
     def test_side_effect_close(self):
         connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
         g = Graph().traversal().withRemote(connection)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index a192cd2..f0e8130 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -29,7 +29,7 @@ import six
 from gremlin_python.statics import *
 from gremlin_python.structure.graph import Vertex
 from gremlin_python.structure.graph import Path
-from gremlin_python.structure.io.graphson import GraphSONWriter, GraphSONReader, _GraphSONIO
+from gremlin_python.structure.io.graphson import GraphSONWriter, GraphSONReader, GraphSONUtil
 import gremlin_python.structure.io.graphson
 from gremlin_python.process.traversal import P
 from gremlin_python.process.strategies import SubgraphStrategy
@@ -108,7 +108,7 @@ class TestGraphSONReader(TestCase):
         assert type_string not in gremlin_python.structure.io.graphson._deserializers
 
         x = X()
-        o = reader.toObject({_GraphSONIO.TYPE_KEY: type_string, _GraphSONIO.VALUE_KEY: x})
+        o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: x})
         serdes.objectify.assert_called_once_with(x, reader)
         assert o is serdes.objectify()
 
@@ -119,7 +119,7 @@ class TestGraphSONReader(TestCase):
         assert gremlin_python.structure.io.graphson._deserializers[type_string] is not reader.deserializers[type_string]
 
         value = 3
-        o = reader.toObject({_GraphSONIO.TYPE_KEY: type_string, _GraphSONIO.VALUE_KEY: value})
+        o = reader.toObject({GraphSONUtil.TYPE_KEY: type_string, GraphSONUtil.VALUE_KEY: value})
         serdes.objectify.assert_called_once_with(value, reader)
         assert o is serdes.objectify()
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e70a509a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseTest.java
index 26bd466..bf050e4 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseTest.java
@@ -32,7 +32,12 @@ import java.util.HashMap;
 import java.util.Map;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.hasLabel;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.identity;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.values;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
@@ -47,6 +52,8 @@ public abstract class ChooseTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, String> get_g_V_chooseXlabel_eqXpersonX__outXknowsX__inXcreatedXX_name();
 
+    public abstract Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name();
+
 
     @Test
     @LoadGraphWith(MODERN)
@@ -74,6 +81,14 @@ public abstract class ChooseTest extends AbstractGremlinProcessTest {
         checkResults(Arrays.asList("josh", "vadas", "josh", "josh", "marko", "peter"), traversal);
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name() {
+        final Traversal<Vertex, String> traversal = get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name();
+        printTraversalForm(traversal);
+        checkResults(Arrays.asList("lop", "ripple", "josh", "vadas", "vadas"), traversal);
+    }
+
     public static class Traversals extends ChooseTest {
 
         @Override
@@ -87,5 +102,10 @@ public abstract class ChooseTest extends AbstractGremlinProcessTest {
         public Traversal<Vertex, String> get_g_V_chooseXlabel_eqXpersonX__outXknowsX__inXcreatedXX_name() {
             return g.V().choose(v -> v.label().equals("person"), out("knows"), in("created")).values("name");
         }
+
+        @Override
+        public Traversal<Vertex, String> get_g_V_chooseXhasLabelXpersonX_and_outXcreatedX__outXknowsX__identityX_name() {
+            return g.V().choose(hasLabel("person").and().out("created"), out("knows"), identity()).values("name");
+        }
     }
 }
\ No newline at end of file


[07/10] tinkerpop git commit: accept custom graphson_io instance in DriverRemoteConnection

Posted by ok...@apache.org.
accept custom graphson_io instance in DriverRemoteConnection


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

Branch: refs/heads/master
Commit: d296eb79719fc97e65339a03573d1be11afe47be
Parents: 2ce68df
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Mon Oct 10 16:23:12 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 16:23:12 2016 -0500

----------------------------------------------------------------------
 .../jython/gremlin_python/driver/driver_remote_connection.py     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d296eb79/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 b8b3d87..20129e9 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
@@ -34,14 +34,14 @@ class GremlinServerError(Exception):
 
 
 class DriverRemoteConnection(RemoteConnection):
-    def __init__(self, url, traversal_source, username="", password="", loop=None):
+    def __init__(self, url, traversal_source, username="", password="", loop=None, graphson_io=None):
         super(DriverRemoteConnection, self).__init__(url, traversal_source)
         self._url = url
         self._username = username
         self._password = password
         if loop is None: self._loop = ioloop.IOLoop.current()
         self._websocket = self._loop.run_sync(lambda: websocket.websocket_connect(self.url))
-        self._graphson_io = GraphSONIO()
+        self._graphson_io = graphson_io or GraphSONIO()
 
     def submit(self, bytecode):
         '''


[05/10] tinkerpop git commit: gremlinpython: refactor GraphsonIO to use instance type maps

Posted by ok...@apache.org.
gremlinpython: refactor GraphsonIO to use instance type maps


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

Branch: refs/heads/master
Commit: d392379e6fc2a7acfc6ed73a8f82ee04cbab2efd
Parents: 6c4bf0b
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Tue Oct 4 13:56:21 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 16:01:50 2016 -0500

----------------------------------------------------------------------
 .../driver/driver_remote_connection.py          |  13 +-
 .../gremlin_python/structure/io/graphson.py     | 372 ++++++++++---------
 .../jython/tests/structure/io/test_graphson.py  |  87 ++++-
 .../python/jsr223/JythonScriptEngineSetup.java  |   4 +-
 .../jsr223/PythonGraphSONJavaTranslator.java    |   2 +-
 .../io/graphson/GraphSONReaderTest.java         |  68 ++--
 .../io/graphson/GraphSONWriterTest.java         |  56 +--
 7 files changed, 344 insertions(+), 258 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/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 e47c8e6..b8b3d87 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
@@ -23,8 +23,7 @@ from tornado import gen
 from tornado import ioloop
 from tornado import websocket
 
-from gremlin_python.structure.io.graphson import GraphSONReader
-from gremlin_python.structure.io.graphson import GraphSONWriter
+from gremlin_python.structure.io.graphson import GraphSONIO
 from .remote_connection import RemoteConnection
 from .remote_connection import RemoteTraversal
 from .remote_connection import RemoteTraversalSideEffects
@@ -42,6 +41,7 @@ class DriverRemoteConnection(RemoteConnection):
         self._password = password
         if loop is None: self._loop = ioloop.IOLoop.current()
         self._websocket = self._loop.run_sync(lambda: websocket.websocket_connect(self.url))
+        self._graphson_io = GraphSONIO()
 
     def submit(self, bytecode):
         '''
@@ -65,7 +65,7 @@ class DriverRemoteConnection(RemoteConnection):
             "op": "bytecode",
             "processor": "traversal",
             "args": {
-                "gremlin": GraphSONWriter.writeObject(bytecode),
+                "gremlin": self._graphson_io.writeObject(bytecode),
                 "aliases": {"g": self.traversal_source}
             }
         }
@@ -142,7 +142,7 @@ class DriverRemoteConnection(RemoteConnection):
         if self._websocket.protocol is None:
             self._websocket = yield websocket.websocket_connect(self.url)
         self._websocket.write_message(send_message, binary=True)
-        response = Response(self._websocket, self._username, self._password)
+        response = Response(self._websocket, self._username, self._password, self._graphson_io)
         results = None
         while True:
             recv_message = yield response.receive()
@@ -183,11 +183,12 @@ class DriverRemoteConnection(RemoteConnection):
 
 
 class Response:
-    def __init__(self, websocket, username, password):
+    def __init__(self, websocket, username, password, graphson_io):
         self._websocket = websocket
         self._username = username
         self._password = password
         self._closed = False
+        self._graphson_io = graphson_io
 
     @gen.coroutine
     def receive(self):
@@ -224,7 +225,7 @@ class Response:
         elif status_code in [200, 206]:
             results = []
             for item in recv_message["result"]["data"]:
-                results.append(GraphSONReader._objectify(item))
+                results.append(self._graphson_io.toObject(item))
             if status_code == 200:
                 self._closed = True
             raise gen.Return((aggregateTo, results))

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index b44897a..50db7cb 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -17,14 +17,12 @@ specific language governing permissions and limitations
 under the License.
 '''
 import json
-from abc import abstractmethod
 from aenum import Enum
 
 import six
 
 from gremlin_python import statics
-from gremlin_python.statics import (
-    FloatType, FunctionType, IntType, LongType, long, TypeType)
+from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType
 from gremlin_python.process.traversal import Binding
 from gremlin_python.process.traversal import Bytecode
 from gremlin_python.process.traversal import P
@@ -38,113 +36,194 @@ from gremlin_python.structure.graph import VertexProperty
 from gremlin_python.structure.graph import Path
 
 
-__author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
+_serializers = {}
+_deserializers = {}
 
 
-class GraphSONWriter(object):
-    @staticmethod
-    def _dictify(obj):
-        for key, serializer in serializers.items():
+class GraphSONTypeType(type):
+    def __new__(mcs, name, bases, dct):
+        cls = super(GraphSONTypeType, mcs).__new__(mcs, name, bases, dct)
+        if not name.startswith('_'):
+            if cls.python_type:
+                _serializers[cls.python_type] = cls
+            if cls.graphson_type:
+                _deserializers[cls.graphson_type] = cls
+        return cls
+
+
+class GraphSONIO(object):
+
+    _TYPE_KEY = "@type"
+    _VALUE_KEY = "@value"
+
+    def __init__(self, serializer_map=None, deserializer_map=None):
+        """
+        :param serializer_map: map from Python type to serializer instance implementing `dictify`
+        :param deserializer_map: map from GraphSON type tag to deserializer instance implementing `objectify`
+        """
+        self.serializers = _serializers.copy()
+        if serializer_map:
+            self.serializers.update(serializer_map)
+
+        self.deserializers = _deserializers.copy()
+        if deserializer_map:
+            self.deserializers.update(deserializer_map)
+
+    def writeObject(self, objectData):
+        # to JSON
+        return json.dumps(self.toDict(objectData), separators=(',', ':'))
+
+    def readObject(self, jsonData):
+        # from JSON
+        return self.toObject(json.loads(jsonData))
+
+    def toDict(self, obj):
+        """
+        Encodes python objects in GraphSON type-tagged dict values
+        """
+        for key, serializer in self.serializers.items():
             if isinstance(obj, key):
-                return serializer._dictify(obj)
+                return serializer.dictify(obj, self)
         # list and map are treated as normal json objs (could be isolated serializers)
         if isinstance(obj, (list, set)):
-            return [GraphSONWriter._dictify(o) for o in obj]
+            return [self.toDict(o) for o in obj]
         elif isinstance(obj, dict):
-            return dict((GraphSONWriter._dictify(k), GraphSONWriter._dictify(v)) for k, v in obj.items())
+            return dict((self.toDict(k), self.toDict(v)) for k, v in obj.items())
         else:
             return obj
 
-    @staticmethod
-    def writeObject(objectData):
-        return json.dumps(GraphSONWriter._dictify(objectData), separators=(',', ':'))
-
-
-class GraphSONReader(object):
-    @staticmethod
-    def _objectify(obj):
+    def toObject(self, obj):
+        """
+        Unpacks GraphSON type-tagged dict values into objects mapped in self.deserializers
+        """
         if isinstance(obj, dict):
             try:
-                return deserializers[obj[_SymbolHelper._TYPE]]._objectify(obj)
+                return self.deserializers[obj[self._TYPE_KEY]].objectify(obj[self._VALUE_KEY], self)
             except KeyError:
                 pass
             # list and map are treated as normal json objs (could be isolated deserializers)
-            return dict((GraphSONReader._objectify(k), GraphSONReader._objectify(v)) for k, v in obj.items())
+            return dict((self.toObject(k), self.toObject(v)) for k, v in obj.items())
         elif isinstance(obj, list):
-            return [GraphSONReader._objectify(o) for o in obj]
+            return [self.toObject(o) for o in obj]
         else:
             return obj
 
-    @staticmethod
-    def readObject(jsonData):
-        return GraphSONReader._objectify(json.loads(jsonData))
+    def typedValue(self, type_name, value, prefix="g"):
+        out = {self._TYPE_KEY: prefix + ":" + type_name}
+        if value is not None:
+            out[self._VALUE_KEY] = value
+        return out
+
 
+@six.add_metaclass(GraphSONTypeType)
+class _GraphSONTypeIO(object):
+    python_type = None
+    graphson_type = None
 
-'''
-SERIALIZERS
-'''
+    symbolMap = {"global_": "global", "as_": "as", "in_": "in", "and_": "and",
+                 "or_": "or", "is_": "is", "not_": "not", "from_": "from",
+                 "set_": "set", "list_": "list", "all_": "all"}
+
+    @classmethod
+    def unmangleKeyword(cls, symbol):
+        return cls.symbolMap.get(symbol, symbol)
+
+    def dictify(self, obj, graphson_io):
+        raise NotImplementedError()
 
+    def objectify(self, d, graphson_io):
+        raise NotImplementedError()
 
-class GraphSONSerializer(object):
-    @abstractmethod
-    def _dictify(self, obj):
-        return obj
 
+class _BytecodeSerializer(_GraphSONTypeIO):
 
-class BytecodeSerializer(GraphSONSerializer):
-    def _dictify_instructions(self, instructions):
+    @classmethod
+    def _dictify_instructions(cls, instructions, graphson_io):
         out = []
         for instruction in instructions:
             inst = [instruction[0]]
-            inst.extend(GraphSONWriter._dictify(arg) for arg in instruction[1:])
+            inst.extend(graphson_io.toDict(arg) for arg in instruction[1:])
             out.append(inst)
         return out
 
-    def _dictify(self, bytecode):
+    @classmethod
+    def dictify(cls, bytecode, graphson_io):
         if isinstance(bytecode, Traversal):
             bytecode = bytecode.bytecode
         out = {}
         if bytecode.source_instructions:
-            out["source"] = self._dictify_instructions(bytecode.source_instructions)
+            out["source"] = cls._dictify_instructions(bytecode.source_instructions, graphson_io)
         if bytecode.step_instructions:
-            out["step"] = self._dictify_instructions(bytecode.step_instructions)
-        return _SymbolHelper.objectify("Bytecode", out)
+            out["step"] = cls._dictify_instructions(bytecode.step_instructions, graphson_io)
+        return graphson_io.typedValue("Bytecode", out)
+
+
+class TraversalSerializer(_BytecodeSerializer):
+    python_type = Traversal
 
 
-class TraversalStrategySerializer(GraphSONSerializer):
-    def _dictify(self, strategy):
-        return _SymbolHelper.objectify(strategy.strategy_name, GraphSONWriter._dictify(strategy.configuration))
+class BytecodeSerializer(_BytecodeSerializer):
+    python_type = Bytecode
 
 
-class TraverserSerializer(GraphSONSerializer):
-    def _dictify(self, traverser):
-        return _SymbolHelper.objectify("Traverser", {"value": GraphSONWriter._dictify(traverser.object),
-                                                     "bulk": GraphSONWriter._dictify(traverser.bulk)})
+class TraversalStrategySerializer(_GraphSONTypeIO):
+    python_type = TraversalStrategy
 
+    @classmethod
+    def dictify(cls, strategy, graphson_io):
+        return graphson_io.typedValue(strategy.strategy_name, graphson_io.toDict(strategy.configuration))
 
-class EnumSerializer(GraphSONSerializer):
-    def _dictify(self, enum):
-        return _SymbolHelper.objectify(_SymbolHelper.toGremlin(type(enum).__name__),
-                                       _SymbolHelper.toGremlin(str(enum.name)))
 
+class TraverserIO(_GraphSONTypeIO):
+    python_type = Traverser
+    graphson_type = "g:Traverser"
 
-class PSerializer(GraphSONSerializer):
-    def _dictify(self, p):
+    @classmethod
+    def dictify(cls, traverser, graphson_io):
+        return graphson_io.typedValue("Traverser", {"value": graphson_io.toDict(traverser.object),
+                                                     "bulk": graphson_io.toDict(traverser.bulk)})
+
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        return Traverser(graphson_io.toObject(d["value"]),
+                         graphson_io.toObject(d["bulk"]))
+
+
+class EnumSerializer(_GraphSONTypeIO):
+    python_type = Enum
+
+    @classmethod
+    def dictify(cls, enum, graphson_io):
+        return graphson_io.typedValue(cls.unmangleKeyword(type(enum).__name__),
+                                      cls.unmangleKeyword(str(enum.name)))
+
+
+class PSerializer(_GraphSONTypeIO):
+    python_type = P
+
+    @classmethod
+    def dictify(cls, p, graphson_io):
         out = {"predicate": p.operator,
-               "value": [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)] if p.other is not None else
-                        GraphSONWriter._dictify(p.value)}
-        return _SymbolHelper.objectify("P", out)
+               "value": [graphson_io.toDict(p.value), graphson_io.toDict(p.other)] if p.other is not None else
+                        graphson_io.toDict(p.value)}
+        return graphson_io.typedValue("P", out)
+
 
+class BindingSerializer(_GraphSONTypeIO):
+    python_type = Binding
 
-class BindingSerializer(GraphSONSerializer):
-    def _dictify(self, binding):
+    @classmethod
+    def dictify(cls, binding, graphson_io):
         out = {"key": binding.key,
-               "value": GraphSONWriter._dictify(binding.value)}
-        return _SymbolHelper.objectify("Binding", out)
+               "value": graphson_io.toDict(binding.value)}
+        return graphson_io.typedValue("Binding", out)
+
 
+class LambdaSerializer(_GraphSONTypeIO):
+    python_type = FunctionType
 
-class LambdaSerializer(GraphSONSerializer):
-    def _dictify(self, lambda_object):
+    @classmethod
+    def dictify(cls, lambda_object, graphson_io):
         lambda_result = lambda_object()
         script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
         language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
@@ -157,137 +236,94 @@ class LambdaSerializer(GraphSONSerializer):
             out["arguments"] = six.get_function_code(eval(out["script"])).co_argcount
         else:
             out["arguments"] = -1
-        return _SymbolHelper.objectify("Lambda", out)
+        return graphson_io.typedValue("Lambda", out)
 
 
-class TypeSerializer(GraphSONSerializer):
-    def _dictify(self, clazz):
-        return GraphSONWriter._dictify(clazz())
+class TypeSerializer(_GraphSONTypeIO):
+    python_type = TypeType
 
+    @classmethod
+    def dictify(cls, typ, graphson_io):
+        return graphson_io.toDict(typ())
 
-class NumberSerializer(GraphSONSerializer):
-    def _dictify(self, number):
-        if isinstance(number, bool):  # python thinks that 0/1 integers are booleans
-            return number
-        elif isinstance(number, long) or (
-                    abs(number) > 2147483647):  # in python all numbers are int unless specified otherwise
-            return _SymbolHelper.objectify("Int64", number)
-        elif isinstance(number, int):
-            return _SymbolHelper.objectify("Int32", number)
-        elif isinstance(number, float):
-            return _SymbolHelper.objectify("Float", number)
-        else:
-            return number
 
+class _NumberIO(_GraphSONTypeIO):
 
-'''
-DESERIALIZERS
-'''
+    @classmethod
+    def dictify(cls, n, graphson_io):
+        if isinstance(n, bool):  # because isinstance(False, int) and isinstance(True, int)
+            return n
+        return graphson_io.typedValue(cls.graphson_base_type, n)
 
+    @classmethod
+    def objectify(cls, v, _):
+        return cls.python_type(v)
 
-class GraphSONDeserializer(object):
-    @abstractmethod
-    def _objectify(self, d):
-        return d
 
+class FloatIO(_NumberIO):
+    python_type = FloatType
+    graphson_type = "g:Float"
+    graphson_base_type = "Float"
 
-class TraverserDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        return Traverser(GraphSONReader._objectify(d[_SymbolHelper._VALUE]["value"]),
-                         GraphSONReader._objectify(d[_SymbolHelper._VALUE]["bulk"]))
 
+class DoubleIO(FloatIO):
+    graphson_type = "g:Double"
+    graphson_base_type = "Double"
 
-class NumberDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        type = d[_SymbolHelper._TYPE]
-        value = d[_SymbolHelper._VALUE]
-        if type == "g:Int32":
-            return int(value)
-        elif type == "g:Int64":
-            return long(value)
-        else:
-            return float(value)
 
+class Int64IO(_NumberIO):
+    python_type = LongType
+    graphson_type = "g:Int64"
+    graphson_base_type = "Int64"
 
-class VertexDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        value = d[_SymbolHelper._VALUE]
-        return Vertex(GraphSONReader._objectify(value["id"]), value.get("label", ""))
 
+class Int32IO(_NumberIO):
+    python_type = IntType
+    graphson_type = "g:Int32"
+    graphson_base_type = "Int32"
 
-class EdgeDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        value = d[_SymbolHelper._VALUE]
-        return Edge(GraphSONReader._objectify(value["id"]),
-                    Vertex(GraphSONReader._objectify(value["outV"]), ""),
-                    value.get("label", "vertex"),
-                    Vertex(GraphSONReader._objectify(value["inV"]), ""))
 
+class VertexDeserializer(_GraphSONTypeIO):
+    graphson_type = "g:Vertex"
 
-class VertexPropertyDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        value = d[_SymbolHelper._VALUE]
-        return VertexProperty(GraphSONReader._objectify(value["id"]), value["label"],
-                              GraphSONReader._objectify(value["value"]))
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        return Vertex(graphson_io.toObject(d["id"]), d.get("label", ""))
 
 
-class PropertyDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        value = d[_SymbolHelper._VALUE]
-        return Property(value["key"], GraphSONReader._objectify(value["value"]))
+class EdgeDeserializer(_GraphSONTypeIO):
+    graphson_type = "g:Edge"
 
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        return Edge(graphson_io.toObject(d["id"]),
+                    Vertex(graphson_io.toObject(d["outV"]), ""),
+                    d.get("label", "vertex"),
+                    Vertex(graphson_io.toObject(d["inV"]), ""))
 
-class PathDeserializer(GraphSONDeserializer):
-    def _objectify(self, d):
-        value = d[_SymbolHelper._VALUE]
-        labels = [set(label) for label in value["labels"]]
-        objects = [GraphSONReader._objectify(o) for o in value["objects"]]
-        return Path(labels, objects)
 
+class VertexPropertyDeserializer(_GraphSONTypeIO):
+    graphson_type = "g:VertexProperty"
 
-class _SymbolHelper(object):
-    symbolMap = {"global_": "global", "as_": "as", "in_": "in", "and_": "and",
-                 "or_": "or", "is_": "is", "not_": "not", "from_": "from",
-                 "set_": "set", "list_": "list", "all_": "all"}
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        return VertexProperty(graphson_io.toObject(d["id"]), d["label"],
+                              graphson_io.toObject(d["value"]))
 
-    _TYPE = "@type"
-    _VALUE = "@value"
 
-    @staticmethod
-    def toGremlin(symbol):
-        return _SymbolHelper.symbolMap.get(symbol, symbol)
+class PropertyDeserializer(_GraphSONTypeIO):
+    graphson_type = "g:Property"
 
-    @staticmethod
-    def objectify(type, value=None, prefix="g"):
-        object = {_SymbolHelper._TYPE: prefix + ":" + type}
-        if value is not None:
-            object[_SymbolHelper._VALUE] = value
-        return object
-
-serializers = {
-    Traversal: BytecodeSerializer(),
-    Traverser: TraverserSerializer(),
-    Bytecode: BytecodeSerializer(),
-    Binding: BindingSerializer(),
-    P: PSerializer(),
-    Enum: EnumSerializer(),
-    FunctionType: LambdaSerializer(),
-    LongType: NumberSerializer(),
-    IntType: NumberSerializer(),
-    FloatType: NumberSerializer(),
-    TypeType: TypeSerializer(),
-    TraversalStrategy: TraversalStrategySerializer(),
-}
-
-deserializers = {
-    "g:Traverser": TraverserDeserializer(),
-    "g:Int32": NumberDeserializer(),
-    "g:Int64": NumberDeserializer(),
-    "g:Float": NumberDeserializer(),
-    "g:Double": NumberDeserializer(),
-    "g:Vertex": VertexDeserializer(),
-    "g:Edge": EdgeDeserializer(),
-    "g:VertexProperty": VertexPropertyDeserializer(),
-    "g:Property": PropertyDeserializer(),
-    "g:Path": PathDeserializer()
-}
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        return Property(d["key"], graphson_io.toObject(d["value"]))
+
+
+class PathDeserializer(_GraphSONTypeIO):
+    graphson_type = "g:Path"
+
+    @classmethod
+    def objectify(cls, d, graphson_io):
+        labels = [set(label) for label in d["labels"]]
+        objects = [graphson_io.toObject(o) for o in d["objects"]]
+        return Path(labels, objects)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index 313f406..90866aa 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -20,6 +20,7 @@ under the License.
 __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
 
 import json
+from mock import Mock
 import unittest
 from unittest import TestCase
 
@@ -28,37 +29,39 @@ import six
 from gremlin_python.statics import *
 from gremlin_python.structure.graph import Vertex
 from gremlin_python.structure.graph import Path
-from gremlin_python.structure.io.graphson import GraphSONReader
-from gremlin_python.structure.io.graphson import GraphSONWriter
+from gremlin_python.structure.io.graphson import GraphSONIO
+import gremlin_python.structure.io.graphson
 from gremlin_python.process.traversal import P
 from gremlin_python.process.strategies import SubgraphStrategy
 from gremlin_python.process.graph_traversal import __
 
+graphson_io = GraphSONIO()
 
-class TestGraphSONReader(TestCase):
-    def test_numbers(self):
-        x = GraphSONReader.readObject(json.dumps({
+
+class TestGraphSONIO(TestCase):
+    def test_number_input(self):
+        x = graphson_io.readObject(json.dumps({
             "@type": "g:Int32",
             "@value": 31
         }))
         assert isinstance(x, int)
         assert 31 == x
         ##
-        x = GraphSONReader.readObject(json.dumps({
+        x = graphson_io.readObject(json.dumps({
             "@type": "g:Int64",
             "@value": 31
         }))
         assert isinstance(x, long)
         assert long(31) == x
         ##
-        x = GraphSONReader.readObject(json.dumps({
+        x = graphson_io.readObject(json.dumps({
             "@type": "g:Float",
             "@value": 31.3
         }))
         assert isinstance(x, float)
         assert 31.3 == x
         ##
-        x = GraphSONReader.readObject(json.dumps({
+        x = graphson_io.readObject(json.dumps({
             "@type": "g:Double",
             "@value": 31.2
         }))
@@ -66,7 +69,7 @@ class TestGraphSONReader(TestCase):
         assert 31.2 == x
 
     def test_graph(self):
-        vertex = GraphSONReader.readObject(
+        vertex = graphson_io.readObject(
             """{"@type":"g:Vertex", "@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","outE":{"created":[{"id":{"@type":"g:Int32","@value":9},"inV":{"@type":"g:Int32","@value":3},"properties":{"weight":{"@type":"g:Double","@value":0.4}}}],"knows":[{"id":{"@type":"g:Int32","@value":7},"inV":{"@type":"g:Int32","@value":2},"properties":{"weight":{"@type":"g:Double","@value":0.5}}},{"id":{"@type":"g:Int32","@value":8},"inV":{"@type":"g:Int32","@value":4},"properties":{"weight":{"@type":"g:Double","@value":1.0}}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":0},"value":"marko"}],"age":[{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29}}]}}}""")
         assert isinstance(vertex, Vertex)
         assert "person" == vertex.label
@@ -75,7 +78,7 @@ class TestGraphSONReader(TestCase):
         assert vertex == Vertex(1)
 
     def test_path(self):
-        path = GraphSONReader.readObject(
+        path = graphson_io.readObject(
             """{"@type":"g:Path","@value":{"labels":[["a"],["b","c"],[]],"objects":[{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":1},"label":"person","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":0},"value":"marko","label":"name"}}],"age":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":1},"value":{"@type":"g:Int32","@value":29},"label":"age"}}]}}},{"@type":"g:Vertex","@value":{"id":{"@type":"g:Int32","@value":3},"label":"software","properties":{"name":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":4},"value":"lop","label":"name"}}],"lang":[{"@type":"g:VertexProperty","@value":{"id":{"@type":"g:Int64","@value":5},"value":"java","label":"lang"}}]}}},"lop"]}}"""
         )
         assert isinstance(path, Path)
@@ -88,25 +91,71 @@ class TestGraphSONReader(TestCase):
         assert "lop" == path[2]
         assert 3 == len(path)
 
+    def test_number_output(self):
+        assert {"@type":"g:Int64","@value":2} == json.loads(graphson_io.writeObject(long(2)))
+        assert {"@type":"g:Int32","@value":1} == json.loads(graphson_io.writeObject(1))
+        assert {"@type":"g:Double","@value":3.2} == json.loads(graphson_io.writeObject(3.2))
+        assert """true""" == graphson_io.writeObject(True)
 
-class TestGraphSONWriter(TestCase):
     def test_numbers(self):
-        assert {"@type": "g:Int64", "@value": 2} == json.loads(GraphSONWriter.writeObject(long(2)))
-        assert {"@type": "g:Int32", "@value": 1} == json.loads(GraphSONWriter.writeObject(1))
-        assert {"@type": "g:Float", "@value": 3.2} == json.loads(GraphSONWriter.writeObject(3.2))
-        assert """true""" == GraphSONWriter.writeObject(True)
+        assert {"@type": "g:Int64", "@value": 2} == json.loads(graphson_io.writeObject(long(2)))
+        assert {"@type": "g:Int32", "@value": 1} == json.loads(graphson_io.writeObject(1))
+        assert {"@type": "g:Double", "@value": 3.2} == json.loads(graphson_io.writeObject(3.2))
+        assert """true""" == graphson_io.writeObject(True)
 
     def test_P(self):
-        assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == GraphSONWriter.writeObject(
+        assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == graphson_io.writeObject(
             P.lt("b").or_(P.gt("c")).and_(P.neq("d")))
 
     def test_strategies(self):
         # we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
-        assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(GraphSONWriter.writeObject(SubgraphStrategy))
+        assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(graphson_io.writeObject(SubgraphStrategy))
         assert {"@type": "g:SubgraphStrategy", "@value": {
             "vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
-            GraphSONWriter.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
-
+            graphson_io.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
+
+    def test_custom_mapping(self):
+
+        # extended mapping
+        class X(object):
+            pass
+
+        type_string = "test:Xtype"
+        override_string = "g:Int64"
+        serdes = Mock()
+
+        gio = GraphSONIO(serializer_map={X: serdes}, deserializer_map={type_string: serdes, })
+        self.assertIn(X, gio.serializers)
+        self.assertIn(type_string, gio.deserializers)
+
+        # base dicts are not modified
+        self.assertNotIn(X, gremlin_python.structure.io.graphson._serializers)
+        self.assertNotIn(type_string, gremlin_python.structure.io.graphson._deserializers)
+
+        obj = X()
+        d = gio.toDict(obj)
+        serdes.dictify.assert_called_once_with(obj, gio)
+        self.assertIs(d, serdes.dictify())
+
+        o = gio.toObject({GraphSONIO._TYPE_KEY: type_string, GraphSONIO._VALUE_KEY: obj})
+        serdes.objectify.assert_called_once_with(obj, gio)
+        self.assertIs(o, serdes.objectify())
+
+        # overridden mapping
+        type_string = "g:Int64"
+        serdes = Mock()
+        gio = GraphSONIO(serializer_map={int: serdes}, deserializer_map={type_string: serdes, override_string: serdes})
+        self.assertIsNot(gremlin_python.structure.io.graphson._serializers[int], gio.serializers[int])
+        self.assertIsNot(gremlin_python.structure.io.graphson._deserializers[type_string], gio.deserializers[type_string])
+
+        value = 3
+        d = gio.toDict(value)
+        serdes.dictify.assert_called_once_with(value, gio)
+        self.assertIs(d, serdes.dictify())
+
+        o = gio.toObject({GraphSONIO._TYPE_KEY: type_string, GraphSONIO._VALUE_KEY: value})
+        serdes.objectify.assert_called_once_with(value, gio)
+        self.assertIs(o, serdes.objectify())
 
 if __name__ == '__main__':
     unittest.main()

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
index e71d3e6..d5305dc 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonScriptEngineSetup.java
@@ -49,8 +49,8 @@ public class JythonScriptEngineSetup {
             jythonEngine.eval("from gremlin_python.structure.graph import Edge");
             jythonEngine.eval("from gremlin_python.structure.graph import VertexProperty");
             jythonEngine.eval("from gremlin_python.structure.graph import Property");
-            jythonEngine.eval("from gremlin_python.structure.io.graphson import GraphSONWriter");
-            jythonEngine.eval("from gremlin_python.structure.io.graphson import GraphSONReader");
+            jythonEngine.eval("from gremlin_python.structure.io.graphson import GraphSONIO");
+            jythonEngine.eval("graphson_io = GraphSONIO()");
             return jythonEngine;
         } catch (final ScriptException e) {
             throw new IllegalStateException(e.getMessage(), e);

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
index 8bb5330..e57afd2 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonGraphSONJavaTranslator.java
@@ -69,7 +69,7 @@ final class PythonGraphSONJavaTranslator<S extends TraversalSource, T extends Tr
             bindings.putAll(jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE));
             bindings.put(this.pythonTranslator.getTraversalSource(), jythonEngine.eval("Graph().traversal()"));
             bindings.putAll(bytecode.getBindings());
-            final String graphsonBytecode = jythonEngine.eval("GraphSONWriter.writeObject(" + this.pythonTranslator.translate(bytecode) + ")", bindings).toString();
+            final String graphsonBytecode = jythonEngine.eval("graphson_io.writeObject(" + this.pythonTranslator.translate(bytecode) + ")", bindings).toString();
             // System.out.println(graphsonBytecode);
             return this.javaTranslator.translate(this.reader.readObject(new ByteArrayInputStream(graphsonBytecode.getBytes()), Bytecode.class));
         } catch (final Exception e) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
index 171fd04..7bbf364 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONReaderTest.java
@@ -60,49 +60,49 @@ public class GraphSONReaderTest {
     public void shouldDeserializeGraphObjects() throws Exception {
         final Vertex vertex = g.V(1).next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(vertex));
-        assertEquals(vertex.toString(), jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),Vertex)"));
+        assertEquals(vertex.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Vertex)"));
         //
         final Edge edge = g.V(1).outE("created").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(edge));
-        assertEquals(edge.toString(), jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),Edge)"));
+        assertEquals(edge.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Edge)"));
         //
         final VertexProperty vertexProperty = (VertexProperty) g.V(1).properties("name").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(vertexProperty));
-        assertEquals(vertexProperty.toString(), jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),VertexProperty)"));
+        assertEquals(vertexProperty.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),VertexProperty)"));
         //
         final Property property = g.V(1).outE("created").properties("weight").next();
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(property));
-        assertEquals(property.toString(), jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),Property)"));
+        assertEquals(property.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Property)"));
         //
         final Traverser<Vertex> traverser = new DefaultRemoteTraverser<>(vertex, 3L);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(traverser));
-        assertEquals(traverser.toString(), jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertEquals(BigInteger.valueOf(3L), jythonEngine.eval("GraphSONReader.readObject(x).bulk")); // jython uses big integer in Java
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x).object,Vertex)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),Traverser)"));
+        assertEquals(traverser.toString(), jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertEquals(BigInteger.valueOf(3L), jythonEngine.eval("graphson_io.readObject(x).bulk")); // jython uses big integer in Java
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x).object,Vertex)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),Traverser)"));
     }
 
     @Test
     public void shouldDeserializeNumbers() throws Exception {
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1));
-        assertEquals("1", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),int)"));
+        assertEquals("1", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),int)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1L));
-        assertEquals("1", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),long)"));
+        assertEquals("1", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),long)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1.2f));
-        assertEquals("1.2", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),float)"));
+        assertEquals("1.2", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),float)"));
         //
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(1.3d));
-        assertEquals("1.3", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x),float)"));
+        assertEquals("1.3", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x),float)"));
     }
 
     @Test
@@ -111,23 +111,23 @@ public class GraphSONReaderTest {
         map.put("a", 2);
         map.put("b", 2.3d);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(map));
-        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertEquals(2, jythonEngine.eval("GraphSONReader.readObject(x)['a']"));
-        assertEquals(2.3d, jythonEngine.eval("GraphSONReader.readObject(x)['b']")); // jython is smart about double
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)['a'],int)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)['b'],float)"));
+        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertEquals(2, jythonEngine.eval("graphson_io.readObject(x)['a']"));
+        assertEquals(2.3d, jythonEngine.eval("graphson_io.readObject(x)['b']")); // jython is smart about double
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)['a'],int)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)['b'],float)"));
         //
         final List<Object> list = Arrays.asList(g.V(1).next(), "hello", map, true);
         jythonEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("x", mapper.writeValueAsString(list));
-        assertEquals("[v[1], u'hello', {u'a': 2, u'b': 2.3}, True]", jythonEngine.eval("str(GraphSONReader.readObject(x))"));
-        assertEquals(g.V(1).next().toString(), jythonEngine.eval("str(GraphSONReader.readObject(x)[0])"));
-        assertEquals("hello", jythonEngine.eval("GraphSONReader.readObject(x)[1]"));
-        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(GraphSONReader.readObject(x)[2])"));
-        assertTrue((Boolean) jythonEngine.eval("GraphSONReader.readObject(x)[3]"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)[0],Vertex)"));
-        // assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)[1],str)")); // its python unicode jython object
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)[2],dict)"));
-        assertTrue((Boolean) jythonEngine.eval("isinstance(GraphSONReader.readObject(x)[3],bool)"));
+        assertEquals("[v[1], u'hello', {u'a': 2, u'b': 2.3}, True]", jythonEngine.eval("str(graphson_io.readObject(x))"));
+        assertEquals(g.V(1).next().toString(), jythonEngine.eval("str(graphson_io.readObject(x)[0])"));
+        assertEquals("hello", jythonEngine.eval("graphson_io.readObject(x)[1]"));
+        assertEquals("{u'a': 2, u'b': 2.3}", jythonEngine.eval("str(graphson_io.readObject(x)[2])"));
+        assertTrue((Boolean) jythonEngine.eval("graphson_io.readObject(x)[3]"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[0],Vertex)"));
+        // assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[1],str)")); // its python unicode jython object
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[2],dict)"));
+        assertTrue((Boolean) jythonEngine.eval("isinstance(graphson_io.readObject(x)[3],bool)"));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d392379e/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
index 0ef3158..01e8c23 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
@@ -56,75 +56,75 @@ public class GraphSONWriterTest {
 
     @Test
     public void shouldSerializeNumbers() throws Exception {
-        assertEquals(1, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(1)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(1), jythonEngine.eval("GraphSONWriter.writeObject(1)").toString().replace(" ", ""));
+        assertEquals(1, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(1)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(1), jythonEngine.eval("graphson_io.writeObject(1)").toString().replace(" ", ""));
         //
-        assertEquals(2L, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(2L)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(2L), jythonEngine.eval("GraphSONWriter.writeObject(2L)").toString().replace(" ", ""));
+        assertEquals(2L, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(2L)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(2L), jythonEngine.eval("graphson_io.writeObject(2L)").toString().replace(" ", ""));
         //
-        assertEquals(3.4f, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(3.4)").toString(), Object.class));
-        assertEquals(mapper.writeValueAsString(3.4f), jythonEngine.eval("GraphSONWriter.writeObject(3.4)").toString().replace(" ", ""));
+        assertEquals(3.4, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(3.4)").toString(), Object.class));
+        assertEquals(mapper.writeValueAsString(3.4), jythonEngine.eval("graphson_io.writeObject(3.4)").toString().replace(" ", ""));
     }
 
     @Test
     public void shouldSerializeCollections() throws Exception {
         final Map<String, Number> map = new LinkedHashMap<>();
         map.put("a", 2);
-        map.put("b", 2.3f);
-        assertEquals(map, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject({'a':2,'b':2.3})").toString(), Object.class));
+        map.put("b", 2.3);
+        assertEquals(map, mapper.readValue(jythonEngine.eval("graphson_io.writeObject({'a':2,'b':2.3})").toString(), Object.class));
         //
         final List<Object> list = Arrays.asList(new DefaultRemoteTraverser<>("hello", 3L), "hello", map, true);
         assertTrue((Boolean) jythonEngine.eval("isinstance([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True],list)"));
-        assertEquals(list, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True])").toString(), Object.class));
+        assertEquals(list, mapper.readValue(jythonEngine.eval("graphson_io.writeObject([Traverser('hello',3L),'hello',{'a':2,'b':2.3},True])").toString(), Object.class));
     }
 
     @Test
     public void shouldSerializeTraverser() throws Exception {
         assertEquals(
                 new DefaultRemoteTraverser<>("hello", 3L),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Traverser('hello',3L))").toString(), Object.class));
-        assertEquals(3L, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Traverser('hello',3L))").toString(), Traverser.class).bulk());
-        assertEquals("hello", mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Traverser('hello',3L))").toString(), Traverser.class).get());
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Object.class));
+        assertEquals(3L, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Traverser.class).bulk());
+        assertEquals("hello", mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Traverser('hello',3L))").toString(), Traverser.class).get());
     }
 
     @Test
     public void shouldSerializeBytecode() throws Exception {
-        assertEquals(P.eq(7L), mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L))").toString(), Object.class));
-        // TODO: assertEquals(mapper.writeValueAsString(P.between(1, 2).and(P.eq(7L))), jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L)._and(P.between(1,2)))").toString().replace(" ",""));
-        assertEquals(AndP.class, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(P.eq(7L).and_(P.between(1,2)))").toString(), Object.class).getClass());
+        assertEquals(P.eq(7L), mapper.readValue(jythonEngine.eval("graphson_io.writeObject(P.eq(7L))").toString(), Object.class));
+        // TODO: assertEquals(mapper.writeValueAsString(P.between(1, 2).and(P.eq(7L))), jythonEngine.eval("graphson_io.writeObject(P.eq(7L)._and(P.between(1,2)))").toString().replace(" ",""));
+        assertEquals(AndP.class, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(P.eq(7L).and_(P.between(1,2)))").toString(), Object.class).getClass());
         //
-        assertEquals(new Bytecode.Binding<>("a", 5L), mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Binding('a',5L))").toString(), Object.class));
+        assertEquals(new Bytecode.Binding<>("a", 5L), mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Binding('a',5L))").toString(), Object.class));
         //
         for (final Column t : Column.values()) {
-            assertEquals(t, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Column." + t.name() + ")").toString(), Object.class));
+            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Column." + t.name() + ")").toString(), Object.class));
         }
         for (final T t : T.values()) {
-            assertEquals(t, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(T." + t.name() + ")").toString(), Object.class));
+            assertEquals(t, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(T." + t.name() + ")").toString(), Object.class));
         }
-        assertEquals(Pop.first, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.first)").toString(), Object.class));
-        assertEquals(Pop.last, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.last)").toString(), Object.class));
-        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.all_)").toString(), Object.class));
-        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope.global_)").toString(), Object.class));
-        assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope.local)").toString(), Object.class));
+        assertEquals(Pop.first, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.first)").toString(), Object.class));
+        assertEquals(Pop.last, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.last)").toString(), Object.class));
+        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Pop.all_)").toString(), Object.class));
+        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Scope.global_)").toString(), Object.class));
+        assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("graphson_io.writeObject(Scope.local)").toString(), Object.class));
     }
 
     @Test
     public void shouldSerializeLambda() throws Exception {
         assertEquals(
                 Lambda.function("lambda z : 1+2", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'z : 1+2')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'z : 1+2')").toString(), Object.class));
         assertEquals(
                 Lambda.function("lambda z : z+ 7", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'lambda z : z+ 7')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z : z+ 7')").toString(), Object.class));
         assertEquals(
                 Lambda.supplier("lambda : 23", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'lambda : 23')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda : 23')").toString(), Object.class));
         assertEquals(
                 Lambda.consumer("lambda z : z + 23", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'lambda z : z + 23')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z : z + 23')").toString(), Object.class));
         assertEquals(
                 Lambda.biFunction("lambda z,y : z - y + 2", "gremlin-python"),
-                mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(lambda : 'lambda z,y : z - y + 2')").toString(), Object.class));
+                mapper.readValue(jythonEngine.eval("graphson_io.writeObject(lambda : 'lambda z,y : z - y + 2')").toString(), Object.class));
     }
 
 }


[06/10] tinkerpop git commit: remove GraphSONWriter and print statement

Posted by ok...@apache.org.
remove GraphSONWriter and print statement


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

Branch: refs/heads/master
Commit: 2ce68df6367a9c45c80aa740b3321b868f9834ea
Parents: d392379
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Thu Oct 6 13:03:47 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 16:20:25 2016 -0500

----------------------------------------------------------------------
 .../main/jython/tests/driver/test_driver_remote_connection.py    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2ce68df6/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index 1fd28ae..f65255b 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -32,7 +32,6 @@ from gremlin_python.process.traversal import TraversalStrategy
 from gremlin_python.process.graph_traversal import __
 from gremlin_python.structure.graph import Graph
 from gremlin_python.structure.graph import Vertex
-from gremlin_python.structure.io.graphson import GraphSONWriter
 from gremlin_python.process.strategies import SubgraphStrategy
 
 
@@ -72,7 +71,6 @@ class TestDriverRemoteConnection(TestCase):
             withStrategies(TraversalStrategy("SubgraphStrategy",
                                              {"vertices": __.hasLabel("person"),
                                               "edges": __.hasLabel("created")}))
-        print GraphSONWriter.writeObject(g.bytecode)
         assert 4 == g.V().count().next()
         assert 0 == g.E().count().next()
         assert 1 == g.V().label().dedup().count().next()
@@ -87,7 +85,7 @@ class TestDriverRemoteConnection(TestCase):
         assert "person" == g.V().label().dedup().next()
         #
         g = g.withoutStrategies(SubgraphStrategy). \
-            withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0))
+            withComputer({"workers": 4, "vertices": __.has("name", "marko"), "edges": __.limit(0)})
         assert 1 == g.V().count().next()
         assert 0 == g.E().count().next()
         assert "person" == g.V().label().next()


[04/10] tinkerpop git commit: simplification in graphson io

Posted by ok...@apache.org.
simplification in graphson io


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

Branch: refs/heads/master
Commit: 6c4bf0b71426b7c5cf5f7a34b5eec23b0d9b8b80
Parents: 697e24f
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Fri Sep 30 13:22:37 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 15:30:44 2016 -0500

----------------------------------------------------------------------
 .../jython/gremlin_python/structure/io/graphson.py     | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6c4bf0b7/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 2f81827..b44897a 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -44,9 +44,9 @@ __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
 class GraphSONWriter(object):
     @staticmethod
     def _dictify(obj):
-        for key in serializers:
+        for key, serializer in serializers.items():
             if isinstance(obj, key):
-                return serializers[key]._dictify(obj)
+                return serializer._dictify(obj)
         # list and map are treated as normal json objs (could be isolated serializers)
         if isinstance(obj, (list, set)):
             return [GraphSONWriter._dictify(o) for o in obj]
@@ -64,10 +64,10 @@ class GraphSONReader(object):
     @staticmethod
     def _objectify(obj):
         if isinstance(obj, dict):
-            if _SymbolHelper._TYPE in obj:
-                type = obj[_SymbolHelper._TYPE]
-                if type in deserializers:
-                    return deserializers[type]._objectify(obj)
+            try:
+                return deserializers[obj[_SymbolHelper._TYPE]]._objectify(obj)
+            except KeyError:
+                pass
             # list and map are treated as normal json objs (could be isolated deserializers)
             return dict((GraphSONReader._objectify(k), GraphSONReader._objectify(v)) for k, v in obj.items())
         elif isinstance(obj, list):
@@ -264,7 +264,6 @@ class _SymbolHelper(object):
             object[_SymbolHelper._VALUE] = value
         return object
 
-
 serializers = {
     Traversal: BytecodeSerializer(),
     Traverser: TraverserSerializer(),


[02/10] tinkerpop git commit: gremlinpython: remove keyword shadows in graphson

Posted by ok...@apache.org.
gremlinpython: remove keyword shadows in graphson


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

Branch: refs/heads/master
Commit: 6931f1293a6034e1521a28cae7a8193959e20dd8
Parents: 0846b8d
Author: Adam Holmberg <Ad...@datastax.com>
Authored: Fri Sep 23 14:38:23 2016 -0500
Committer: Adam Holmberg <Ad...@datastax.com>
Committed: Mon Oct 10 15:30:43 2016 -0500

----------------------------------------------------------------------
 .../gremlin_python/structure/io/graphson.py     | 84 ++++++++++----------
 1 file changed, 42 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6931f129/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index 30aa47f..4676539 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -87,15 +87,15 @@ SERIALIZERS
 
 class GraphSONSerializer(object):
     @abstractmethod
-    def _dictify(self, object):
-        return object
+    def _dictify(self, obj):
+        return obj
 
 
 class BytecodeSerializer(GraphSONSerializer):
     def _dictify(self, bytecode):
         if isinstance(bytecode, Traversal):
             bytecode = bytecode.bytecode
-        dict = {}
+        out = {}
         sources = []
         for instruction in bytecode.source_instructions:
             inst = []
@@ -111,10 +111,10 @@ class BytecodeSerializer(GraphSONSerializer):
                 inst.append(GraphSONWriter._dictify(arg))
             steps.append(inst)
         if len(sources) > 0:
-            dict["source"] = sources
+            out["source"] = sources
         if len(steps) > 0:
-            dict["step"] = steps
-        return _SymbolHelper.objectify("Bytecode", dict)
+            out["step"] = steps
+        return _SymbolHelper.objectify("Bytecode", out)
 
 
 class TraversalStrategySerializer(GraphSONSerializer):
@@ -136,39 +136,39 @@ class EnumSerializer(GraphSONSerializer):
 
 class PSerializer(GraphSONSerializer):
     def _dictify(self, p):
-        dict = {}
-        dict["predicate"] = p.operator
+        out = {}
+        out["predicate"] = p.operator
         if p.other is None:
-            dict["value"] = GraphSONWriter._dictify(p.value)
+            out["value"] = GraphSONWriter._dictify(p.value)
         else:
-            dict["value"] = [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)]
-        return _SymbolHelper.objectify("P", dict)
+            out["value"] = [GraphSONWriter._dictify(p.value), GraphSONWriter._dictify(p.other)]
+        return _SymbolHelper.objectify("P", out)
 
 
 class BindingSerializer(GraphSONSerializer):
     def _dictify(self, binding):
-        dict = {}
-        dict["key"] = binding.key
-        dict["value"] = GraphSONWriter._dictify(binding.value)
-        return _SymbolHelper.objectify("Binding", dict)
+        out = {}
+        out["key"] = binding.key
+        out["value"] = GraphSONWriter._dictify(binding.value)
+        return _SymbolHelper.objectify("Binding", out)
 
 
 class LambdaSerializer(GraphSONSerializer):
-    def _dictify(self, lambdaObject):
-        lambda_result = lambdaObject()
-        dict = {}
+    def _dictify(self, lambda_object):
+        lambda_result = lambda_object()
+        out = {}
         script = lambda_result if isinstance(lambda_result, str) else lambda_result[0]
         language = statics.default_lambda_language if isinstance(lambda_result, str) else lambda_result[1]
-        dict["script"] = script
-        dict["language"] = language
+        out["script"] = script
+        out["language"] = language
         if language == "gremlin-jython" or language == "gremlin-python":
             if not script.strip().startswith("lambda"):
                 script = "lambda " + script
-                dict["script"] = script
-            dict["arguments"] = six.get_function_code(eval(dict["script"])).co_argcount
+                out["script"] = script
+            out["arguments"] = six.get_function_code(eval(out["script"])).co_argcount
         else:
-            dict["arguments"] = -1
-        return _SymbolHelper.objectify("Lambda", dict)
+            out["arguments"] = -1
+        return _SymbolHelper.objectify("Lambda", out)
 
 
 class TypeSerializer(GraphSONSerializer):
@@ -198,20 +198,20 @@ DESERIALIZERS
 
 class GraphSONDeserializer(object):
     @abstractmethod
-    def _objectify(self, dict):
-        return dict
+    def _objectify(self, d):
+        return d
 
 
 class TraverserDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        return Traverser(GraphSONReader._objectify(dict[_SymbolHelper._VALUE]["value"]),
-                         GraphSONReader._objectify(dict[_SymbolHelper._VALUE]["bulk"]))
+    def _objectify(self, d):
+        return Traverser(GraphSONReader._objectify(d[_SymbolHelper._VALUE]["value"]),
+                         GraphSONReader._objectify(d[_SymbolHelper._VALUE]["bulk"]))
 
 
 class NumberDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        type = dict[_SymbolHelper._TYPE]
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        type = d[_SymbolHelper._TYPE]
+        value = d[_SymbolHelper._VALUE]
         if type == "g:Int32":
             return int(value)
         elif type == "g:Int64":
@@ -221,14 +221,14 @@ class NumberDeserializer(GraphSONDeserializer):
 
 
 class VertexDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        value = d[_SymbolHelper._VALUE]
         return Vertex(GraphSONReader._objectify(value["id"]), value["label"] if "label" in value else "")
 
 
 class EdgeDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        value = d[_SymbolHelper._VALUE]
         return Edge(GraphSONReader._objectify(value["id"]),
                     Vertex(GraphSONReader._objectify(value["outV"]), ""),
                     value["label"] if "label" in value else "vertex",
@@ -236,21 +236,21 @@ class EdgeDeserializer(GraphSONDeserializer):
 
 
 class VertexPropertyDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        value = d[_SymbolHelper._VALUE]
         return VertexProperty(GraphSONReader._objectify(value["id"]), value["label"],
                               GraphSONReader._objectify(value["value"]))
 
 
 class PropertyDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        value = d[_SymbolHelper._VALUE]
         return Property(value["key"], GraphSONReader._objectify(value["value"]))
 
 
 class PathDeserializer(GraphSONDeserializer):
-    def _objectify(self, dict):
-        value = dict[_SymbolHelper._VALUE]
+    def _objectify(self, d):
+        value = d[_SymbolHelper._VALUE]
         labels = []
         objects = []
         for label in value["labels"]: