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 2017/05/19 19:11:45 UTC
[1/2] tinkerpop git commit: TINKERPOP-1618 Removed dependence on
groovy for gremlin-python
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1618 [created] 0d6e0bb51
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/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 e722215..6888801 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
@@ -16,6 +16,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
+
import sys
from .traversal import Traversal
from .traversal import TraversalStrategies
@@ -26,1106 +27,1217 @@ from .. import statics
from ..statics import long
class GraphTraversalSource(object):
- def __init__(self, graph, traversal_strategies, bytecode=None):
- self.graph = graph
- self.traversal_strategies = traversal_strategies
- if bytecode is None:
- bytecode = Bytecode()
- self.bytecode = bytecode
- def __repr__(self):
- return "graphtraversalsource[" + str(self.graph) + "]"
- def withBulk(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withBulk", *args)
- return source
- def withPath(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withPath", *args)
- return source
- def withSack(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withSack", *args)
- return source
- def withSideEffect(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withSideEffect", *args)
- return source
- def withStrategies(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withStrategies", *args)
- return source
- def withoutStrategies(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withoutStrategies", *args)
- return source
- def withRemote(self, remote_connection):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
- return source
- def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
- return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
- def E(self, *args):
- traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
- traversal.bytecode.add_step("E", *args)
- return traversal
- def V(self, *args):
- traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
- traversal.bytecode.add_step("V", *args)
- return traversal
- def addV(self, *args):
- traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
- traversal.bytecode.add_step("addV", *args)
- return traversal
- def inject(self, *args):
- traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
- traversal.bytecode.add_step("inject", *args)
- return traversal
+ def __init__(self, graph, traversal_strategies, bytecode=None):
+ self.graph = graph
+ self.traversal_strategies = traversal_strategies
+ if bytecode is None:
+ bytecode = Bytecode()
+ self.bytecode = bytecode
+ def __repr__(self):
+ return "graphtraversalsource[" + str(self.graph) + "]"
+
+
+ def withBulk(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withBulk", *args)
+ return source
+
+ def withPath(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withPath", *args)
+ return source
+
+ def withSack(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withSack", *args)
+ return source
+
+ def withSideEffect(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withSideEffect", *args)
+ return source
+
+ def withStrategies(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withStrategies", *args)
+ return source
+
+ def withoutStrategies(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("withoutStrategies", *args)
+ return source
+
+
+ def withRemote(self, remote_connection):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
+ return source
+ def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
+ return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
+
+
+ def E(self, *args):
+ traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+ traversal.bytecode.add_step("E", *args)
+ return traversal
+
+ def V(self, *args):
+ traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+ traversal.bytecode.add_step("V", *args)
+ return traversal
+
+ def addV(self, *args):
+ traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+ traversal.bytecode.add_step("addV", *args)
+ return traversal
+
+ def inject(self, *args):
+ traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+ traversal.bytecode.add_step("inject", *args)
+ return traversal
class GraphTraversal(Traversal):
- def __init__(self, graph, traversal_strategies, bytecode):
- Traversal.__init__(self, graph, traversal_strategies, bytecode)
- def __getitem__(self, index):
- if isinstance(index, int):
- return self.range(long(index), long(index + 1))
- elif isinstance(index, slice):
- return self.range(long(0) if index.start is None else long(index.start), long(sys.maxsize) if index.stop is None else long(index.stop))
- else:
- raise TypeError("Index must be int or slice")
- def __getattr__(self, key):
- return self.values(key)
- def V(self, *args):
- self.bytecode.add_step("V", *args)
- return self
- def addE(self, *args):
- self.bytecode.add_step("addE", *args)
- return self
- def addInE(self, *args):
- self.bytecode.add_step("addInE", *args)
- return self
- def addOutE(self, *args):
- self.bytecode.add_step("addOutE", *args)
- return self
- def addV(self, *args):
- self.bytecode.add_step("addV", *args)
- return self
- 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
- def both(self, *args):
- self.bytecode.add_step("both", *args)
- return self
- def bothE(self, *args):
- self.bytecode.add_step("bothE", *args)
- return self
- def bothV(self, *args):
- self.bytecode.add_step("bothV", *args)
- return self
- def branch(self, *args):
- self.bytecode.add_step("branch", *args)
- return self
- def by(self, *args):
- self.bytecode.add_step("by", *args)
- return self
- def cap(self, *args):
- self.bytecode.add_step("cap", *args)
- return self
- def choose(self, *args):
- self.bytecode.add_step("choose", *args)
- return self
- def coalesce(self, *args):
- self.bytecode.add_step("coalesce", *args)
- return self
- def coin(self, *args):
- self.bytecode.add_step("coin", *args)
- return self
- def constant(self, *args):
- self.bytecode.add_step("constant", *args)
- return self
- def count(self, *args):
- self.bytecode.add_step("count", *args)
- return self
- def cyclicPath(self, *args):
- self.bytecode.add_step("cyclicPath", *args)
- return self
- def dedup(self, *args):
- self.bytecode.add_step("dedup", *args)
- return self
- def drop(self, *args):
- self.bytecode.add_step("drop", *args)
- return self
- def emit(self, *args):
- self.bytecode.add_step("emit", *args)
- return self
- def filter(self, *args):
- self.bytecode.add_step("filter", *args)
- return self
- def flatMap(self, *args):
- self.bytecode.add_step("flatMap", *args)
- return self
- 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
- def groupCount(self, *args):
- self.bytecode.add_step("groupCount", *args)
- return self
- def groupV3d0(self, *args):
- self.bytecode.add_step("groupV3d0", *args)
- return self
- def has(self, *args):
- self.bytecode.add_step("has", *args)
- return self
- def hasId(self, *args):
- self.bytecode.add_step("hasId", *args)
- return self
- def hasKey(self, *args):
- self.bytecode.add_step("hasKey", *args)
- return self
- def hasLabel(self, *args):
- self.bytecode.add_step("hasLabel", *args)
- return self
- def hasNot(self, *args):
- self.bytecode.add_step("hasNot", *args)
- return self
- def hasValue(self, *args):
- self.bytecode.add_step("hasValue", *args)
- return self
- def id(self, *args):
- self.bytecode.add_step("id", *args)
- return self
- def identity(self, *args):
- self.bytecode.add_step("identity", *args)
- return self
- def inE(self, *args):
- self.bytecode.add_step("inE", *args)
- return self
- 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
- def label(self, *args):
- self.bytecode.add_step("label", *args)
- return self
- def limit(self, *args):
- self.bytecode.add_step("limit", *args)
- return self
- def local(self, *args):
- self.bytecode.add_step("local", *args)
- return self
- def loops(self, *args):
- self.bytecode.add_step("loops", *args)
- return self
- def map(self, *args):
- self.bytecode.add_step("map", *args)
- return self
- def mapKeys(self, *args):
- self.bytecode.add_step("mapKeys", *args)
- return self
- def mapValues(self, *args):
- self.bytecode.add_step("mapValues", *args)
- return self
- def match(self, *args):
- self.bytecode.add_step("match", *args)
- return self
- def max(self, *args):
- self.bytecode.add_step("max", *args)
- return self
- def mean(self, *args):
- self.bytecode.add_step("mean", *args)
- return self
- 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
- def otherV(self, *args):
- self.bytecode.add_step("otherV", *args)
- return self
- def out(self, *args):
- self.bytecode.add_step("out", *args)
- return self
- def outE(self, *args):
- self.bytecode.add_step("outE", *args)
- return self
- def outV(self, *args):
- self.bytecode.add_step("outV", *args)
- return self
- def pageRank(self, *args):
- self.bytecode.add_step("pageRank", *args)
- return self
- def path(self, *args):
- self.bytecode.add_step("path", *args)
- return self
- def peerPressure(self, *args):
- self.bytecode.add_step("peerPressure", *args)
- return self
- def profile(self, *args):
- self.bytecode.add_step("profile", *args)
- return self
- def program(self, *args):
- self.bytecode.add_step("program", *args)
- return self
- def project(self, *args):
- self.bytecode.add_step("project", *args)
- return self
- def properties(self, *args):
- self.bytecode.add_step("properties", *args)
- return self
- def property(self, *args):
- self.bytecode.add_step("property", *args)
- return self
- def propertyMap(self, *args):
- self.bytecode.add_step("propertyMap", *args)
- return self
- def range(self, *args):
- self.bytecode.add_step("range", *args)
- return self
- def repeat(self, *args):
- self.bytecode.add_step("repeat", *args)
- return self
- def sack(self, *args):
- self.bytecode.add_step("sack", *args)
- return self
- def sample(self, *args):
- self.bytecode.add_step("sample", *args)
- return self
- def select(self, *args):
- self.bytecode.add_step("select", *args)
- return self
- def sideEffect(self, *args):
- self.bytecode.add_step("sideEffect", *args)
- return self
- def simplePath(self, *args):
- self.bytecode.add_step("simplePath", *args)
- return self
- def store(self, *args):
- self.bytecode.add_step("store", *args)
- return self
- def subgraph(self, *args):
- self.bytecode.add_step("subgraph", *args)
- return self
- def sum(self, *args):
- self.bytecode.add_step("sum", *args)
- return self
- def tail(self, *args):
- self.bytecode.add_step("tail", *args)
- return self
- def timeLimit(self, *args):
- self.bytecode.add_step("timeLimit", *args)
- return self
- def times(self, *args):
- self.bytecode.add_step("times", *args)
- return self
- def to(self, *args):
- self.bytecode.add_step("to", *args)
- return self
- def toE(self, *args):
- self.bytecode.add_step("toE", *args)
- return self
- def toV(self, *args):
- self.bytecode.add_step("toV", *args)
- return self
- def tree(self, *args):
- self.bytecode.add_step("tree", *args)
- return self
- def unfold(self, *args):
- self.bytecode.add_step("unfold", *args)
- return self
- def union(self, *args):
- self.bytecode.add_step("union", *args)
- return self
- def until(self, *args):
- self.bytecode.add_step("until", *args)
- return self
- def value(self, *args):
- self.bytecode.add_step("value", *args)
- return self
- def valueMap(self, *args):
- self.bytecode.add_step("valueMap", *args)
- return self
- def values(self, *args):
- self.bytecode.add_step("values", *args)
- return self
- def where(self, *args):
- self.bytecode.add_step("where", *args)
- return self
+ def __init__(self, graph, traversal_strategies, bytecode):
+ Traversal.__init__(self, graph, traversal_strategies, bytecode)
+ def __getitem__(self, index):
+ if isinstance(index, int):
+ return self.range(long(index), long(index + 1))
+ elif isinstance(index, slice):
+ return self.range(long(0) if index.start is None else long(index.start), long(sys.maxsize) if index.stop is None else long(index.stop))
+ else:
+ raise TypeError("Index must be int or slice")
+ def __getattr__(self, key):
+ return self.values(key)
+
+ def V(self, *args):
+ self.bytecode.add_step("V", *args)
+ return self
+
+ def addE(self, *args):
+ self.bytecode.add_step("addE", *args)
+ return self
+
+ def addInE(self, *args):
+ self.bytecode.add_step("addInE", *args)
+ return self
+
+ def addOutE(self, *args):
+ self.bytecode.add_step("addOutE", *args)
+ return self
+
+ def addV(self, *args):
+ self.bytecode.add_step("addV", *args)
+ return self
+
+ 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
+
+ def both(self, *args):
+ self.bytecode.add_step("both", *args)
+ return self
+
+ def bothE(self, *args):
+ self.bytecode.add_step("bothE", *args)
+ return self
+
+ def bothV(self, *args):
+ self.bytecode.add_step("bothV", *args)
+ return self
+
+ def branch(self, *args):
+ self.bytecode.add_step("branch", *args)
+ return self
+
+ def by(self, *args):
+ self.bytecode.add_step("by", *args)
+ return self
+
+ def cap(self, *args):
+ self.bytecode.add_step("cap", *args)
+ return self
+
+ def choose(self, *args):
+ self.bytecode.add_step("choose", *args)
+ return self
+
+ def coalesce(self, *args):
+ self.bytecode.add_step("coalesce", *args)
+ return self
+
+ def coin(self, *args):
+ self.bytecode.add_step("coin", *args)
+ return self
+
+ def constant(self, *args):
+ self.bytecode.add_step("constant", *args)
+ return self
+
+ def count(self, *args):
+ self.bytecode.add_step("count", *args)
+ return self
+
+ def cyclicPath(self, *args):
+ self.bytecode.add_step("cyclicPath", *args)
+ return self
+
+ def dedup(self, *args):
+ self.bytecode.add_step("dedup", *args)
+ return self
+
+ def drop(self, *args):
+ self.bytecode.add_step("drop", *args)
+ return self
+
+ def emit(self, *args):
+ self.bytecode.add_step("emit", *args)
+ return self
+
+ def filter(self, *args):
+ self.bytecode.add_step("filter", *args)
+ return self
+
+ def flatMap(self, *args):
+ self.bytecode.add_step("flatMap", *args)
+ return self
+
+ 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
+
+ def groupCount(self, *args):
+ self.bytecode.add_step("groupCount", *args)
+ return self
+
+ def groupV3d0(self, *args):
+ self.bytecode.add_step("groupV3d0", *args)
+ return self
+
+ def has(self, *args):
+ self.bytecode.add_step("has", *args)
+ return self
+
+ def hasId(self, *args):
+ self.bytecode.add_step("hasId", *args)
+ return self
+
+ def hasKey(self, *args):
+ self.bytecode.add_step("hasKey", *args)
+ return self
+
+ def hasLabel(self, *args):
+ self.bytecode.add_step("hasLabel", *args)
+ return self
+
+ def hasNot(self, *args):
+ self.bytecode.add_step("hasNot", *args)
+ return self
+
+ def hasValue(self, *args):
+ self.bytecode.add_step("hasValue", *args)
+ return self
+
+ def id(self, *args):
+ self.bytecode.add_step("id", *args)
+ return self
+
+ def identity(self, *args):
+ self.bytecode.add_step("identity", *args)
+ return self
+
+ def inE(self, *args):
+ self.bytecode.add_step("inE", *args)
+ return self
+
+ 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
+
+ def label(self, *args):
+ self.bytecode.add_step("label", *args)
+ return self
+
+ def limit(self, *args):
+ self.bytecode.add_step("limit", *args)
+ return self
+
+ def local(self, *args):
+ self.bytecode.add_step("local", *args)
+ return self
+
+ def loops(self, *args):
+ self.bytecode.add_step("loops", *args)
+ return self
+
+ def map(self, *args):
+ self.bytecode.add_step("map", *args)
+ return self
+
+ def mapKeys(self, *args):
+ self.bytecode.add_step("mapKeys", *args)
+ return self
+
+ def mapValues(self, *args):
+ self.bytecode.add_step("mapValues", *args)
+ return self
+
+ def match(self, *args):
+ self.bytecode.add_step("match", *args)
+ return self
+
+ def max(self, *args):
+ self.bytecode.add_step("max", *args)
+ return self
+
+ def mean(self, *args):
+ self.bytecode.add_step("mean", *args)
+ return self
+
+ 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
+
+ def otherV(self, *args):
+ self.bytecode.add_step("otherV", *args)
+ return self
+
+ def out(self, *args):
+ self.bytecode.add_step("out", *args)
+ return self
+
+ def outE(self, *args):
+ self.bytecode.add_step("outE", *args)
+ return self
+
+ def outV(self, *args):
+ self.bytecode.add_step("outV", *args)
+ return self
+
+ def pageRank(self, *args):
+ self.bytecode.add_step("pageRank", *args)
+ return self
+
+ def path(self, *args):
+ self.bytecode.add_step("path", *args)
+ return self
+
+ def peerPressure(self, *args):
+ self.bytecode.add_step("peerPressure", *args)
+ return self
+
+ def profile(self, *args):
+ self.bytecode.add_step("profile", *args)
+ return self
+
+ def program(self, *args):
+ self.bytecode.add_step("program", *args)
+ return self
+
+ def project(self, *args):
+ self.bytecode.add_step("project", *args)
+ return self
+
+ def properties(self, *args):
+ self.bytecode.add_step("properties", *args)
+ return self
+
+ def property(self, *args):
+ self.bytecode.add_step("property", *args)
+ return self
+
+ def propertyMap(self, *args):
+ self.bytecode.add_step("propertyMap", *args)
+ return self
+
+ def range(self, *args):
+ self.bytecode.add_step("range", *args)
+ return self
+
+ def repeat(self, *args):
+ self.bytecode.add_step("repeat", *args)
+ return self
+
+ def sack(self, *args):
+ self.bytecode.add_step("sack", *args)
+ return self
+
+ def sample(self, *args):
+ self.bytecode.add_step("sample", *args)
+ return self
+
+ def select(self, *args):
+ self.bytecode.add_step("select", *args)
+ return self
+
+ def sideEffect(self, *args):
+ self.bytecode.add_step("sideEffect", *args)
+ return self
+
+ def simplePath(self, *args):
+ self.bytecode.add_step("simplePath", *args)
+ return self
+
+ def store(self, *args):
+ self.bytecode.add_step("store", *args)
+ return self
+
+ def subgraph(self, *args):
+ self.bytecode.add_step("subgraph", *args)
+ return self
+
+ def sum(self, *args):
+ self.bytecode.add_step("sum", *args)
+ return self
+
+ def tail(self, *args):
+ self.bytecode.add_step("tail", *args)
+ return self
+
+ def timeLimit(self, *args):
+ self.bytecode.add_step("timeLimit", *args)
+ return self
+
+ def times(self, *args):
+ self.bytecode.add_step("times", *args)
+ return self
+
+ def to(self, *args):
+ self.bytecode.add_step("to", *args)
+ return self
+
+ def toE(self, *args):
+ self.bytecode.add_step("toE", *args)
+ return self
+
+ def toV(self, *args):
+ self.bytecode.add_step("toV", *args)
+ return self
+
+ def tree(self, *args):
+ self.bytecode.add_step("tree", *args)
+ return self
+
+ def unfold(self, *args):
+ self.bytecode.add_step("unfold", *args)
+ return self
+
+ def union(self, *args):
+ self.bytecode.add_step("union", *args)
+ return self
+
+ def until(self, *args):
+ self.bytecode.add_step("until", *args)
+ return self
+
+ def value(self, *args):
+ self.bytecode.add_step("value", *args)
+ return self
+
+ def valueMap(self, *args):
+ self.bytecode.add_step("valueMap", *args)
+ return self
+
+ def values(self, *args):
+ self.bytecode.add_step("values", *args)
+ return self
+
+ def where(self, *args):
+ self.bytecode.add_step("where", *args)
+ return self
class __(object):
- @staticmethod
- def start():
- return GraphTraversal(None, None, Bytecode())
- @staticmethod
- def __(*args):
- return __.inject(*args)
- @staticmethod
- def V(*args):
- return GraphTraversal(None, None, Bytecode()).V(*args)
- @staticmethod
- def addE(*args):
- return GraphTraversal(None, None, Bytecode()).addE(*args)
- @staticmethod
- def addInE(*args):
- return GraphTraversal(None, None, Bytecode()).addInE(*args)
- @staticmethod
- def addOutE(*args):
- return GraphTraversal(None, None, Bytecode()).addOutE(*args)
- @staticmethod
- def addV(*args):
- return GraphTraversal(None, None, Bytecode()).addV(*args)
- @staticmethod
- 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
- def both(*args):
- return GraphTraversal(None, None, Bytecode()).both(*args)
- @staticmethod
- def bothE(*args):
- return GraphTraversal(None, None, Bytecode()).bothE(*args)
- @staticmethod
- def bothV(*args):
- return GraphTraversal(None, None, Bytecode()).bothV(*args)
- @staticmethod
- def branch(*args):
- return GraphTraversal(None, None, Bytecode()).branch(*args)
- @staticmethod
- def cap(*args):
- return GraphTraversal(None, None, Bytecode()).cap(*args)
- @staticmethod
- def choose(*args):
- return GraphTraversal(None, None, Bytecode()).choose(*args)
- @staticmethod
- def coalesce(*args):
- return GraphTraversal(None, None, Bytecode()).coalesce(*args)
- @staticmethod
- def coin(*args):
- return GraphTraversal(None, None, Bytecode()).coin(*args)
- @staticmethod
- def constant(*args):
- return GraphTraversal(None, None, Bytecode()).constant(*args)
- @staticmethod
- def count(*args):
- return GraphTraversal(None, None, Bytecode()).count(*args)
- @staticmethod
- def cyclicPath(*args):
- return GraphTraversal(None, None, Bytecode()).cyclicPath(*args)
- @staticmethod
- def dedup(*args):
- return GraphTraversal(None, None, Bytecode()).dedup(*args)
- @staticmethod
- def drop(*args):
- return GraphTraversal(None, None, Bytecode()).drop(*args)
- @staticmethod
- def emit(*args):
- return GraphTraversal(None, None, Bytecode()).emit(*args)
- @staticmethod
- def filter(*args):
- return GraphTraversal(None, None, Bytecode()).filter(*args)
- @staticmethod
- def flatMap(*args):
- return GraphTraversal(None, None, Bytecode()).flatMap(*args)
- @staticmethod
- def fold(*args):
- return GraphTraversal(None, None, Bytecode()).fold(*args)
- @staticmethod
- def group(*args):
- return GraphTraversal(None, None, Bytecode()).group(*args)
- @staticmethod
- def groupCount(*args):
- return GraphTraversal(None, None, Bytecode()).groupCount(*args)
- @staticmethod
- def groupV3d0(*args):
- return GraphTraversal(None, None, Bytecode()).groupV3d0(*args)
- @staticmethod
- def has(*args):
- return GraphTraversal(None, None, Bytecode()).has(*args)
- @staticmethod
- def hasId(*args):
- return GraphTraversal(None, None, Bytecode()).hasId(*args)
- @staticmethod
- def hasKey(*args):
- return GraphTraversal(None, None, Bytecode()).hasKey(*args)
- @staticmethod
- def hasLabel(*args):
- return GraphTraversal(None, None, Bytecode()).hasLabel(*args)
- @staticmethod
- def hasNot(*args):
- return GraphTraversal(None, None, Bytecode()).hasNot(*args)
- @staticmethod
- def hasValue(*args):
- return GraphTraversal(None, None, Bytecode()).hasValue(*args)
- @staticmethod
- def id(*args):
- return GraphTraversal(None, None, Bytecode()).id(*args)
- @staticmethod
- def identity(*args):
- return GraphTraversal(None, None, Bytecode()).identity(*args)
- @staticmethod
- def inE(*args):
- return GraphTraversal(None, None, Bytecode()).inE(*args)
- @staticmethod
- 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
- def label(*args):
- return GraphTraversal(None, None, Bytecode()).label(*args)
- @staticmethod
- def limit(*args):
- return GraphTraversal(None, None, Bytecode()).limit(*args)
- @staticmethod
- def local(*args):
- return GraphTraversal(None, None, Bytecode()).local(*args)
- @staticmethod
- def loops(*args):
- return GraphTraversal(None, None, Bytecode()).loops(*args)
- @staticmethod
- def map(*args):
- return GraphTraversal(None, None, Bytecode()).map(*args)
- @staticmethod
- def mapKeys(*args):
- return GraphTraversal(None, None, Bytecode()).mapKeys(*args)
- @staticmethod
- def mapValues(*args):
- return GraphTraversal(None, None, Bytecode()).mapValues(*args)
- @staticmethod
- def match(*args):
- return GraphTraversal(None, None, Bytecode()).match(*args)
- @staticmethod
- def max(*args):
- return GraphTraversal(None, None, Bytecode()).max(*args)
- @staticmethod
- def mean(*args):
- return GraphTraversal(None, None, Bytecode()).mean(*args)
- @staticmethod
- 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
- def otherV(*args):
- return GraphTraversal(None, None, Bytecode()).otherV(*args)
- @staticmethod
- def out(*args):
- return GraphTraversal(None, None, Bytecode()).out(*args)
- @staticmethod
- def outE(*args):
- return GraphTraversal(None, None, Bytecode()).outE(*args)
- @staticmethod
- def outV(*args):
- return GraphTraversal(None, None, Bytecode()).outV(*args)
- @staticmethod
- def path(*args):
- return GraphTraversal(None, None, Bytecode()).path(*args)
- @staticmethod
- def project(*args):
- return GraphTraversal(None, None, Bytecode()).project(*args)
- @staticmethod
- def properties(*args):
- return GraphTraversal(None, None, Bytecode()).properties(*args)
- @staticmethod
- def property(*args):
- return GraphTraversal(None, None, Bytecode()).property(*args)
- @staticmethod
- def propertyMap(*args):
- return GraphTraversal(None, None, Bytecode()).propertyMap(*args)
- @staticmethod
- def range(*args):
- return GraphTraversal(None, None, Bytecode()).range(*args)
- @staticmethod
- def repeat(*args):
- return GraphTraversal(None, None, Bytecode()).repeat(*args)
- @staticmethod
- def sack(*args):
- return GraphTraversal(None, None, Bytecode()).sack(*args)
- @staticmethod
- def sample(*args):
- return GraphTraversal(None, None, Bytecode()).sample(*args)
- @staticmethod
- def select(*args):
- return GraphTraversal(None, None, Bytecode()).select(*args)
- @staticmethod
- def sideEffect(*args):
- return GraphTraversal(None, None, Bytecode()).sideEffect(*args)
- @staticmethod
- def simplePath(*args):
- return GraphTraversal(None, None, Bytecode()).simplePath(*args)
- @staticmethod
- def store(*args):
- return GraphTraversal(None, None, Bytecode()).store(*args)
- @staticmethod
- def subgraph(*args):
- return GraphTraversal(None, None, Bytecode()).subgraph(*args)
- @staticmethod
- def sum(*args):
- return GraphTraversal(None, None, Bytecode()).sum(*args)
- @staticmethod
- def tail(*args):
- return GraphTraversal(None, None, Bytecode()).tail(*args)
- @staticmethod
- def timeLimit(*args):
- return GraphTraversal(None, None, Bytecode()).timeLimit(*args)
- @staticmethod
- def times(*args):
- return GraphTraversal(None, None, Bytecode()).times(*args)
- @staticmethod
- def to(*args):
- return GraphTraversal(None, None, Bytecode()).to(*args)
- @staticmethod
- def toE(*args):
- return GraphTraversal(None, None, Bytecode()).toE(*args)
- @staticmethod
- def toV(*args):
- return GraphTraversal(None, None, Bytecode()).toV(*args)
- @staticmethod
- def tree(*args):
- return GraphTraversal(None, None, Bytecode()).tree(*args)
- @staticmethod
- def unfold(*args):
- return GraphTraversal(None, None, Bytecode()).unfold(*args)
- @staticmethod
- def union(*args):
- return GraphTraversal(None, None, Bytecode()).union(*args)
- @staticmethod
- def until(*args):
- return GraphTraversal(None, None, Bytecode()).until(*args)
- @staticmethod
- def value(*args):
- return GraphTraversal(None, None, Bytecode()).value(*args)
- @staticmethod
- def valueMap(*args):
- return GraphTraversal(None, None, Bytecode()).valueMap(*args)
- @staticmethod
- def values(*args):
- return GraphTraversal(None, None, Bytecode()).values(*args)
- @staticmethod
- def where(*args):
- return GraphTraversal(None, None, Bytecode()).where(*args)
+ @staticmethod
+ def start():
+ return GraphTraversal(None, None, Bytecode())
+ @staticmethod
+ def __(*args):
+ return __.inject(*args)
-def V(*args):
- return __.V(*args)
+ @staticmethod
+ def V(*args):
+ return GraphTraversal(None, None, Bytecode()).V(*args)
+
+ @staticmethod
+ def addE(*args):
+ return GraphTraversal(None, None, Bytecode()).addE(*args)
+
+ @staticmethod
+ def addInE(*args):
+ return GraphTraversal(None, None, Bytecode()).addInE(*args)
+
+ @staticmethod
+ def addOutE(*args):
+ return GraphTraversal(None, None, Bytecode()).addOutE(*args)
+
+ @staticmethod
+ def addV(*args):
+ return GraphTraversal(None, None, Bytecode()).addV(*args)
+
+ @staticmethod
+ 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
+ def both(*args):
+ return GraphTraversal(None, None, Bytecode()).both(*args)
+
+ @staticmethod
+ def bothE(*args):
+ return GraphTraversal(None, None, Bytecode()).bothE(*args)
+
+ @staticmethod
+ def bothV(*args):
+ return GraphTraversal(None, None, Bytecode()).bothV(*args)
+
+ @staticmethod
+ def branch(*args):
+ return GraphTraversal(None, None, Bytecode()).branch(*args)
+
+ @staticmethod
+ def cap(*args):
+ return GraphTraversal(None, None, Bytecode()).cap(*args)
+
+ @staticmethod
+ def choose(*args):
+ return GraphTraversal(None, None, Bytecode()).choose(*args)
+
+ @staticmethod
+ def coalesce(*args):
+ return GraphTraversal(None, None, Bytecode()).coalesce(*args)
+
+ @staticmethod
+ def coin(*args):
+ return GraphTraversal(None, None, Bytecode()).coin(*args)
+
+ @staticmethod
+ def constant(*args):
+ return GraphTraversal(None, None, Bytecode()).constant(*args)
+
+ @staticmethod
+ def count(*args):
+ return GraphTraversal(None, None, Bytecode()).count(*args)
+
+ @staticmethod
+ def cyclicPath(*args):
+ return GraphTraversal(None, None, Bytecode()).cyclicPath(*args)
+
+ @staticmethod
+ def dedup(*args):
+ return GraphTraversal(None, None, Bytecode()).dedup(*args)
+
+ @staticmethod
+ def drop(*args):
+ return GraphTraversal(None, None, Bytecode()).drop(*args)
+
+ @staticmethod
+ def emit(*args):
+ return GraphTraversal(None, None, Bytecode()).emit(*args)
+
+ @staticmethod
+ def filter(*args):
+ return GraphTraversal(None, None, Bytecode()).filter(*args)
+
+ @staticmethod
+ def flatMap(*args):
+ return GraphTraversal(None, None, Bytecode()).flatMap(*args)
+
+ @staticmethod
+ def fold(*args):
+ return GraphTraversal(None, None, Bytecode()).fold(*args)
+
+ @staticmethod
+ def group(*args):
+ return GraphTraversal(None, None, Bytecode()).group(*args)
+
+ @staticmethod
+ def groupCount(*args):
+ return GraphTraversal(None, None, Bytecode()).groupCount(*args)
+
+ @staticmethod
+ def groupV3d0(*args):
+ return GraphTraversal(None, None, Bytecode()).groupV3d0(*args)
+
+ @staticmethod
+ def has(*args):
+ return GraphTraversal(None, None, Bytecode()).has(*args)
+
+ @staticmethod
+ def hasId(*args):
+ return GraphTraversal(None, None, Bytecode()).hasId(*args)
+
+ @staticmethod
+ def hasKey(*args):
+ return GraphTraversal(None, None, Bytecode()).hasKey(*args)
+
+ @staticmethod
+ def hasLabel(*args):
+ return GraphTraversal(None, None, Bytecode()).hasLabel(*args)
+
+ @staticmethod
+ def hasNot(*args):
+ return GraphTraversal(None, None, Bytecode()).hasNot(*args)
+
+ @staticmethod
+ def hasValue(*args):
+ return GraphTraversal(None, None, Bytecode()).hasValue(*args)
+
+ @staticmethod
+ def id(*args):
+ return GraphTraversal(None, None, Bytecode()).id(*args)
+
+ @staticmethod
+ def identity(*args):
+ return GraphTraversal(None, None, Bytecode()).identity(*args)
+
+ @staticmethod
+ def inE(*args):
+ return GraphTraversal(None, None, Bytecode()).inE(*args)
+
+ @staticmethod
+ 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
+ def label(*args):
+ return GraphTraversal(None, None, Bytecode()).label(*args)
+
+ @staticmethod
+ def limit(*args):
+ return GraphTraversal(None, None, Bytecode()).limit(*args)
+
+ @staticmethod
+ def local(*args):
+ return GraphTraversal(None, None, Bytecode()).local(*args)
+
+ @staticmethod
+ def loops(*args):
+ return GraphTraversal(None, None, Bytecode()).loops(*args)
+
+ @staticmethod
+ def map(*args):
+ return GraphTraversal(None, None, Bytecode()).map(*args)
+
+ @staticmethod
+ def mapKeys(*args):
+ return GraphTraversal(None, None, Bytecode()).mapKeys(*args)
+
+ @staticmethod
+ def mapValues(*args):
+ return GraphTraversal(None, None, Bytecode()).mapValues(*args)
+
+ @staticmethod
+ def match(*args):
+ return GraphTraversal(None, None, Bytecode()).match(*args)
+
+ @staticmethod
+ def max(*args):
+ return GraphTraversal(None, None, Bytecode()).max(*args)
+
+ @staticmethod
+ def mean(*args):
+ return GraphTraversal(None, None, Bytecode()).mean(*args)
+
+ @staticmethod
+ 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
+ def otherV(*args):
+ return GraphTraversal(None, None, Bytecode()).otherV(*args)
+
+ @staticmethod
+ def out(*args):
+ return GraphTraversal(None, None, Bytecode()).out(*args)
+
+ @staticmethod
+ def outE(*args):
+ return GraphTraversal(None, None, Bytecode()).outE(*args)
+
+ @staticmethod
+ def outV(*args):
+ return GraphTraversal(None, None, Bytecode()).outV(*args)
+
+ @staticmethod
+ def path(*args):
+ return GraphTraversal(None, None, Bytecode()).path(*args)
+
+ @staticmethod
+ def project(*args):
+ return GraphTraversal(None, None, Bytecode()).project(*args)
+
+ @staticmethod
+ def properties(*args):
+ return GraphTraversal(None, None, Bytecode()).properties(*args)
+
+ @staticmethod
+ def property(*args):
+ return GraphTraversal(None, None, Bytecode()).property(*args)
+
+ @staticmethod
+ def propertyMap(*args):
+ return GraphTraversal(None, None, Bytecode()).propertyMap(*args)
+
+ @staticmethod
+ def range(*args):
+ return GraphTraversal(None, None, Bytecode()).range(*args)
+
+ @staticmethod
+ def repeat(*args):
+ return GraphTraversal(None, None, Bytecode()).repeat(*args)
+
+ @staticmethod
+ def sack(*args):
+ return GraphTraversal(None, None, Bytecode()).sack(*args)
+
+ @staticmethod
+ def sample(*args):
+ return GraphTraversal(None, None, Bytecode()).sample(*args)
+
+ @staticmethod
+ def select(*args):
+ return GraphTraversal(None, None, Bytecode()).select(*args)
+
+ @staticmethod
+ def sideEffect(*args):
+ return GraphTraversal(None, None, Bytecode()).sideEffect(*args)
+
+ @staticmethod
+ def simplePath(*args):
+ return GraphTraversal(None, None, Bytecode()).simplePath(*args)
+
+ @staticmethod
+ def store(*args):
+ return GraphTraversal(None, None, Bytecode()).store(*args)
+
+ @staticmethod
+ def subgraph(*args):
+ return GraphTraversal(None, None, Bytecode()).subgraph(*args)
+
+ @staticmethod
+ def sum(*args):
+ return GraphTraversal(None, None, Bytecode()).sum(*args)
+
+ @staticmethod
+ def tail(*args):
+ return GraphTraversal(None, None, Bytecode()).tail(*args)
+
+ @staticmethod
+ def timeLimit(*args):
+ return GraphTraversal(None, None, Bytecode()).timeLimit(*args)
+
+ @staticmethod
+ def times(*args):
+ return GraphTraversal(None, None, Bytecode()).times(*args)
+
+ @staticmethod
+ def to(*args):
+ return GraphTraversal(None, None, Bytecode()).to(*args)
+
+ @staticmethod
+ def toE(*args):
+ return GraphTraversal(None, None, Bytecode()).toE(*args)
+
+ @staticmethod
+ def toV(*args):
+ return GraphTraversal(None, None, Bytecode()).toV(*args)
+
+ @staticmethod
+ def tree(*args):
+ return GraphTraversal(None, None, Bytecode()).tree(*args)
+
+ @staticmethod
+ def unfold(*args):
+ return GraphTraversal(None, None, Bytecode()).unfold(*args)
+
+ @staticmethod
+ def union(*args):
+ return GraphTraversal(None, None, Bytecode()).union(*args)
+
+ @staticmethod
+ def until(*args):
+ return GraphTraversal(None, None, Bytecode()).until(*args)
+
+ @staticmethod
+ def value(*args):
+ return GraphTraversal(None, None, Bytecode()).value(*args)
+
+ @staticmethod
+ def valueMap(*args):
+ return GraphTraversal(None, None, Bytecode()).valueMap(*args)
+
+ @staticmethod
+ def values(*args):
+ return GraphTraversal(None, None, Bytecode()).values(*args)
+
+ @staticmethod
+ def where(*args):
+ return GraphTraversal(None, None, Bytecode()).where(*args)
+
+
+
+def V(*args):
+ return __.V(*args)
statics.add_static('V', V)
def addE(*args):
- return __.addE(*args)
-
+ return __.addE(*args)
statics.add_static('addE', addE)
def addInE(*args):
- return __.addInE(*args)
-
+ return __.addInE(*args)
statics.add_static('addInE', addInE)
def addOutE(*args):
- return __.addOutE(*args)
-
+ return __.addOutE(*args)
statics.add_static('addOutE', addOutE)
def addV(*args):
- return __.addV(*args)
-
+ return __.addV(*args)
statics.add_static('addV', addV)
def aggregate(*args):
- return __.aggregate(*args)
-
+ return __.aggregate(*args)
statics.add_static('aggregate', aggregate)
def and_(*args):
- return __.and_(*args)
-
+ return __.and_(*args)
statics.add_static('and_', and_)
def as_(*args):
- return __.as_(*args)
-
+ return __.as_(*args)
statics.add_static('as_', as_)
def barrier(*args):
- return __.barrier(*args)
-
+ return __.barrier(*args)
statics.add_static('barrier', barrier)
def both(*args):
- return __.both(*args)
-
+ return __.both(*args)
statics.add_static('both', both)
def bothE(*args):
- return __.bothE(*args)
-
+ return __.bothE(*args)
statics.add_static('bothE', bothE)
def bothV(*args):
- return __.bothV(*args)
-
+ return __.bothV(*args)
statics.add_static('bothV', bothV)
def branch(*args):
- return __.branch(*args)
-
+ return __.branch(*args)
statics.add_static('branch', branch)
def cap(*args):
- return __.cap(*args)
-
+ return __.cap(*args)
statics.add_static('cap', cap)
def choose(*args):
- return __.choose(*args)
-
+ return __.choose(*args)
statics.add_static('choose', choose)
def coalesce(*args):
- return __.coalesce(*args)
-
+ return __.coalesce(*args)
statics.add_static('coalesce', coalesce)
def coin(*args):
- return __.coin(*args)
-
+ return __.coin(*args)
statics.add_static('coin', coin)
def constant(*args):
- return __.constant(*args)
-
+ return __.constant(*args)
statics.add_static('constant', constant)
def count(*args):
- return __.count(*args)
-
+ return __.count(*args)
statics.add_static('count', count)
def cyclicPath(*args):
- return __.cyclicPath(*args)
-
+ return __.cyclicPath(*args)
statics.add_static('cyclicPath', cyclicPath)
def dedup(*args):
- return __.dedup(*args)
-
+ return __.dedup(*args)
statics.add_static('dedup', dedup)
def drop(*args):
- return __.drop(*args)
-
+ return __.drop(*args)
statics.add_static('drop', drop)
def emit(*args):
- return __.emit(*args)
-
+ return __.emit(*args)
statics.add_static('emit', emit)
def filter(*args):
- return __.filter(*args)
-
+ return __.filter(*args)
statics.add_static('filter', filter)
def flatMap(*args):
- return __.flatMap(*args)
-
+ return __.flatMap(*args)
statics.add_static('flatMap', flatMap)
def fold(*args):
- return __.fold(*args)
-
+ return __.fold(*args)
statics.add_static('fold', fold)
def group(*args):
- return __.group(*args)
-
+ return __.group(*args)
statics.add_static('group', group)
def groupCount(*args):
- return __.groupCount(*args)
-
+ return __.groupCount(*args)
statics.add_static('groupCount', groupCount)
def groupV3d0(*args):
- return __.groupV3d0(*args)
-
+ return __.groupV3d0(*args)
statics.add_static('groupV3d0', groupV3d0)
def has(*args):
- return __.has(*args)
-
+ return __.has(*args)
statics.add_static('has', has)
def hasId(*args):
- return __.hasId(*args)
-
+ return __.hasId(*args)
statics.add_static('hasId', hasId)
def hasKey(*args):
- return __.hasKey(*args)
-
+ return __.hasKey(*args)
statics.add_static('hasKey', hasKey)
def hasLabel(*args):
- return __.hasLabel(*args)
-
+ return __.hasLabel(*args)
statics.add_static('hasLabel', hasLabel)
def hasNot(*args):
- return __.hasNot(*args)
-
+ return __.hasNot(*args)
statics.add_static('hasNot', hasNot)
def hasValue(*args):
- return __.hasValue(*args)
-
+ return __.hasValue(*args)
statics.add_static('hasValue', hasValue)
def id(*args):
- return __.id(*args)
-
+ return __.id(*args)
statics.add_static('id', id)
def identity(*args):
- return __.identity(*args)
-
+ return __.identity(*args)
statics.add_static('identity', identity)
def inE(*args):
- return __.inE(*args)
-
+ return __.inE(*args)
statics.add_static('inE', inE)
def inV(*args):
- return __.inV(*args)
-
+ return __.inV(*args)
statics.add_static('inV', inV)
def in_(*args):
- return __.in_(*args)
-
+ return __.in_(*args)
statics.add_static('in_', in_)
def inject(*args):
- return __.inject(*args)
-
+ return __.inject(*args)
statics.add_static('inject', inject)
def is_(*args):
- return __.is_(*args)
-
+ return __.is_(*args)
statics.add_static('is_', is_)
def key(*args):
- return __.key(*args)
-
+ return __.key(*args)
statics.add_static('key', key)
def label(*args):
- return __.label(*args)
-
+ return __.label(*args)
statics.add_static('label', label)
def limit(*args):
- return __.limit(*args)
-
+ return __.limit(*args)
statics.add_static('limit', limit)
def local(*args):
- return __.local(*args)
-
+ return __.local(*args)
statics.add_static('local', local)
def loops(*args):
- return __.loops(*args)
-
+ return __.loops(*args)
statics.add_static('loops', loops)
def map(*args):
- return __.map(*args)
-
+ return __.map(*args)
statics.add_static('map', map)
def mapKeys(*args):
- return __.mapKeys(*args)
-
+ return __.mapKeys(*args)
statics.add_static('mapKeys', mapKeys)
def mapValues(*args):
- return __.mapValues(*args)
-
+ return __.mapValues(*args)
statics.add_static('mapValues', mapValues)
def match(*args):
- return __.match(*args)
-
+ return __.match(*args)
statics.add_static('match', match)
def max(*args):
- return __.max(*args)
-
+ return __.max(*args)
statics.add_static('max', max)
def mean(*args):
- return __.mean(*args)
-
+ return __.mean(*args)
statics.add_static('mean', mean)
def min(*args):
- return __.min(*args)
-
+ return __.min(*args)
statics.add_static('min', min)
def not_(*args):
- return __.not_(*args)
-
+ return __.not_(*args)
statics.add_static('not_', not_)
def optional(*args):
- return __.optional(*args)
-
+ return __.optional(*args)
statics.add_static('optional', optional)
def or_(*args):
- return __.or_(*args)
-
+ return __.or_(*args)
statics.add_static('or_', or_)
def order(*args):
- return __.order(*args)
-
+ return __.order(*args)
statics.add_static('order', order)
def otherV(*args):
- return __.otherV(*args)
-
+ return __.otherV(*args)
statics.add_static('otherV', otherV)
def out(*args):
- return __.out(*args)
-
+ return __.out(*args)
statics.add_static('out', out)
def outE(*args):
- return __.outE(*args)
-
+ return __.outE(*args)
statics.add_static('outE', outE)
def outV(*args):
- return __.outV(*args)
-
+ return __.outV(*args)
statics.add_static('outV', outV)
def path(*args):
- return __.path(*args)
-
+ return __.path(*args)
statics.add_static('path', path)
def project(*args):
- return __.project(*args)
-
+ return __.project(*args)
statics.add_static('project', project)
def properties(*args):
- return __.properties(*args)
-
+ return __.properties(*args)
statics.add_static('properties', properties)
def property(*args):
- return __.property(*args)
-
+ return __.property(*args)
statics.add_static('property', property)
def propertyMap(*args):
- return __.propertyMap(*args)
-
+ return __.propertyMap(*args)
statics.add_static('propertyMap', propertyMap)
def range(*args):
- return __.range(*args)
-
+ return __.range(*args)
statics.add_static('range', range)
def repeat(*args):
- return __.repeat(*args)
-
+ return __.repeat(*args)
statics.add_static('repeat', repeat)
def sack(*args):
- return __.sack(*args)
-
+ return __.sack(*args)
statics.add_static('sack', sack)
def sample(*args):
- return __.sample(*args)
-
+ return __.sample(*args)
statics.add_static('sample', sample)
def select(*args):
- return __.select(*args)
-
+ return __.select(*args)
statics.add_static('select', select)
def sideEffect(*args):
- return __.sideEffect(*args)
-
+ return __.sideEffect(*args)
statics.add_static('sideEffect', sideEffect)
def simplePath(*args):
- return __.simplePath(*args)
-
+ return __.simplePath(*args)
statics.add_static('simplePath', simplePath)
def store(*args):
- return __.store(*args)
-
+ return __.store(*args)
statics.add_static('store', store)
def subgraph(*args):
- return __.subgraph(*args)
-
+ return __.subgraph(*args)
statics.add_static('subgraph', subgraph)
def sum(*args):
- return __.sum(*args)
-
+ return __.sum(*args)
statics.add_static('sum', sum)
def tail(*args):
- return __.tail(*args)
-
+ return __.tail(*args)
statics.add_static('tail', tail)
def timeLimit(*args):
- return __.timeLimit(*args)
-
+ return __.timeLimit(*args)
statics.add_static('timeLimit', timeLimit)
def times(*args):
- return __.times(*args)
-
+ return __.times(*args)
statics.add_static('times', times)
def to(*args):
- return __.to(*args)
-
+ return __.to(*args)
statics.add_static('to', to)
def toE(*args):
- return __.toE(*args)
-
+ return __.toE(*args)
statics.add_static('toE', toE)
def toV(*args):
- return __.toV(*args)
-
+ return __.toV(*args)
statics.add_static('toV', toV)
def tree(*args):
- return __.tree(*args)
-
+ return __.tree(*args)
statics.add_static('tree', tree)
def unfold(*args):
- return __.unfold(*args)
-
+ return __.unfold(*args)
statics.add_static('unfold', unfold)
def union(*args):
- return __.union(*args)
-
+ return __.union(*args)
statics.add_static('union', union)
def until(*args):
- return __.until(*args)
-
+ return __.until(*args)
statics.add_static('until', until)
def value(*args):
- return __.value(*args)
-
+ return __.value(*args)
statics.add_static('value', value)
def valueMap(*args):
- return __.valueMap(*args)
-
+ return __.valueMap(*args)
statics.add_static('valueMap', valueMap)
def values(*args):
- return __.values(*args)
-
+ return __.values(*args)
statics.add_static('values', values)
def where(*args):
- return __.where(*args)
-
+ return __.where(*args)
statics.add_static('where', where)
-
-
-
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/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 6996b23..69275fb 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/traversal.py
@@ -16,11 +16,11 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
+
from aenum import Enum
from .. import statics
from ..statics import long
-
class Traversal(object):
def __init__(self, graph, traversal_strategies, bytecode):
self.graph = graph
@@ -102,31 +102,38 @@ class Traversal(object):
return future
-Barrier = Enum('Barrier', 'normSack')
+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_)
-Column = Enum('Column', 'keys values')
+Column = Enum('Column', ' keys values')
+
statics.add_static('keys', Column.keys)
statics.add_static('values', Column.values)
-Direction = Enum('Direction', 'BOTH IN OUT')
+Direction = Enum('Direction', ' BOTH IN OUT')
+
statics.add_static('OUT', Direction.OUT)
statics.add_static('IN', Direction.IN)
statics.add_static('BOTH', Direction.BOTH)
-GraphSONVersion = Enum('GraphSONVersion', 'V1_0 V2_0')
+GraphSONVersion = Enum('GraphSONVersion', ' V1_0 V2_0')
+
statics.add_static('V1_0', GraphSONVersion.V1_0)
statics.add_static('V2_0', GraphSONVersion.V2_0)
-GryoVersion = Enum('GryoVersion', 'V1_0')
+GryoVersion = Enum('GryoVersion', ' V1_0')
+
statics.add_static('V1_0', GryoVersion.V1_0)
-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)
@@ -139,7 +146,8 @@ statics.add_static('or_', Operator.or_)
statics.add_static('addAll', Operator.addAll)
statics.add_static('sumLong', Operator.sumLong)
-Order = Enum('Order', 'decr incr keyDecr keyIncr shuffle valueDecr valueIncr')
+Order = Enum('Order', ' decr incr keyDecr keyIncr shuffle valueDecr valueIncr')
+
statics.add_static('incr', Order.incr)
statics.add_static('decr', Order.decr)
statics.add_static('keyIncr', Order.keyIncr)
@@ -148,132 +156,159 @@ statics.add_static('keyDecr', Order.keyDecr)
statics.add_static('valueDecr', Order.valueDecr)
statics.add_static('shuffle', Order.shuffle)
-Pick = Enum('Pick', 'any none')
+Pick = Enum('Pick', ' any none')
+
statics.add_static('any', Pick.any)
statics.add_static('none', Pick.none)
-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_)
-Scope = Enum('Scope', 'global_ local')
+Scope = Enum('Scope', ' global_ local')
+
statics.add_static('global_', Scope.global_)
statics.add_static('local', Scope.local)
-T = Enum('T', 'id key label value')
+T = Enum('T', ' id key label value')
+
statics.add_static('label', T.label)
statics.add_static('id', T.id)
statics.add_static('key', T.key)
statics.add_static('value', T.value)
+
class P(object):
- def __init__(self, operator, value, other=None):
- self.operator = operator
- self.value = value
- self.other = other
- @staticmethod
- def between(*args):
- return P("between", *args)
- @staticmethod
- def eq(*args):
- return P("eq", *args)
- @staticmethod
- def gt(*args):
- return P("gt", *args)
- @staticmethod
- def gte(*args):
- return P("gte", *args)
- @staticmethod
- def inside(*args):
- return P("inside", *args)
- @staticmethod
- def lt(*args):
- return P("lt", *args)
- @staticmethod
- def lte(*args):
- return P("lte", *args)
- @staticmethod
- def neq(*args):
- return P("neq", *args)
- @staticmethod
- def not_(*args):
- return P("not", *args)
- @staticmethod
- def outside(*args):
- return P("outside", *args)
- @staticmethod
- def test(*args):
- return P("test", *args)
- @staticmethod
- def within(*args):
- return P("within", *args)
- @staticmethod
- def without(*args):
- return P("without", *args)
- def and_(self, arg):
- return P("and", self, arg)
- def or_(self, arg):
- return P("or", self, arg)
- def __eq__(self, other):
+ def __init__(self, operator, value, other=None):
+ self.operator = operator
+ self.value = value
+ self.other = other
+
+
+ @staticmethod
+ def between(*args):
+ return P("between", *args)
+
+ @staticmethod
+ def eq(*args):
+ return P("eq", *args)
+
+ @staticmethod
+ def gt(*args):
+ return P("gt", *args)
+
+ @staticmethod
+ def gte(*args):
+ return P("gte", *args)
+
+ @staticmethod
+ def inside(*args):
+ return P("inside", *args)
+
+ @staticmethod
+ def lt(*args):
+ return P("lt", *args)
+
+ @staticmethod
+ def lte(*args):
+ return P("lte", *args)
+
+ @staticmethod
+ def neq(*args):
+ return P("neq", *args)
+
+ @staticmethod
+ def not_(*args):
+ return P("not_", *args)
+
+ @staticmethod
+ def outside(*args):
+ return P("outside", *args)
+
+ @staticmethod
+ def test(*args):
+ return P("test", *args)
+
+ @staticmethod
+ def within(*args):
+ return P("within", *args)
+
+ @staticmethod
+ def without(*args):
+ return P("without", *args)
+
+ def and_(self, arg):
+ return P("and", self, arg)
+ def or_(self, arg):
+ return P("or", self, arg)
+ def __eq__(self, other):
return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
- def __repr__(self):
- return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
+ def __repr__(self):
+ return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
+ def and_(self, arg):
+ return P("and", self, arg)
+ def or_(self, arg):
+ return P("or", self, arg)
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
+ def __repr__(self):
+ return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
def between(*args):
- return P.between(*args)
+ return P.between(*args)
statics.add_static('between',between)
def eq(*args):
- return P.eq(*args)
+ return P.eq(*args)
statics.add_static('eq',eq)
def gt(*args):
- return P.gt(*args)
+ return P.gt(*args)
statics.add_static('gt',gt)
def gte(*args):
- return P.gte(*args)
+ return P.gte(*args)
statics.add_static('gte',gte)
def inside(*args):
- return P.inside(*args)
+ return P.inside(*args)
statics.add_static('inside',inside)
def lt(*args):
- return P.lt(*args)
+ return P.lt(*args)
statics.add_static('lt',lt)
def lte(*args):
- return P.lte(*args)
+ return P.lte(*args)
statics.add_static('lte',lte)
def neq(*args):
- return P.neq(*args)
+ return P.neq(*args)
statics.add_static('neq',neq)
def not_(*args):
- return P.not_(*args)
+ return P.not_(*args)
statics.add_static('not_',not_)
def outside(*args):
- return P.outside(*args)
+ return P.outside(*args)
statics.add_static('outside',outside)
def test(*args):
- return P.test(*args)
+ return P.test(*args)
statics.add_static('test',test)
def within(*args):
- return P.within(*args)
+ return P.within(*args)
statics.add_static('within',within)
def without(*args):
- return P.without(*args)
+ return P.without(*args)
statics.add_static('without',without)
-
'''
TRAVERSER
'''
@@ -413,5 +448,4 @@ class Binding(object):
def __hash__(self):
return hash(self.key) + hash(self.value)
def __repr__(self):
- return "binding[" + self.key + "=" + str(self.value) + "]"
-
+ return "binding[" + self.key + "=" + str(self.value) + "]"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/src/main/resources/GraphTraversalSource.template
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/resources/GraphTraversalSource.template b/gremlin-python/src/main/resources/GraphTraversalSource.template
new file mode 100644
index 0000000..b607b86
--- /dev/null
+++ b/gremlin-python/src/main/resources/GraphTraversalSource.template
@@ -0,0 +1,96 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+'''
+
+import sys
+from .traversal import Traversal
+from .traversal import TraversalStrategies
+from .strategies import VertexProgramStrategy
+from .traversal import Bytecode
+from ..driver.remote_connection import RemoteStrategy
+from .. import statics
+from ..statics import long
+
+class GraphTraversalSource(object):
+ def __init__(self, graph, traversal_strategies, bytecode=None):
+ self.graph = graph
+ self.traversal_strategies = traversal_strategies
+ if bytecode is None:
+ bytecode = Bytecode()
+ self.bytecode = bytecode
+ def __repr__(self):
+ return "graphtraversalsource[" + str(self.graph) + "]"
+
+<% sourceStepMethods.each{ method -> %>
+ def <%= method %>(self, *args):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.bytecode.add_source("<%= toJava.call(method) %>", *args)
+ return source
+<% } %>
+
+ def withRemote(self, remote_connection):
+ source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
+ source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
+ return source
+ def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
+ return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
+
+<% sourceSpawnMethods.each { method -> %>
+ def <%= method %>(self, *args):
+ traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
+ traversal.bytecode.add_step("<%= toJava.call(method) %>", *args)
+ return traversal
+<% } %>
+
+class GraphTraversal(Traversal):
+ def __init__(self, graph, traversal_strategies, bytecode):
+ Traversal.__init__(self, graph, traversal_strategies, bytecode)
+ def __getitem__(self, index):
+ if isinstance(index, int):
+ return self.range(long(index), long(index + 1))
+ elif isinstance(index, slice):
+ return self.range(long(0) if index.start is None else long(index.start), long(sys.maxsize) if index.stop is None else long(index.stop))
+ else:
+ raise TypeError("Index must be int or slice")
+ def __getattr__(self, key):
+ return self.values(key)
+<% graphStepMethods.each { method -> %>
+ def <%= method %>(self, *args):
+ self.bytecode.add_step("<%= toJava.call(method) %>", *args)
+ return self
+<% } %>
+
+class __(object):
+ @staticmethod
+ def start():
+ return GraphTraversal(None, None, Bytecode())
+ @staticmethod
+ def __(*args):
+ return __.inject(*args)
+
+<% anonStepMethods.each{ method -> %>
+ @staticmethod
+ def <%= method %>(*args):
+ return GraphTraversal(None, None, Bytecode()).<%= method %>(*args)
+<% } %>
+
+<% anonStepMethods.each{ method -> %>
+def <%= method %>(*args):
+ return __.<%= method %>(*args)
+statics.add_static('<%= method %>', <%= method %>)
+<% } %>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/src/main/resources/TraversalSource.template
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/resources/TraversalSource.template b/gremlin-python/src/main/resources/TraversalSource.template
new file mode 100644
index 0000000..66ea940
--- /dev/null
+++ b/gremlin-python/src/main/resources/TraversalSource.template
@@ -0,0 +1,282 @@
+'''
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+'''
+
+from aenum import Enum
+from .. import statics
+from ..statics import long
+
+class Traversal(object):
+ def __init__(self, graph, traversal_strategies, bytecode):
+ self.graph = graph
+ self.traversal_strategies = traversal_strategies
+ self.bytecode = bytecode
+ self.side_effects = TraversalSideEffects()
+ self.traversers = None
+ self.last_traverser = None
+ def __repr__(self):
+ return str(self.bytecode)
+ def __eq__(self, other):
+ if isinstance(other, self.__class__):
+ return self.bytecode == other.bytecode
+ else:
+ return False
+ def __iter__(self):
+ return self
+ def __next__(self):
+ if self.traversers is None:
+ self.traversal_strategies.apply_strategies(self)
+ if self.last_traverser is None:
+ self.last_traverser = next(self.traversers)
+ object = self.last_traverser.object
+ self.last_traverser.bulk = self.last_traverser.bulk - 1
+ if self.last_traverser.bulk <= 0:
+ self.last_traverser = None
+ return object
+ def toList(self):
+ return list(iter(self))
+ def toSet(self):
+ return set(iter(self))
+ def iterate(self):
+ while True:
+ try: self.nextTraverser()
+ except StopIteration: return self
+ def nextTraverser(self):
+ if self.traversers is None:
+ self.traversal_strategies.apply_strategies(self)
+ if self.last_traverser is None:
+ return next(self.traversers)
+ else:
+ temp = self.last_traverser
+ self.last_traverser = None
+ return temp
+ def next(self, amount=None):
+ if amount is None:
+ return self.__next__()
+ else:
+ count = 0
+ tempList = []
+ while count < amount:
+ count = count + 1
+ try: temp = self.__next__()
+ except StopIteration: return tempList
+ tempList.append(temp)
+ return tempList
+ def promise(self, cb=None):
+ self.traversal_strategies.apply_async_strategies(self)
+ future_traversal = self.remote_results
+ future = type(future_traversal)()
+ def process(f):
+ try:
+ traversal = f.result()
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ self.traversers = iter(traversal.traversers)
+ self.side_effects = traversal.side_effects
+ if cb:
+ try:
+ result = cb(self)
+ except Exception as e:
+ future.set_exception(e)
+ else:
+ future.set_result(result)
+ else:
+ future.set_result(self)
+ future_traversal.add_done_callback(process)
+ return future
+
+<% enums.each { e -> %>
+<%= e.getSimpleName() %> = Enum('<%= e.getSimpleName() %>', ' <%= e.getEnumConstants().sort{a, b -> a.name() <=> b.name()}.collect{v -> toPython.call(v.name())}.join(" ") %>')
+<% e.getEnumConstants().each {v -> %>
+statics.add_static('<%= toPython.call(v.name()) %>', <%= v.getDeclaringClass().getSimpleName() %>.<%= toPython.call(v.name()) %>)<% } %>
+<% } %>
+
+class P(object):
+ def __init__(self, operator, value, other=None):
+ self.operator = operator
+ self.value = value
+ self.other = other
+
+<% pmethods.each { method -> %>
+ @staticmethod
+ def <%= method %>(*args):
+ return P("<%= toPython.call(method) %>", *args)
+<% } %>
+ def and_(self, arg):
+ return P("and", self, arg)
+ def or_(self, arg):
+ return P("or", self, arg)
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
+ def __repr__(self):
+ return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
+ def and_(self, arg):
+ return P("and", self, arg)
+ def or_(self, arg):
+ return P("or", self, arg)
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
+ def __repr__(self):
+ return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
+<% pmethods.findAll{!it.equals("clone")}.each { method -> %>
+def <%= method %>(*args):
+ return P.<%= method %>(*args)
+statics.add_static('<%= method %>',<%= method %>)
+<% } %>
+
+'''
+TRAVERSER
+'''
+
+class Traverser(object):
+ def __init__(self, object, bulk=None):
+ if bulk is None:
+ bulk = long(1)
+ self.object = object
+ self.bulk = bulk
+ def __repr__(self):
+ return str(self.object)
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.object == other.object
+
+'''
+TRAVERSAL SIDE-EFFECTS
+'''
+
+class TraversalSideEffects(object):
+ def keys(self):
+ return set()
+ def get(self, key):
+ raise KeyError(key)
+ def __getitem__(self, key):
+ return self.get(key)
+ def __repr__(self):
+ return "sideEffects[size:" + str(len(self.keys())) + "]"
+
+'''
+TRAVERSAL STRATEGIES
+'''
+
+class TraversalStrategies(object):
+ global_cache = {}
+ def __init__(self, traversal_strategies=None):
+ self.traversal_strategies = traversal_strategies.traversal_strategies if traversal_strategies is not None else []
+ def add_strategies(self, traversal_strategies):
+ self.traversal_strategies = self.traversal_strategies + traversal_strategies
+ def apply_strategies(self, traversal):
+ for traversal_strategy in self.traversal_strategies:
+ traversal_strategy.apply(traversal)
+ def apply_async_strategies(self, traversal):
+ for traversal_strategy in self.traversal_strategies:
+ traversal_strategy.apply_async(traversal)
+ def __repr__(self):
+ return str(self.traversal_strategies)
+
+
+class TraversalStrategy(object):
+ def __init__(self, strategy_name=None, configuration=None):
+ self.strategy_name = type(self).__name__ if strategy_name is None else strategy_name
+ self.configuration = {} if configuration is None else configuration
+ def apply(self, traversal):
+ return
+ def apply_async(self, traversal):
+ return
+ def __eq__(self, other):
+ return isinstance(other, self.__class__)
+ def __hash__(self):
+ return hash(self.strategy_name)
+ def __repr__(self):
+ return self.strategy_name
+
+'''
+BYTECODE
+'''
+
+class Bytecode(object):
+ def __init__(self, bytecode=None):
+ self.source_instructions = []
+ self.step_instructions = []
+ self.bindings = {}
+ if bytecode is not None:
+ self.source_instructions = list(bytecode.source_instructions)
+ self.step_instructions = list(bytecode.step_instructions)
+ def add_source(self, source_name, *args):
+ instruction = [source_name]
+ for arg in args:
+ instruction.append(self.__convertArgument(arg))
+ self.source_instructions.append(instruction)
+ def add_step(self, step_name, *args):
+ instruction = [step_name]
+ for arg in args:
+ instruction.append(self.__convertArgument(arg))
+ self.step_instructions.append(instruction)
+ def __eq__(self, other):
+ if isinstance(other, self.__class__):
+ return self.source_instructions == other.source_instructions and self.step_instructions == other.step_instructions
+ else:
+ return False
+ def __convertArgument(self,arg):
+ if isinstance(arg, Traversal):
+ self.bindings.update(arg.bytecode.bindings)
+ return arg.bytecode
+ elif isinstance(arg, dict):
+ newDict = {}
+ for key in arg:
+ newDict[self.__convertArgument(key)] = self.__convertArgument(arg[key])
+ return newDict
+ elif isinstance(arg, list):
+ newList = []
+ for item in arg:
+ newList.append(self.__convertArgument(item))
+ return newList
+ elif isinstance(arg, set):
+ newSet = set()
+ for item in arg:
+ newSet.add(self.__convertArgument(item))
+ return newSet
+ elif isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
+ self.bindings[arg[0]] = arg[1]
+ return Binding(arg[0],self.__convertArgument(arg[1]))
+ else:
+ return arg
+ def __repr__(self):
+ return (str(self.source_instructions) if len(self.source_instructions) > 0 else "") + \\
+ (str(self.step_instructions) if len(self.step_instructions) > 0 else "")
+
+
+'''
+BINDINGS
+'''
+
+class Bindings(object):
+ def of(self,key,value):
+ if not isinstance(key, str):
+ raise TypeError("Key must be str")
+ return (key,value)
+
+class Binding(object):
+ def __init__(self,key,value):
+ self.key = key
+ self.value = value
+ def __eq__(self, other):
+ return isinstance(other, self.__class__) and self.key == other.key and self.value == other.value
+ def __hash__(self):
+ return hash(self.key) + hash(self.value)
+ def __repr__(self):
+ return "binding[" + self.key + "=" + str(self.value) + "]"
\ No newline at end of file
[2/2] tinkerpop git commit: TINKERPOP-1618 Removed dependence on
groovy for gremlin-python
Posted by sp...@apache.org.
TINKERPOP-1618 Removed dependence on groovy for gremlin-python
Executed code generation with the gmaven plugin and the Groovy templating library. This approach also gets the files generated in a much earlier (and more correct) phase of the maven life cycle which may be important to other GLVs using this as a pattern.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0d6e0bb5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0d6e0bb5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0d6e0bb5
Branch: refs/heads/TINKERPOP-1618
Commit: 0d6e0bb512b6d9544957656315cf2c3b585ba86f
Parents: abe23d4
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri May 19 14:37:27 2017 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri May 19 14:37:27 2017 -0400
----------------------------------------------------------------------
gremlin-python/pom.xml | 120 +-
.../python/GraphTraversalSourceGenerator.groovy | 201 --
.../python/TraversalSourceGenerator.groovy | 356 ----
.../gremlin/python/GenerateGremlinPython.java | 32 -
.../gremlin_python/process/graph_traversal.py | 1758 ++++++++++--------
.../jython/gremlin_python/process/traversal.py | 192 +-
.../resources/GraphTraversalSource.template | 96 +
.../src/main/resources/TraversalSource.template | 282 +++
8 files changed, 1514 insertions(+), 1523 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/pom.xml
----------------------------------------------------------------------
diff --git a/gremlin-python/pom.xml b/gremlin-python/pom.xml
index 19d3041..96cbc51 100644
--- a/gremlin-python/pom.xml
+++ b/gremlin-python/pom.xml
@@ -32,12 +32,6 @@ limitations under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy</artifactId>
- <version>${groovy.version}</version>
- <classifier>indy</classifier>
- </dependency>
- <dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1b2</version>
@@ -90,32 +84,6 @@ limitations under the License.
</testResources>
<plugins>
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.2.1</version>
- <executions>
- <execution>
- <id>generate-python</id>
- <phase>generate-test-resources</phase>
- <goals>
- <goal>java</goal>
- </goals>
- <configuration>
- <mainClass>org.apache.tinkerpop.gremlin.python.GenerateGremlinPython</mainClass>
- <arguments>
- <argument>${basedir}/src/main/jython/gremlin_python/process/traversal.py</argument>
- <argument>${basedir}/src/main/jython/gremlin_python/process/graph_traversal.py
- </argument>
- </arguments>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.codehaus.gmavenplus</groupId>
- <artifactId>gmavenplus-plugin</artifactId>
- </plugin>
- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
@@ -511,6 +479,94 @@ limitations under the License.
</dependencies>
<executions>
<execution>
+ <id>generate-dsl</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <scripts>
+ <script><![CDATA[
+import org.apache.tinkerpop.gremlin.jsr223.CoreImports
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
+import org.apache.tinkerpop.gremlin.process.traversal.P
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
+import java.lang.reflect.Modifier
+
+// this is a bit of a copy of what's in SymbolHelper - no way around it because this code generation task occurs
+// before the SymbolHelper is available to the plugin.
+def toPythonMap = ["global": "global_",
+ "as": "as_",
+ "in": "in_",
+ "and": "and_",
+ "or": "or_",
+ "is": "is_",
+ "not": "not_",
+ "from": "from_",
+ "list": "list_",
+ "set": "set_",
+ "all": "all_"]
+def toJavaMap = toPythonMap.collectEntries{k,v -> [(v):k]}
+
+def toPython = { symbol -> toPythonMap.getOrDefault(symbol, symbol) }
+def toJava = { symbol -> toJavaMap.getOrDefault(symbol, symbol) }
+
+def binding = ["enums": CoreImports.getClassImports()
+ .findAll { Enum.class.isAssignableFrom(it) }
+ .sort { a, b -> a.getSimpleName() <=> b.getSimpleName() },
+ "pmethods": P.class.getMethods().
+ findAll { Modifier.isStatic(it.getModifiers()) }.
+ findAll { P.class.isAssignableFrom(it.returnType) }.
+ collect { toPython(it.name) }.
+ unique().
+ sort { a, b -> a <=> b },
+ "sourceStepMethods": GraphTraversalSource.getMethods(). // SOURCE STEPS
+ findAll { GraphTraversalSource.class.equals(it.returnType) }.
+ findAll {
+ !it.name.equals("clone") &&
+ !it.name.equals(TraversalSource.Symbols.withBindings) &&
+ !it.name.equals(TraversalSource.Symbols.withRemote) &&
+ !it.name.equals(TraversalSource.Symbols.withComputer)
+ }.
+ collect { toPython(it.name) }.
+ unique().
+ sort { a, b -> a <=> b },
+ "sourceSpawnMethods": GraphTraversalSource.getMethods(). // SPAWN STEPS
+ findAll { GraphTraversal.class.equals(it.returnType) }.
+ collect { toPython(it.name) }.
+ unique().
+ sort { a, b -> a <=> b },
+ "graphStepMethods": GraphTraversal.getMethods().
+ findAll { GraphTraversal.class.equals(it.returnType) }.
+ findAll { !it.name.equals("clone") && !it.name.equals("iterate") }.
+ collect { toPython(it.name) }.
+ unique().
+ sort { a, b -> a <=> b },
+ "anonStepMethods": __.class.getMethods().
+ findAll { GraphTraversal.class.equals(it.returnType) }.
+ findAll { Modifier.isStatic(it.getModifiers()) }.
+ findAll { !it.name.equals("__") && !it.name.equals("start") }.
+ collect { toPython(it.name) }.
+ unique().
+ sort { a, b -> a <=> b },
+ "toPython": toPython,
+ "toJava": toJava]
+
+def engine = new groovy.text.GStringTemplateEngine()
+def traversalTemplate = engine.createTemplate(new File('${project.basedir}/src/main/resources/TraversalSource.template')).make(binding)
+def traversalFile = new File('${project.basedir}/src/main/jython/gremlin_python/process/traversal.py')
+traversalFile.newWriter().withWriter{ it << traversalTemplate }
+
+def graphTraversalTemplate = engine.createTemplate(new File('${project.basedir}/src/main/resources/GraphTraversalSource.template')).make(binding)
+def graphTraversalFile = new File('${project.basedir}/src/main/jython/gremlin_python/process/graph_traversal.py')
+graphTraversalFile.newWriter().withWriter{ it << graphTraversalTemplate }
+]]> </script>
+ </scripts>
+ </configuration>
+ </execution>
+ <execution>
<id>gremlin-server-start</id>
<phase>pre-integration-test</phase>
<goals>
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
deleted file mode 100644
index 1c66c35..0000000
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.python
-
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource
-import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__
-import org.apache.tinkerpop.gremlin.python.jsr223.SymbolHelper
-
-import java.lang.reflect.Modifier
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-class GraphTraversalSourceGenerator {
-
- public static void create(final String graphTraversalSourceFile) {
-
- final StringBuilder pythonClass = new StringBuilder()
-
- pythonClass.append("""'''
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-'''
-""")
- pythonClass.append("import sys\n")
- pythonClass.append("from .traversal import Traversal\n")
- pythonClass.append("from .traversal import TraversalStrategies\n")
- pythonClass.append("from .strategies import VertexProgramStrategy\n")
- pythonClass.append("from .traversal import Bytecode\n")
- pythonClass.append("from ..driver.remote_connection import RemoteStrategy\n")
- pythonClass.append("from .. import statics\n")
- pythonClass.append("from ..statics import long\n\n")
-
-//////////////////////////
-// GraphTraversalSource //
-//////////////////////////
- pythonClass.append(
- """class GraphTraversalSource(object):
- def __init__(self, graph, traversal_strategies, bytecode=None):
- self.graph = graph
- self.traversal_strategies = traversal_strategies
- if bytecode is None:
- bytecode = Bytecode()
- self.bytecode = bytecode
- def __repr__(self):
- return "graphtraversalsource[" + str(self.graph) + "]"
-""")
- GraphTraversalSource.getMethods(). // SOURCE STEPS
- findAll { GraphTraversalSource.class.equals(it.returnType) }.
- findAll {
- !it.name.equals("clone") &&
- !it.name.equals(TraversalSource.Symbols.withBindings) &&
- !it.name.equals(TraversalSource.Symbols.withRemote) &&
- !it.name.equals(TraversalSource.Symbols.withComputer)
- }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach { method ->
- pythonClass.append(
- """ def ${method}(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("${SymbolHelper.toJava(method)}", *args)
- return source
-""")
- }
- pythonClass.append(
- """ def withRemote(self, remote_connection):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
- return source
- def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
- return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
-""")
- GraphTraversalSource.getMethods(). // SPAWN STEPS
- findAll { GraphTraversal.class.equals(it.returnType) }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach { method ->
- pythonClass.append(
- """ def ${method}(self, *args):
- traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
- traversal.bytecode.add_step("${SymbolHelper.toJava(method)}", *args)
- return traversal
-""")
- }
- pythonClass.append("\n\n")
-
-////////////////////
-// GraphTraversal //
-////////////////////
- pythonClass.append(
- """class GraphTraversal(Traversal):
- def __init__(self, graph, traversal_strategies, bytecode):
- Traversal.__init__(self, graph, traversal_strategies, bytecode)
- def __getitem__(self, index):
- if isinstance(index, int):
- return self.range(long(index), long(index + 1))
- elif isinstance(index, slice):
- return self.range(long(0) if index.start is None else long(index.start), long(sys.maxsize) if index.stop is None else long(index.stop))
- else:
- raise TypeError("Index must be int or slice")
- def __getattr__(self, key):
- return self.values(key)
-""")
- GraphTraversal.getMethods().
- findAll { GraphTraversal.class.equals(it.returnType) }.
- findAll { !it.name.equals("clone") && !it.name.equals("iterate") }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach { method ->
- pythonClass.append(
- """ def ${method}(self, *args):
- self.bytecode.add_step("${SymbolHelper.toJava(method)}", *args)
- return self
-""")
- };
- pythonClass.append("\n\n")
-
-////////////////////////
-// AnonymousTraversal //
-////////////////////////
- pythonClass.append(
- """class __(object):
- @staticmethod
- def start():
- return GraphTraversal(None, None, Bytecode())
- @staticmethod
- def __(*args):
- return __.inject(*args)
-""")
- __.class.getMethods().
- findAll { GraphTraversal.class.equals(it.returnType) }.
- findAll { Modifier.isStatic(it.getModifiers()) }.
- findAll { !it.name.equals("__") && !it.name.equals("start") }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach { method ->
- pythonClass.append(
- """ @staticmethod
- def ${method}(*args):
- return GraphTraversal(None, None, Bytecode()).${method}(*args)
-""")
- };
- pythonClass.append("\n\n")
- // add to gremlin.python.statics
- __.class.getMethods().
- findAll { GraphTraversal.class.equals(it.returnType) }.
- findAll { Modifier.isStatic(it.getModifiers()) }.
- findAll { !it.name.equals("__") && !it.name.equals("start") }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach {
- pythonClass.append("def ${it}(*args):\n").append(" return __.${it}(*args)\n\n")
- pythonClass.append("statics.add_static('${it}', ${it})\n\n")
- }
- pythonClass.append("\n\n")
-
-// save to a python file
- final File file = new File(graphTraversalSourceFile);
- file.delete()
- pythonClass.eachLine { file.append(it + "\n") }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/TraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/TraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/TraversalSourceGenerator.groovy
deleted file mode 100644
index 995fe80..0000000
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/TraversalSourceGenerator.groovy
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.python
-
-import org.apache.tinkerpop.gremlin.jsr223.CoreImports
-import org.apache.tinkerpop.gremlin.process.traversal.P
-import org.apache.tinkerpop.gremlin.python.jsr223.SymbolHelper
-
-import java.lang.reflect.Modifier
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-class TraversalSourceGenerator {
-
- public static void create(final String traversalSourceFile) {
-
- final StringBuilder pythonClass = new StringBuilder()
-
- pythonClass.append("""'''
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements. See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership. The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at
-
-http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing,
-software distributed under the License is distributed on an
-"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-KIND, either express or implied. See the License for the
-specific language governing permissions and limitations
-under the License.
-'''
-""")
- pythonClass.append("from aenum import Enum\n")
- pythonClass.append("from .. import statics\n")
- pythonClass.append("from ..statics import long\n\n")
-
- pythonClass.append("""
-class Traversal(object):
- def __init__(self, graph, traversal_strategies, bytecode):
- self.graph = graph
- self.traversal_strategies = traversal_strategies
- self.bytecode = bytecode
- self.side_effects = TraversalSideEffects()
- self.traversers = None
- self.last_traverser = None
- def __repr__(self):
- return str(self.bytecode)
- def __eq__(self, other):
- if isinstance(other, self.__class__):
- return self.bytecode == other.bytecode
- else:
- return False
- def __iter__(self):
- return self
- def __next__(self):
- if self.traversers is None:
- self.traversal_strategies.apply_strategies(self)
- if self.last_traverser is None:
- self.last_traverser = next(self.traversers)
- object = self.last_traverser.object
- self.last_traverser.bulk = self.last_traverser.bulk - 1
- if self.last_traverser.bulk <= 0:
- self.last_traverser = None
- return object
- def toList(self):
- return list(iter(self))
- def toSet(self):
- return set(iter(self))
- def iterate(self):
- while True:
- try: self.nextTraverser()
- except StopIteration: return self
- def nextTraverser(self):
- if self.traversers is None:
- self.traversal_strategies.apply_strategies(self)
- if self.last_traverser is None:
- return next(self.traversers)
- else:
- temp = self.last_traverser
- self.last_traverser = None
- return temp
- def next(self, amount=None):
- if amount is None:
- return self.__next__()
- else:
- count = 0
- tempList = []
- while count < amount:
- count = count + 1
- try: temp = self.__next__()
- except StopIteration: return tempList
- tempList.append(temp)
- return tempList
- def promise(self, cb=None):
- self.traversal_strategies.apply_async_strategies(self)
- future_traversal = self.remote_results
- future = type(future_traversal)()
- def process(f):
- try:
- traversal = f.result()
- except Exception as e:
- future.set_exception(e)
- else:
- self.traversers = iter(traversal.traversers)
- self.side_effects = traversal.side_effects
- if cb:
- try:
- result = cb(self)
- except Exception as e:
- future.set_exception(e)
- else:
- future.set_result(result)
- else:
- future.set_result(self)
- future_traversal.add_done_callback(process)
- return future
-
-
-""")
-
-///////////
-// Enums //
-///////////
- for (final Class<? extends Enum> enumClass : CoreImports.getClassImports()
- .findAll { Enum.class.isAssignableFrom(it) }
- .sort { a, b -> a.getSimpleName() <=> b.getSimpleName() }
- .collect()) {
- pythonClass.append("${enumClass.getSimpleName()} = Enum('${enumClass.getSimpleName()}', '");
- enumClass.getEnumConstants()
- .sort { a, b -> a.name() <=> b.name() }
- .each { value -> pythonClass.append("${SymbolHelper.toPython(value.name())} "); }
- pythonClass.deleteCharAt(pythonClass.length() - 1).append("')\n")
- enumClass.getEnumConstants().each { value ->
- pythonClass.append("statics.add_static('${SymbolHelper.toPython(value.name())}', ${value.getDeclaringClass().getSimpleName()}.${SymbolHelper.toPython(value.name())})\n");
- }
- pythonClass.append("\n");
- }
- //////////////
-
- pythonClass.append("""class P(object):
- def __init__(self, operator, value, other=None):
- self.operator = operator
- self.value = value
- self.other = other
-""")
- P.class.getMethods().
- findAll { Modifier.isStatic(it.getModifiers()) }.
- findAll { P.class.isAssignableFrom(it.returnType) }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- each { method ->
- pythonClass.append(
- """ @staticmethod
- def ${method}(*args):
- return P("${SymbolHelper.toJava(method)}", *args)
-""")
- };
- pythonClass.append(""" def and_(self, arg):
- return P("and", self, arg)
- def or_(self, arg):
- return P("or", self, arg)
- def __eq__(self, other):
- return isinstance(other, self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
- def __repr__(self):
- return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(self.value) + "," + str(self.other) + ")"
-""")
- pythonClass.append("\n")
- P.class.getMethods().
- findAll { Modifier.isStatic(it.getModifiers()) }.
- findAll { !it.name.equals("clone") }.
- findAll { P.class.isAssignableFrom(it.getReturnType()) }.
- collect { SymbolHelper.toPython(it.name) }.
- unique().
- sort { a, b -> a <=> b }.
- forEach {
- pythonClass.append("def ${it}(*args):\n").append(" return P.${it}(*args)\n")
- pythonClass.append("statics.add_static('${it}',${it})\n\n")
- }
- pythonClass.append("\n")
- //////////////
-
- pythonClass.append("""
-'''
-TRAVERSER
-'''
-
-class Traverser(object):
- def __init__(self, object, bulk=None):
- if bulk is None:
- bulk = long(1)
- self.object = object
- self.bulk = bulk
- def __repr__(self):
- return str(self.object)
- def __eq__(self, other):
- return isinstance(other, self.__class__) and self.object == other.object
-
-'''
-TRAVERSAL SIDE-EFFECTS
-'''
-
-class TraversalSideEffects(object):
- def keys(self):
- return set()
- def get(self, key):
- raise KeyError(key)
- def __getitem__(self, key):
- return self.get(key)
- def __repr__(self):
- return "sideEffects[size:" + str(len(self.keys())) + "]"
-
-'''
-TRAVERSAL STRATEGIES
-'''
-
-class TraversalStrategies(object):
- global_cache = {}
- def __init__(self, traversal_strategies=None):
- self.traversal_strategies = traversal_strategies.traversal_strategies if traversal_strategies is not None else []
- def add_strategies(self, traversal_strategies):
- self.traversal_strategies = self.traversal_strategies + traversal_strategies
- def apply_strategies(self, traversal):
- for traversal_strategy in self.traversal_strategies:
- traversal_strategy.apply(traversal)
- def apply_async_strategies(self, traversal):
- for traversal_strategy in self.traversal_strategies:
- traversal_strategy.apply_async(traversal)
- def __repr__(self):
- return str(self.traversal_strategies)
-
-
-class TraversalStrategy(object):
- def __init__(self, strategy_name=None, configuration=None):
- self.strategy_name = type(self).__name__ if strategy_name is None else strategy_name
- self.configuration = {} if configuration is None else configuration
- def apply(self, traversal):
- return
- def apply_async(self, traversal):
- return
- def __eq__(self, other):
- return isinstance(other, self.__class__)
- def __hash__(self):
- return hash(self.strategy_name)
- def __repr__(self):
- return self.strategy_name
-
-'''
-BYTECODE
-'''
-
-class Bytecode(object):
- def __init__(self, bytecode=None):
- self.source_instructions = []
- self.step_instructions = []
- self.bindings = {}
- if bytecode is not None:
- self.source_instructions = list(bytecode.source_instructions)
- self.step_instructions = list(bytecode.step_instructions)
- def add_source(self, source_name, *args):
- instruction = [source_name]
- for arg in args:
- instruction.append(self.__convertArgument(arg))
- self.source_instructions.append(instruction)
- def add_step(self, step_name, *args):
- instruction = [step_name]
- for arg in args:
- instruction.append(self.__convertArgument(arg))
- self.step_instructions.append(instruction)
- def __eq__(self, other):
- if isinstance(other, self.__class__):
- return self.source_instructions == other.source_instructions and self.step_instructions == other.step_instructions
- else:
- return False
- def __convertArgument(self,arg):
- if isinstance(arg, Traversal):
- self.bindings.update(arg.bytecode.bindings)
- return arg.bytecode
- elif isinstance(arg, dict):
- newDict = {}
- for key in arg:
- newDict[self.__convertArgument(key)] = self.__convertArgument(arg[key])
- return newDict
- elif isinstance(arg, list):
- newList = []
- for item in arg:
- newList.append(self.__convertArgument(item))
- return newList
- elif isinstance(arg, set):
- newSet = set()
- for item in arg:
- newSet.add(self.__convertArgument(item))
- return newSet
- elif isinstance(arg, tuple) and 2 == len(arg) and isinstance(arg[0], str):
- self.bindings[arg[0]] = arg[1]
- return Binding(arg[0],self.__convertArgument(arg[1]))
- else:
- return arg
- def __repr__(self):
- return (str(self.source_instructions) if len(self.source_instructions) > 0 else "") + \\
- (str(self.step_instructions) if len(self.step_instructions) > 0 else "")
-
-
-'''
-BINDINGS
-'''
-
-class Bindings(object):
- def of(self,key,value):
- if not isinstance(key, str):
- raise TypeError("Key must be str")
- return (key,value)
-
-class Binding(object):
- def __init__(self,key,value):
- self.key = key
- self.value = value
- def __eq__(self, other):
- return isinstance(other, self.__class__) and self.key == other.key and self.value == other.value
- def __hash__(self):
- return hash(self.key) + hash(self.value)
- def __repr__(self):
- return "binding[" + self.key + "=" + str(self.value) + "]"
-
-""")
- //////////////
-
- // save to a python file
- final File file = new File(traversalSourceFile);
- file.delete()
- pythonClass.eachLine { file.append(it + "\n") }
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0d6e0bb5/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
deleted file mode 100644
index 6d8f04d..0000000
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/GenerateGremlinPython.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tinkerpop.gremlin.python;
-
-public class GenerateGremlinPython {
-
- private GenerateGremlinPython() {
- // just need the main method
- }
-
- public static void main(String[] args) {
- TraversalSourceGenerator.create(args[0]);
- GraphTraversalSourceGenerator.create(args[1]);
- }
-}