You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by kr...@apache.org on 2021/02/24 19:40:25 UTC
[tinkerpop] branch TINKERPOP-2527 updated: Add license header and
additional comments
This is an automated email from the ASF dual-hosted git repository.
krlawrence pushed a commit to branch TINKERPOP-2527
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/TINKERPOP-2527 by this push:
new 197fdb4 Add license header and additional comments
197fdb4 is described below
commit 197fdb49864bf41c51efdb26e0d4cb27f14dd590
Author: Kelvin Lawrence <gf...@yahoo.com>
AuthorDate: Wed Feb 24 13:39:59 2021 -0600
Add license header and additional comments
---
.../python/gremlin_python/process/translator.py | 38 ++++++++++++++++++++--
.../main/python/tests/process/test_translator.py | 17 ++++++++++
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/gremlin-python/src/main/python/gremlin_python/process/translator.py b/gremlin-python/src/main/python/gremlin_python/process/translator.py
index e1610d1..f7a9b57 100755
--- a/gremlin-python/src/main/python/gremlin_python/process/translator.py
+++ b/gremlin-python/src/main/python/gremlin_python/process/translator.py
@@ -1,3 +1,22 @@
+#
+# 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.
+#
+
'''
Class that can turn traversals back into Gremlin Groovy format text queries.
Those queries can then be run in the Gremlin console or using the GLV submit(<String>) API or
@@ -18,6 +37,8 @@ class Translator:
"""
Turn a bytecode object back into a textual query (Gremlin Groovy script).
"""
+
+ # Dictionary used to reverse-map token IDs to strings
options = {
WithOptions.tokens: 'tokens',
WithOptions.none: 'none',
@@ -44,6 +65,8 @@ class Translator:
self.traversal_source = traversal_source
return self
+ # Do any needed special processing for the representation
+ # of strings and dates.
def fixup(self,v):
if type(v) == str:
return f'\'{v}\''
@@ -51,7 +74,8 @@ class Translator:
return self.process_date(v)
else:
return str(v)
-
+
+ # Turn a Python datetime into the equivalent new Date(...)
def process_date(selfself,date):
y = date.year - 1900
mo = date.month
@@ -61,6 +85,8 @@ class Translator:
s = date.second
return f'new Date({y},{mo},{d},{h},{mi},{s})'
+ # Do special processing needed to format predicates that come in
+ # such as "gt(a)" correctly.
def process_predicate(self,p):
res = str(p).split('(')[0] + '('
@@ -76,6 +102,7 @@ class Translator:
res += ')'
return res
+ # Special processing to handle strategies
def process_strategy(self,s):
c = 0
res = f'new {str(s)}('
@@ -92,6 +119,8 @@ class Translator:
return res
pass
+ # Main driver of the translation. Different parts of
+ # a Traversal are handled appropriately.
def do_translation(self,step):
script = ''
params = step[1:]
@@ -126,15 +155,18 @@ class Translator:
script += ')'
return script
+ # Translation starts here. There are two main parts to a
+ # traversal. Source instructions such as "withSideffect"
+ # and "withStrategies", and step instructions such as
+ # "addV" and "repeat". If child is True we will generate
+ # anonymous traversal style syntax.
def translate(self,bytecode,child=False):
script = '__' if child else self.traversal_source
for step in bytecode.source_instructions:
- #print(f'Source {step}')
script += self.do_translation(step)
for step in bytecode.step_instructions:
- #print(f'Step {step}')
script += self.do_translation(step)
return script
diff --git a/gremlin-python/src/main/python/tests/process/test_translator.py b/gremlin-python/src/main/python/tests/process/test_translator.py
index fdd21c1..c2e62ad 100644
--- a/gremlin-python/src/main/python/tests/process/test_translator.py
+++ b/gremlin-python/src/main/python/tests/process/test_translator.py
@@ -1,3 +1,20 @@
+# 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.
+#
'''
Unit tests for the Translator Class.