You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2019/09/04 13:22:27 UTC
[tinkerpop] 17/40: Added traverser, byte,
bytearray to python graphbinary
This is an automated email from the ASF dual-hosted git repository.
spmallette pushed a commit to branch TINKERPOP-2279
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 6bb645ed4a9082d9c894cd51a761accb9c8956a4
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Aug 2 06:39:56 2019 -0400
Added traverser, byte, bytearray to python graphbinary
---
.../gremlin_python/structure/io/graphbinaryV1.py | 51 +++++++++++++++++++++-
.../tests/structure/io/test_graphbinaryV1.py | 12 ++++-
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
index edb1136..208a1e3 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphbinaryV1.py
@@ -85,6 +85,11 @@ class DataType(Enum):
p = 0x1e
scope = 0x1f
t = 0x20
+ traverser = 0x21
+ bigdecimal = 0x22 #todo
+ biginteger = 0x23 #todo
+ byte = 0x24
+ bytebuffer = 0x25
class GraphBinaryTypeType(type):
@@ -702,4 +707,48 @@ class ScopeIO(_EnumIO):
class TIO(_EnumIO):
graphbinary_type = DataType.t
- python_type = T
\ No newline at end of file
+ python_type = T
+
+
+class TraverserIO(_GraphBinaryTypeIO):
+ graphbinary_type = DataType.traverser
+ python_type = Traverser
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(struct.pack(">i", obj.bulk))
+ ba.extend(writer.writeObject(obj.object))
+
+ return ba
+
+
+class ByteIO(_GraphBinaryTypeIO):
+ python_type = SingleByte
+ graphbinary_type = DataType.byte
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(struct.pack(">b", obj))
+ return ba
+
+ @classmethod
+ def objectify(cls, b, reader):
+ return int.__new__(SingleByte, struct.unpack_from(">b", b.read(1))[0])
+
+
+class ByteBufferIO(_GraphBinaryTypeIO):
+ python_type = ByteBufferType
+ graphbinary_type = DataType.bytebuffer
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ return cls.as_bytes(cls.graphbinary_type, len(obj), obj)
+
+ @classmethod
+ def objectify(cls, b, reader):
+ size = cls.read_int(b)
+ return ByteBufferType(b.read(size))
+
+
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py
index c9ce87e..4c827ad 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphbinaryV1.py
@@ -28,7 +28,7 @@ from mock import Mock
import six
-from gremlin_python.statics import timestamp, long
+from gremlin_python.statics import timestamp, long, SingleByte, SingleChar, ByteBufferType
from gremlin_python.structure.graph import Vertex, Edge, Property, VertexProperty, Graph, Path
from gremlin_python.structure.io.graphbinaryV1 import GraphBinaryWriter, GraphBinaryReader, DataType
from gremlin_python.process.traversal import P, Barrier, Binding, Bytecode
@@ -168,4 +168,14 @@ class TestGraphSONWriter(object):
output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
assert x == output
+ def test_byte(self):
+ x = int.__new__(SingleByte, 1)
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output
+
+ def test_bytebuffer(self):
+ x = ByteBufferType("c29tZSBieXRlcyBmb3IgeW91", "utf8")
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output
+