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/08/09 19:13:16 UTC
[tinkerpop] 18/23: Added boolean and textp 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 e778a8d872d1f141d9a89b8d64cbc336972e2a36
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Aug 2 07:03:40 2019 -0400
Added boolean and textp to python graphbinary
---
.../gremlin_python/structure/io/graphbinaryV1.py | 39 ++++++++++++++++++++++
.../tests/structure/io/test_graphbinaryV1.py | 9 +++++
2 files changed, 48 insertions(+)
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 208a1e3..2f64ba2 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
@@ -90,6 +90,15 @@ class DataType(Enum):
biginteger = 0x23 #todo
byte = 0x24
bytebuffer = 0x25
+ short = 0x26 #todo?
+ boolean = 0x27
+ textp = 0x28
+ traversalstrategy = 0x29
+ bulkset = 0x2a
+ tree = 0x2b
+ metrics = 0x2c
+ traversalmetrics = 0x2d
+ custom = 0x00
class GraphBinaryTypeType(type):
@@ -752,3 +761,33 @@ class ByteBufferIO(_GraphBinaryTypeIO):
return ByteBufferType(b.read(size))
+class BooleanIO(_GraphBinaryTypeIO):
+ python_type = bool
+ graphbinary_type = DataType.boolean
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(struct.pack(">b", 0x01 if obj else 0x00))
+ return ba
+
+ @classmethod
+ def objectify(cls, b, reader):
+ return True if struct.unpack_from(">b", b.read(1))[0] == 0x01 else False
+
+
+class TextPIO(_GraphBinaryTypeIO):
+ graphbinary_type = DataType.textp
+ python_type = TextP
+
+ @classmethod
+ def dictify(cls, obj, writer):
+ ba = bytearray([cls.graphbinary_type.value])
+ ba.extend(cls.string_as_bytes(obj.operator))
+ additional = [writer.writeObject(obj.value), writer.writeObject(obj.other)] \
+ if obj.other is not None else [writer.writeObject(obj.value)]
+ ba.extend(struct.pack(">i", len(additional)))
+ for a in additional:
+ ba.extend(a)
+
+ return ba
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 4c827ad..620c3fc 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
@@ -178,4 +178,13 @@ class TestGraphSONWriter(object):
output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
assert x == output
+ def test_boolean(self):
+ x = True
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output
+
+ x = False
+ output = self.graphbinary_reader.readObject(self.graphbinary_writer.writeObject(x))
+ assert x == output
+