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 eea1ca3af648d5615b0ba98334d4c75319187eb6 Author: Stephen Mallette <[email protected]> AuthorDate: Wed Jul 31 14:06:23 2019 -0400 Added Graph/Vertex/VertexProperty to python graphbinary --- .../gremlin_python/structure/io/graphbinaryV1.py | 62 +++++++++++++++++++++- .../tests/structure/io/test_graphbinaryV1.py | 10 ++++ 2 files changed, 71 insertions(+), 1 deletion(-) 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 c12ffca..551db60 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 @@ -37,7 +37,7 @@ from isodate import parse_duration, duration_isoformat from gremlin_python import statics from gremlin_python.statics import FloatType, FunctionType, IntType, LongType, TypeType, DictType, ListType, SetType, SingleByte, ByteBufferType, SingleChar from gremlin_python.process.traversal import Binding, Bytecode, P, TextP, Traversal, Traverser, TraversalStrategy, T -from gremlin_python.structure.graph import Edge, Property, Vertex, VertexProperty, Path +from gremlin_python.structure.graph import Graph, Edge, Property, Vertex, VertexProperty, Path log = logging.getLogger(__name__) @@ -65,6 +65,9 @@ class DataType(Enum): edge = 0x0d path = 0x0e property = 0x0f + tinkergraph = 0x10 + vertex = 0x11 + vertexproperty = 0x12 class GraphBinaryTypeType(type): @@ -444,3 +447,60 @@ class PropertyIO(_GraphBinaryTypeIO): p = Property(cls.read_string(b), reader.readObject(b), None) b.read(1) return p + + +class TinkerGraphIO(_GraphBinaryTypeIO): + + python_type = Graph + graphbinary_type = DataType.tinkergraph + + @classmethod + def dictify(cls, obj, writer): + raise AttributeError("TinkerGraph serialization is not currently supported by gremlin-python") + + @classmethod + def objectify(cls, b, reader): + raise AttributeError("TinkerGraph deserialization is not currently supported by gremlin-python") + + +class VertexIO(_GraphBinaryTypeIO): + + python_type = Vertex + graphbinary_type = DataType.vertex + + @classmethod + def dictify(cls, obj, writer): + ba = bytearray([cls.graphbinary_type.value]) + ba.extend(writer.writeObject(obj.id)) + ba.extend(cls.string_as_bytes(obj.label)) + ba.extend([DataType.null.value]) + return ba + + @classmethod + def objectify(cls, b, reader): + vertex = Vertex(reader.readObject(b), cls.read_string(b)) + b.read(1) + return vertex + + +class VertexPropertyIO(_GraphBinaryTypeIO): + + python_type = VertexProperty + graphbinary_type = DataType.vertexproperty + + @classmethod + def dictify(cls, obj, writer): + ba = bytearray([cls.graphbinary_type.value]) + ba.extend(writer.writeObject(obj.id)) + ba.extend(cls.string_as_bytes(obj.label)) + ba.extend(writer.writeObject(obj.value)) + ba.extend([DataType.null.value]) + ba.extend([DataType.null.value]) + return ba + + @classmethod + def objectify(cls, b, reader): + vp = VertexProperty(reader.readObject(b), cls.read_string(b), reader.readObject(b), None) + b.read(1) + b.read(1) + return vp \ No newline at end of file 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 3c4ef34..cdf52fc 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 @@ -139,3 +139,13 @@ class TestGraphSONWriter(object): x = Property("name", "stephen", None) output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) assert x == output + + def test_vertex(self): + x = Vertex(123, "person") + output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) + assert x == output + + def test_vertexproperty(self): + x = VertexProperty(123, "name", "stephen", None) + output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x)) + assert x == output
