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/31 16:46:44 UTC

tinkerpop git commit: Changed the _ prefix for reserved words in Python to a _ postfix. E.g. _as is now as_. Updated tests and documentation accordingly. CTR.

Repository: tinkerpop
Updated Branches:
  refs/heads/master 4e8335ab1 -> a1257e2b6


Changed the _ prefix for reserved words in Python to a _ postfix. E.g. _as is now as_. Updated tests and documentation accordingly. CTR.


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

Branch: refs/heads/master
Commit: a1257e2b6e049eadf4a811905e275790bffce87c
Parents: 4e8335a
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Aug 31 10:46:37 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Aug 31 10:46:37 2016 -0600

----------------------------------------------------------------------
 docs/src/reference/gremlin-variants.asciidoc    |   2 +-
 .../gremlin-language-variants/index.asciidoc    |   8 +-
 .../gremlin/python/jsr223/SymbolHelper.java     |  22 +--
 .../gremlin_python/process/graph_traversal.py   | 138 +++++++++----------
 .../jython/gremlin_python/process/traversal.py  |  34 ++---
 .../gremlin_python/structure/io/graphson.py     |   6 +-
 .../src/main/jython/tests/test_statics.py       |   4 +-
 .../io/graphson/GraphSONWriterTest.java         |   4 +-
 8 files changed, 109 insertions(+), 109 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index ab4910a..efa24a4 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -49,7 +49,7 @@ namespaces (`a(b())` vs `a(__.b())`). As such, anyone familiar with Gremlin-Java
 with Gremlin-Python. Moreover, there are a few added constructs to Gremlin-Python that make traversals a bit more succinct.
 
 WARNING: In Python, `as`, `in`, `and`, `or`, `is`, `not`, `from`, and `global` are reserved words. Gremlin-Python simply
-prefixes `_` in front of these terms for their use with graph traversal. For instance: `g.V()._as('a')._in()._as('b').select('a','b')`.
+postfixes `_` to the end of these terms for their use with graph traversal. For instance: `g.V().as_('a').in_().as_('b').select('a','b')`.
 
 To install Gremlin-Python, use Python's link:https://en.wikipedia.org/wiki/Pip_(package_manager)[pip] package manager.
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/docs/src/tutorials/gremlin-language-variants/index.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/tutorials/gremlin-language-variants/index.asciidoc b/docs/src/tutorials/gremlin-language-variants/index.asciidoc
index 8833733..4605765 100644
--- a/docs/src/tutorials/gremlin-language-variants/index.asciidoc
+++ b/docs/src/tutorials/gremlin-language-variants/index.asciidoc
@@ -560,11 +560,11 @@ Type "help", "copyright", "credits" or "license" for more information.
 [u'peter', u'peter']
 # a complex, nested multi-line traversal
 >>> g.V().match( \
-...     _as("a").out("created")._as("b"), \
-...     _as("b")._in("created")._as("c"), \
-...     _as("a").out("knows")._as("c")). \
+...     as_("a").out("created").as_("b"), \
+...     as_("b").in_("created").as_("c"), \
+...     as_("a").out("knows").as_("c")). \
 ...   select("c"). \
