You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/08/10 20:41:13 UTC

tinkerpop git commit: added Lambda serialization to Gremlin-Pyhton graphson.py. Right now it can only do python lambdas, not Groovy closures.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 0eb8e720c -> 9353adb9b


added Lambda serialization to Gremlin-Pyhton graphson.py. Right now it can only do python lambdas, not Groovy closures.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9353adb9
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9353adb9
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9353adb9

Branch: refs/heads/TINKERPOP-1278
Commit: 9353adb9b7055157e57db308143576a13433dc8d
Parents: 0eb8e72
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Aug 10 14:41:06 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Aug 10 14:41:06 2016 -0600

----------------------------------------------------------------------
 .../src/main/jython/gremlin_python/process/graphson.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9353adb9/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graphson.py b/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
index 871ccfa..b3a1ea1 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graphson.py
@@ -20,6 +20,7 @@ under the License.
 import json
 from abc import abstractmethod
 from aenum import Enum
+from types import FunctionType
 
 from .traversal import Binding
 from .traversal import Bytecode
@@ -105,6 +106,17 @@ class BindingSerializer(GraphSONSerializer):
         return dict
 
 
+class LambdaSerializer(GraphSONSerializer):
+    def _dictify(self, lambdaObject):
+        lambdaString = lambdaObject()
+        dict = {}
+        dict["@type"] = "Lambda"
+        dict["value"] = lambdaString
+        dict["language"] = "gremlin-python"
+        dict["arguments"] = eval(lambdaString).func_code.co_argcount
+        return dict
+
+
 class TraversalSerializer(BytecodeSerializer):
     def _dictify(self, traversal):
         return BytecodeSerializer._dictify(self, traversal.bytecode)
@@ -134,5 +146,6 @@ serializers = {
     Binding: BindingSerializer(),
     P: PSerializer(),
     Enum: EnumSerializer(),
+    FunctionType: LambdaSerializer(),
     Traversal: TraversalSerializer()
 }