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:21 UTC
[tinkerpop] 11/40: Added property/path 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 2dca61ab87fc496f4cb390cb263469cf518dc917
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Wed Jul 31 13:55:52 2019 -0400
Added property/path to python graphbinary
---
.../gremlin_python/structure/io/graphbinaryV1.py | 44 +++++++++++++++++++++-
.../tests/structure/io/test_graphbinaryV1.py | 10 +++++
2 files changed, 52 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 76dfaee..c12ffca 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
@@ -49,6 +49,7 @@ _deserializers = {}
class DataType(Enum):
+ null = 0xfe
int = 0x01
long = 0x02
string = 0x03
@@ -62,6 +63,8 @@ class DataType(Enum):
set = 0x0b
uuid = 0x0c
edge = 0x0d
+ path = 0x0e
+ property = 0x0f
class GraphBinaryTypeType(type):
@@ -392,8 +395,8 @@ class EdgeIO(_GraphBinaryTypeIO):
ba.extend(cls.string_as_bytes(obj.inV.label))
ba.extend(writer.writeObject(obj.outV.id))
ba.extend(cls.string_as_bytes(obj.outV.label))
- ba.extend([0xfe])
- ba.extend([0xfe])
+ ba.extend([DataType.null.value])
+ ba.extend([DataType.null.value])
return ba
@classmethod
@@ -404,3 +407,40 @@ class EdgeIO(_GraphBinaryTypeIO):
edgelbl, Vertex(reader.readObject(b), cls.read_string(b)))
b.read(2)
return edge
+
+
+class PathIO(_GraphBinaryTypeIO):
+
+ python_type = Path
+ graphbinary_type = DataType.path
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(writer.writeObject(obj.labels))
+ ba.extend(writer.writeObject(obj.objects))
+ return ba
+
+ @classmethod
+ def objectify(cls, b, reader):
+ return Path(reader.readObject(b), reader.readObject(b))
+
+
+class PropertyIO(_GraphBinaryTypeIO):
+
+ python_type = Property
+ graphbinary_type = DataType.property
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(cls.string_as_bytes(obj.key))
+ ba.extend(writer.writeObject(obj.value))
+ ba.extend([DataType.null.value])
+ return ba
+
+ @classmethod
+ def objectify(cls, b, reader):
+ p = Property(cls.read_string(b), reader.readObject(b), None)
+ b.read(1)
+ return p
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 f287c01..3c4ef34 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
@@ -129,3 +129,13 @@ class TestGraphSONWriter(object):
x = Edge(123, Vertex(1, 'person'), "developed", Vertex(10, "software"))
output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
assert x == output
+
+ def test_path(self):
+ x = Path(["x", "y", "z"], [1, 2, 3])
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output
+
+ def test_property(self):
+ x = Property("name", "stephen", None)
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output