-...   union(_in("knows"),out("created")). \
+...   union(in_("knows"),out("created")). \
 ...   name.toList()
 [u'ripple', u'marko', u'lop']
 >>>

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/SymbolHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/SymbolHelper.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/SymbolHelper.java
index 5264ce7..ce4ad7f 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/SymbolHelper.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/SymbolHelper.java
@@ -31,17 +31,17 @@ public final class SymbolHelper {
     private final static Map<String, String> FROM_PYTHON_MAP = new HashMap<>();
 
     static {
-        TO_PYTHON_MAP.put("global", "_global");
-        TO_PYTHON_MAP.put("as", "_as");
-        TO_PYTHON_MAP.put("in", "_in");
-        TO_PYTHON_MAP.put("and", "_and");
-        TO_PYTHON_MAP.put("or", "_or");
-        TO_PYTHON_MAP.put("is", "_is");
-        TO_PYTHON_MAP.put("not", "_not");
-        TO_PYTHON_MAP.put("from", "_from");
-        TO_PYTHON_MAP.put("list", "_list");
-        TO_PYTHON_MAP.put("set", "_set");
-        TO_PYTHON_MAP.put("all", "_all");
+        TO_PYTHON_MAP.put("global", "global_");
+        TO_PYTHON_MAP.put("as", "as_");
+        TO_PYTHON_MAP.put("in", "in_");
+        TO_PYTHON_MAP.put("and", "and_");
+        TO_PYTHON_MAP.put("or", "or_");
+        TO_PYTHON_MAP.put("is", "is_");
+        TO_PYTHON_MAP.put("not", "not_");
+        TO_PYTHON_MAP.put("from", "from_");
+        TO_PYTHON_MAP.put("list", "list_");
+        TO_PYTHON_MAP.put("set", "set_");
+        TO_PYTHON_MAP.put("all", "all_");
         //
         TO_PYTHON_MAP.forEach((k, v) -> FROM_PYTHON_MAP.put(v, k));
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index 13d2629..96985b7 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -99,27 +99,6 @@ class GraphTraversal(Traversal):
   def V(self, *args):
     self.bytecode.add_step("V", *args)
     return self
-  def _and(self, *args):
-    self.bytecode.add_step("and", *args)
-    return self
-  def _as(self, *args):
-    self.bytecode.add_step("as", *args)
-    return self
-  def _from(self, *args):
-    self.bytecode.add_step("from", *args)
-    return self
-  def _in(self, *args):
-    self.bytecode.add_step("in", *args)
-    return self
-  def _is(self, *args):
-    self.bytecode.add_step("is", *args)
-    return self
-  def _not(self, *args):
-    self.bytecode.add_step("not", *args)
-    return self
-  def _or(self, *args):
-    self.bytecode.add_step("or", *args)
-    return self
   def addE(self, *args):
     self.bytecode.add_step("addE", *args)
     return self
@@ -135,6 +114,12 @@ class GraphTraversal(Traversal):
   def aggregate(self, *args):
     self.bytecode.add_step("aggregate", *args)
     return self
+  def and_(self, *args):
+    self.bytecode.add_step("and", *args)
+    return self
+  def as_(self, *args):
+    self.bytecode.add_step("as", *args)
+    return self
   def barrier(self, *args):
     self.bytecode.add_step("barrier", *args)
     return self
@@ -192,6 +177,9 @@ class GraphTraversal(Traversal):
   def fold(self, *args):
     self.bytecode.add_step("fold", *args)
     return self
+  def from_(self, *args):
+    self.bytecode.add_step("from", *args)
+    return self
   def group(self, *args):
     self.bytecode.add_step("group", *args)
     return self
@@ -231,9 +219,15 @@ class GraphTraversal(Traversal):
   def inV(self, *args):
     self.bytecode.add_step("inV", *args)
     return self
+  def in_(self, *args):
+    self.bytecode.add_step("in", *args)
+    return self
   def inject(self, *args):
     self.bytecode.add_step("inject", *args)
     return self
+  def is_(self, *args):
+    self.bytecode.add_step("is", *args)
+    return self
   def key(self, *args):
     self.bytecode.add_step("key", *args)
     return self
@@ -270,12 +264,18 @@ class GraphTraversal(Traversal):
   def min(self, *args):
     self.bytecode.add_step("min", *args)
     return self
+  def not_(self, *args):
+    self.bytecode.add_step("not", *args)
+    return self
   def option(self, *args):
     self.bytecode.add_step("option", *args)
     return self
   def optional(self, *args):
     self.bytecode.add_step("optional", *args)
     return self
+  def or_(self, *args):
+    self.bytecode.add_step("or", *args)
+    return self
   def order(self, *args):
     self.bytecode.add_step("order", *args)
     return self
@@ -400,24 +400,6 @@ class __(object):
   def __(*args):
     return GraphTraversal(None, None, Bytecode()).__(*args)
   @staticmethod
-  def _and(*args):
-    return GraphTraversal(None, None, Bytecode())._and(*args)
-  @staticmethod
-  def _as(*args):
-    return GraphTraversal(None, None, Bytecode())._as(*args)
-  @staticmethod
-  def _in(*args):
-    return GraphTraversal(None, None, Bytecode())._in(*args)
-  @staticmethod
-  def _is(*args):
-    return GraphTraversal(None, None, Bytecode())._is(*args)
-  @staticmethod
-  def _not(*args):
-    return GraphTraversal(None, None, Bytecode())._not(*args)
-  @staticmethod
-  def _or(*args):
-    return GraphTraversal(None, None, Bytecode())._or(*args)
-  @staticmethod
   def addE(*args):
     return GraphTraversal(None, None, Bytecode()).addE(*args)
   @staticmethod
@@ -433,6 +415,12 @@ class __(object):
   def aggregate(*args):
     return GraphTraversal(None, None, Bytecode()).aggregate(*args)
   @staticmethod
+  def and_(*args):
+    return GraphTraversal(None, None, Bytecode()).and_(*args)
+  @staticmethod
+  def as_(*args):
+    return GraphTraversal(None, None, Bytecode()).as_(*args)
+  @staticmethod
   def barrier(*args):
     return GraphTraversal(None, None, Bytecode()).barrier(*args)
   @staticmethod
@@ -526,9 +514,15 @@ class __(object):
   def inV(*args):
     return GraphTraversal(None, None, Bytecode()).inV(*args)
   @staticmethod
+  def in_(*args):
+    return GraphTraversal(None, None, Bytecode()).in_(*args)
+  @staticmethod
   def inject(*args):
     return GraphTraversal(None, None, Bytecode()).inject(*args)
   @staticmethod
+  def is_(*args):
+    return GraphTraversal(None, None, Bytecode()).is_(*args)
+  @staticmethod
   def key(*args):
     return GraphTraversal(None, None, Bytecode()).key(*args)
   @staticmethod
@@ -565,9 +559,15 @@ class __(object):
   def min(*args):
     return GraphTraversal(None, None, Bytecode()).min(*args)
   @staticmethod
+  def not_(*args):
+    return GraphTraversal(None, None, Bytecode()).not_(*args)
+  @staticmethod
   def optional(*args):
     return GraphTraversal(None, None, Bytecode()).optional(*args)
   @staticmethod
+  def or_(*args):
+    return GraphTraversal(None, None, Bytecode()).or_(*args)
+  @staticmethod
   def order(*args):
     return GraphTraversal(None, None, Bytecode()).order(*args)
   @staticmethod
@@ -679,36 +679,6 @@ def V(*args):
 
 statics.add_static('V', V)
 
-def _and(*args):
-      return __._and(*args)
-
-statics.add_static('_and', _and)
-
-def _as(*args):
-      return __._as(*args)
-
-statics.add_static('_as', _as)
-
-def _in(*args):
-      return __._in(*args)
-
-statics.add_static('_in', _in)
-
-def _is(*args):
-      return __._is(*args)
-
-statics.add_static('_is', _is)
-
-def _not(*args):
-      return __._not(*args)
-
-statics.add_static('_not', _not)
-
-def _or(*args):
-      return __._or(*args)
-
-statics.add_static('_or', _or)
-
 def addE(*args):
       return __.addE(*args)
 
@@ -734,6 +704,16 @@ def aggregate(*args):
 
 statics.add_static('aggregate', aggregate)
 
+def and_(*args):
+      return __.and_(*args)
+
+statics.add_static('and_', and_)
+
+def as_(*args):
+      return __.as_(*args)
+
+statics.add_static('as_', as_)
+
 def barrier(*args):
       return __.barrier(*args)
 
@@ -889,11 +869,21 @@ def inV(*args):
 
 statics.add_static('inV', inV)
 
+def in_(*args):
+      return __.in_(*args)
+
+statics.add_static('in_', in_)
+
 def inject(*args):
       return __.inject(*args)
 
 statics.add_static('inject', inject)
 
+def is_(*args):
+      return __.is_(*args)
+
+statics.add_static('is_', is_)
+
 def key(*args):
       return __.key(*args)
 
@@ -954,11 +944,21 @@ def min(*args):
 
 statics.add_static('min', min)
 
+def not_(*args):
+      return __.not_(*args)
+
+statics.add_static('not_', not_)
+
 def optional(*args):
       return __.optional(*args)
 
 statics.add_static('optional', optional)
 
+def or_(*args):
+      return __.or_(*args)
+
+statics.add_static('or_', or_)
+
 def order(*args):
       return __.order(*args)
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
index 2dc929a..0302047 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
@@ -77,10 +77,10 @@ class Traversal(object):
 Barrier = Enum('Barrier', 'normSack')
 statics.add_static('normSack', Barrier.normSack)
 
-Cardinality = Enum('Cardinality', '_list _set single')
+Cardinality = Enum('Cardinality', 'list_ set_ single')
 statics.add_static('single', Cardinality.single)
-statics.add_static('_list', Cardinality._list)
-statics.add_static('_set', Cardinality._set)
+statics.add_static('list_', Cardinality.list_)
+statics.add_static('set_', Cardinality.set_)
 
 Column = Enum('Column', 'keys values')
 statics.add_static('keys', Column.keys)
@@ -91,7 +91,7 @@ statics.add_static('OUT', Direction.OUT)
 statics.add_static('IN', Direction.IN)
 statics.add_static('BOTH', Direction.BOTH)
 
-Operator = Enum('Operator', 'addAll _and assign div max min minus mult _or sum sumLong')
+Operator = Enum('Operator', 'addAll and_ assign div max min minus mult or_ sum sumLong')
 statics.add_static('sum', Operator.sum)
 statics.add_static('minus', Operator.minus)
 statics.add_static('mult', Operator.mult)
@@ -99,8 +99,8 @@ statics.add_static('div', Operator.div)
 statics.add_static('min', Operator.min)
 statics.add_static('max', Operator.max)
 statics.add_static('assign', Operator.assign)
-statics.add_static('_and', Operator._and)
-statics.add_static('_or', Operator._or)
+statics.add_static('and_', Operator.and_)
+statics.add_static('or_', Operator.or_)
 statics.add_static('addAll', Operator.addAll)
 statics.add_static('sumLong', Operator.sumLong)
 
@@ -113,13 +113,13 @@ statics.add_static('keyDecr', Order.keyDecr)
 statics.add_static('valueDecr', Order.valueDecr)
 statics.add_static('shuffle', Order.shuffle)
 
-Pop = Enum('Pop', '_all first last')
+Pop = Enum('Pop', 'all_ first last')
 statics.add_static('first', Pop.first)
 statics.add_static('last', Pop.last)
-statics.add_static('_all', Pop._all)
+statics.add_static('all_', Pop.all_)
 
-Scope = Enum('Scope', '_global local')
-statics.add_static('_global', Scope._global)
+Scope = Enum('Scope', 'global_ local')
+statics.add_static('global_', Scope.global_)
 statics.add_static('local', Scope.local)
 
 T = Enum('T', 'id key label value')
@@ -134,9 +134,6 @@ class P(object):
       self.value = value
       self.other = other
    @staticmethod
-   def _not(*args):
-      return P("not", *args)
-   @staticmethod
    def between(*args):
       return P("between", *args)
    @staticmethod
@@ -161,6 +158,9 @@ class P(object):
    def neq(*args):
       return P("neq", *args)
    @staticmethod
+   def not_(*args):
+      return P("not", *args)
+   @staticmethod
    def outside(*args):
       return P("outside", *args)
    @staticmethod
@@ -181,10 +181,6 @@ class P(object):
    def __repr__(self):
       return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
 
-def _not(*args):
-      return P._not(*args)
-statics.add_static('_not',_not)
-
 def between(*args):
       return P.between(*args)
 statics.add_static('between',between)
@@ -217,6 +213,10 @@ def neq(*args):
       return P.neq(*args)
 statics.add_static('neq',neq)
 
+def not_(*args):
+      return P.not_(*args)
+statics.add_static('not_',not_)
+
 def outside(*args):
       return P.outside(*args)
 statics.add_static('outside',outside)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
index a844191..dcc6976 100644
--- a/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
+++ b/gremlin-python/src/main/jython/gremlin_python/structure/io/graphson.py
@@ -248,9 +248,9 @@ class PropertyDeserializer(GraphSONDeserializer):
 
 
 class _SymbolHelper(object):
-    symbolMap = {"_global": "global", "_as": "as", "_in": "in", "_and": "and",
-                 "_or": "or", "_is": "is", "_not": "not", "_from": "from",
-                 "_set": "set", "_list": "list", "_all": "all"}
+    symbolMap = {"global_": "global", "as_": "as", "in_": "in", "and_": "and",
+                 "or_": "or", "is_": "is", "not_": "not", "from_": "from",
+                 "set_": "set", "list_": "list", "all_": "all"}
 
     _TYPE = "@type"
     _VALUE = "@value"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/main/jython/tests/test_statics.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/test_statics.py b/gremlin-python/src/main/jython/tests/test_statics.py
index 246101f..75fae2d 100644
--- a/gremlin-python/src/main/jython/tests/test_statics.py
+++ b/gremlin-python/src/main/jython/tests/test_statics.py
@@ -31,8 +31,8 @@ from gremlin_python.process.traversal import Pop
 class TestStatics(TestCase):
     def test_enums(self):
         statics.load_statics(globals())
-        assert isinstance(_list, Cardinality)
-        assert _list is Cardinality._list
+        assert isinstance(list_, Cardinality)
+        assert list_ is Cardinality.list_
         #
         assert isinstance(eq(2), P)
         assert eq(2) == P.eq(2)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a1257e2b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
index 5e71bda..0e0bcb3 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/structure/io/graphson/GraphSONWriterTest.java
@@ -103,8 +103,8 @@ public class GraphSONWriterTest {
         }
         assertEquals(Pop.first, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.first)").toString(), Object.class));
         assertEquals(Pop.last, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.last)").toString(), Object.class));
-        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop._all)").toString(), Object.class));
-        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope._global)").toString(), Object.class));
+        assertEquals(Pop.all, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Pop.all_)").toString(), Object.class));
+        assertEquals(Scope.global, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope.global_)").toString(), Object.class));
         assertEquals(Scope.local, mapper.readValue(jythonEngine.eval("GraphSONWriter.writeObject(Scope.local)").toString(), Object.class));
     }