tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [tinkerpop] branch TINKERPOP-1435 updated: TINKERPOP-1435 Add ByteBuffer support in GraphSON for python
Date Fri, 08 Feb 2019 15:42:32 GMT
This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-1435
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/TINKERPOP-1435 by this push:
     new 1f17eaf  TINKERPOP-1435 Add ByteBuffer support in GraphSON for python
1f17eaf is described below

commit 1f17eaf89ae3fbb55f37cdf02130832e2fad9336
Author: Stephen Mallette <spmva@genoprime.com>
AuthorDate: Fri Feb 8 10:41:49 2019 -0500

    TINKERPOP-1435 Add ByteBuffer support in GraphSON for python
---
 .../src/main/jython/gremlin_python/statics.py           |  2 ++
 .../jython/gremlin_python/structure/io/graphsonV2d0.py  | 17 ++++++++++++++++-
 .../jython/gremlin_python/structure/io/graphsonV3d0.py  | 17 ++++++++++++++++-
 .../main/jython/tests/structure/io/test_graphsonV2d0.py | 12 ++++++++++++
 .../main/jython/tests/structure/io/test_graphsonV3d0.py | 12 ++++++++++++
 5 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/gremlin-python/src/main/jython/gremlin_python/statics.py b/gremlin-python/src/main/jython/gremlin_python/statics.py
index 61b8f3e..9ab7286 100644
--- a/gremlin-python/src/main/jython/gremlin_python/statics.py
+++ b/gremlin-python/src/main/jython/gremlin_python/statics.py
@@ -32,9 +32,11 @@ if six.PY3:
     ListType = list
     DictType = dict
     SetType = set
+    ByteBufferType = bytes
 else:
     long = long
     SetType = set
+    ByteBufferType = bytearray
     from types import FloatType
     from types import IntType
     from types import LongType
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
index d72cd8f..45bab4c 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV2d0.py
@@ -21,6 +21,7 @@ import json
 import time
 import uuid
 import math
+import base64
 from collections import OrderedDict
 from decimal import *
 
@@ -28,7 +29,7 @@ import six
 from aenum import Enum
 
 from gremlin_python import statics
-from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType,
SingleByte
+from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType,
SingleByte, ByteBufferType
 from gremlin_python.process.traversal import Binding, Bytecode, P, Traversal, Traverser,
TraversalStrategy
 from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path
 
@@ -501,6 +502,20 @@ class ByteIO(_NumberIO):
         return int.__new__(SingleByte, v)
 
 
+class ByteBufferIO(_GraphSONTypeIO):
+    python_type = ByteBufferType
+    graphson_type = "gx:ByteBuffer"
+    graphson_base_type = "ByteBuffer"
+
+    @classmethod
+    def dictify(cls, n, writer):
+        return GraphSONUtil.typedValue(cls.graphson_base_type, "".join(chr(x) for x in n),
"gx")
+
+    @classmethod
+    def objectify(cls, v, _):
+        return cls.python_type(v, "ascii")
+
+
 class VertexDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Vertex"
 
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
index 1a0298b..454074e 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphsonV3d0.py
@@ -21,6 +21,7 @@ import json
 import time
 import uuid
 import math
+import base64
 from collections import OrderedDict
 from decimal import *
 import logging
@@ -29,7 +30,7 @@ import six
 from aenum import Enum
 
 from gremlin_python import statics
-from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType,
DictType, ListType, SetType, SingleByte
+from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType,
DictType, ListType, SetType, SingleByte, ByteBufferType
 from gremlin_python.process.traversal import Binding, Bytecode, P, Traversal, Traverser,
TraversalStrategy, T
 from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path
 
@@ -582,6 +583,20 @@ class ByteIO(_NumberIO):
         return int.__new__(SingleByte, v)
 
 
+class ByteBufferIO(_GraphSONTypeIO):
+    python_type = ByteBufferType
+    graphson_type = "gx:ByteBuffer"
+    graphson_base_type = "ByteBuffer"
+
+    @classmethod
+    def dictify(cls, n, writer):
+        return GraphSONUtil.typedValue(cls.graphson_base_type, "".join(chr(x) for x in n),
"gx")
+
+    @classmethod
+    def objectify(cls, v, _):
+        return cls.python_type(v, "ascii")
+
+
 class VertexDeserializer(_GraphSONTypeIO):
     graphson_type = "g:Vertex"
 
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
index 68fe015..8d3c68c 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV2d0.py
@@ -277,6 +277,12 @@ class TestGraphSONReader(object):
                 {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations':
{'percentDur': 5.967408283024444}, 'id': '3.0.0()'}
                 ]}]
 
+    def test_bytebuffer(self):
+        bb = self.graphson_reader.readObject(
+            json.dumps({"@type": "gx:ByteBuffer", "@value": "c29tZSBieXRlcyBmb3IgeW91"}))
+        assert isinstance(bb, ByteBufferType)
+        assert ByteBufferType("c29tZSBieXRlcyBmb3IgeW91", "ascii") == bb
+
 
 class TestGraphSONWriter(object):
     graphson_writer = GraphSONWriter()
@@ -435,6 +441,12 @@ class TestGraphSONWriter(object):
         output = self.graphson_writer.writeObject(prop)
         assert expected == output
 
+    def test_bytebuffer(self):
+        expected = json.dumps({'@type': 'gx:ByteBuffer', '@value': 'c29tZSBieXRlcyBmb3IgeW91'},
separators=(',', ':'))
+        bb = ByteBufferType("c29tZSBieXRlcyBmb3IgeW91", "ascii")
+        output = self.graphson_writer.writeObject(bb)
+        assert expected == output
+
 
 class TestFunctionalGraphSONIO(object):
     """Functional IO tests"""
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
index 206c03b..af9bf33 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphsonV3d0.py
@@ -315,6 +315,12 @@ class TestGraphSONReader(object):
                 {'dur': 0.087637, 'counts': {}, 'name': 'ReferenceElementStep', 'annotations':
{'percentDur': 5.967408283024444}, 'id': '3.0.0()'}
                 ]}]
 
+    def test_bytebuffer(self):
+        bb = self.graphson_reader.readObject(
+            json.dumps({"@type": "gx:ByteBuffer", "@value": "c29tZSBieXRlcyBmb3IgeW91"}))
+        assert isinstance(bb, ByteBufferType)
+        assert ByteBufferType("c29tZSBieXRlcyBmb3IgeW91", "ascii") == bb
+
 
 class TestGraphSONWriter(object):
     graphson_writer = GraphSONWriter()
@@ -489,6 +495,12 @@ class TestGraphSONWriter(object):
         output = self.graphson_writer.writeObject(prop)
         assert expected == output
 
+    def test_bytebuffer(self):
+        expected = json.dumps({'@type': 'gx:ByteBuffer', '@value': 'c29tZSBieXRlcyBmb3IgeW91'},
separators=(',', ':'))
+        bb = ByteBufferType("c29tZSBieXRlcyBmb3IgeW91", "ascii")
+        output = self.graphson_writer.writeObject(bb)
+        assert expected == output
+
 
 class TestFunctionalGraphSONIO(object):
     """Functional IO tests"""


Mime
View raw message