Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Goblin OGM
Goblin
Commits
f80a5ab5
Commit
f80a5ab5
authored
Jul 10, 2016
by
davebshow
Browse files
simple async remote graph interface
parent
415da694
Changes
16
Hide whitespace changes
Inline
Side-by-side
goblin/driver/connection.py
View file @
f80a5ab5
...
...
@@ -77,6 +77,10 @@ class Connection(AbstractConnection):
def
force_close
(
self
):
return
self
.
_force_close
@
property
def
url
(
self
):
return
self
.
_url
async
def
submit
(
self
,
gremlin
,
*
,
...
...
goblin/driver/graph.py
0 → 100644
View file @
f80a5ab5
from
goblin.gremlin_python.process.graph_traversal
import
GraphTraversalSource
,
GraphTraversal
from
goblin.gremlin_python.process.traversal
import
TraversalStrategy
,
TraversalStrategies
class
AsyncGraphTraversal
(
GraphTraversal
):
def
__init__
(
self
,
graph
,
traversal_strategies
,
bytecode
):
GraphTraversal
.
__init__
(
self
,
graph
,
traversal_strategies
,
bytecode
)
def
__repr__
(
self
):
return
self
.
graph
.
translator
.
translate
(
self
.
bytecode
)
def
toList
(
self
):
raise
NotImplementedError
def
toSet
(
self
):
raise
NotImplementedError
async
def
next
(
self
):
resp
=
await
self
.
traversal_strategies
.
apply
(
self
)
return
resp
class
AsyncRemoteStrategy
(
TraversalStrategy
):
async
def
apply
(
self
,
traversal
):
result
=
await
traversal
.
graph
.
remote_connection
.
submit
(
traversal
.
graph
.
translator
.
translate
(
traversal
.
bytecode
),
bindings
=
traversal
.
bindings
,
lang
=
traversal
.
graph
.
translator
.
target_language
)
return
result
class
AsyncGraph
(
object
):
def
traversal
(
self
):
return
GraphTraversalSource
(
self
,
self
.
traversal_strategy
,
graph_traversal
=
AsyncGraphTraversal
)
class
AsyncRemoteGraph
(
AsyncGraph
):
def
__init__
(
self
,
translator
,
remote_connection
):
self
.
traversal_strategy
=
AsyncRemoteStrategy
()
# A single traversal strategy
self
.
translator
=
translator
self
.
remote_connection
=
remote_connection
def
__repr__
(
self
):
return
"remotegraph["
+
self
.
remote_connection
.
url
+
"]"
goblin/gremlin_python/__init__.py
View file @
f80a5ab5
...
...
@@ -16,6 +16,6 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
import
statics
from
.
import
statics
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
goblin/gremlin_python/driver/__init__.py
View file @
f80a5ab5
...
...
@@ -16,7 +16,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
from
remote_connection
import
RemoteConnection
from
rest_remote_connection
import
RESTRemoteConnection
from
.
remote_connection
import
RemoteConnection
from
.
rest_remote_connection
import
RESTRemoteConnection
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
goblin/gremlin_python/driver/rest_remote_connection.py
View file @
f80a5ab5
...
...
@@ -19,8 +19,8 @@ under the License.
import
json
import
requests
from
gremlin_python.process.traversal
import
Traverser
from
remote_connection
import
RemoteConnection
from
goblin.
gremlin_python.process.traversal
import
Traverser
from
.
remote_connection
import
RemoteConnection
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
...
...
goblin/gremlin_python/process/__init__.py
View file @
f80a5ab5
...
...
@@ -17,22 +17,22 @@ specific language governing permissions and limitations
under the License.
'''
from
graph_traversal
import
GraphTraversal
from
graph_traversal
import
GraphTraversalSource
from
graph_traversal
import
__
from
groovy_translator
import
GroovyTranslator
from
jython_translator
import
JythonTranslator
from
traversal
import
Barrier
from
traversal
import
Bytecode
from
traversal
import
Cardinality
from
traversal
import
Column
from
traversal
import
Direction
from
traversal
import
Operator
from
traversal
import
Order
from
traversal
import
P
from
traversal
import
Pop
from
traversal
import
Scope
from
traversal
import
T
from
traversal
import
Traversal
from
.
graph_traversal
import
GraphTraversal
from
.
graph_traversal
import
GraphTraversalSource
from
.
graph_traversal
import
__
from
.
groovy_translator
import
GroovyTranslator
from
.
jython_translator
import
JythonTranslator
from
.
traversal
import
Barrier
from
.
traversal
import
Bytecode
from
.
traversal
import
Cardinality
from
.
traversal
import
Column
from
.
traversal
import
Direction
from
.
traversal
import
Operator
from
.
traversal
import
Order
from
.
traversal
import
P
from
.
traversal
import
Pop
from
.
traversal
import
Scope
from
.
traversal
import
T
from
.
traversal
import
Traversal
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
goblin/gremlin_python/process/graph_traversal.py
View file @
f80a5ab5
...
...
@@ -16,20 +16,23 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
from
traversal
import
RawExpression
from
traversal
import
Traversal
from
traversal
import
Bytecode
from
gremlin_python
import
statics
from
.
traversal
import
RawExpression
from
.
traversal
import
Traversal
from
.
traversal
import
Bytecode
from
goblin.
gremlin_python
import
statics
class
GraphTraversalSource
(
object
):
def
__init__
(
self
,
graph
,
traversal_strategies
,
bytecode
=
Bytecode
()):
def
__init__
(
self
,
graph
,
traversal_strategies
,
graph_traversal
=
None
,
bytecode
=
Bytecode
()):
self
.
graph
=
graph
self
.
traversal_strategies
=
traversal_strategies
if
graph_traversal
is
None
:
graph_traversal
=
GraphTraversal
self
.
graph_traversal
=
graph_traversal
self
.
bytecode
=
bytecode
def
__repr__
(
self
):
return
"graphtraversalsource["
+
str
(
self
.
graph
)
+
"]"
def
E
(
self
,
*
args
):
traversal
=
G
raph
T
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
=
self
.
g
raph
_t
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
.
bytecode
.
add_step
(
"E"
,
*
args
)
for
arg
in
args
:
if
isinstance
(
arg
,
tuple
)
and
2
==
len
(
arg
)
and
isinstance
(
arg
[
0
],
str
):
...
...
@@ -38,7 +41,7 @@ class GraphTraversalSource(object):
self
.
bindings
.
update
(
arg
.
bindings
)
return
traversal
def
V
(
self
,
*
args
):
traversal
=
G
raph
T
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
=
self
.
g
raph
_t
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
.
bytecode
.
add_step
(
"V"
,
*
args
)
for
arg
in
args
:
if
isinstance
(
arg
,
tuple
)
and
2
==
len
(
arg
)
and
isinstance
(
arg
[
0
],
str
):
...
...
@@ -47,7 +50,7 @@ class GraphTraversalSource(object):
self
.
bindings
.
update
(
arg
.
bindings
)
return
traversal
def
addV
(
self
,
*
args
):
traversal
=
G
raph
T
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
=
self
.
g
raph
_t
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
.
bytecode
.
add_step
(
"addV"
,
*
args
)
for
arg
in
args
:
if
isinstance
(
arg
,
tuple
)
and
2
==
len
(
arg
)
and
isinstance
(
arg
[
0
],
str
):
...
...
@@ -56,7 +59,7 @@ class GraphTraversalSource(object):
self
.
bindings
.
update
(
arg
.
bindings
)
return
traversal
def
inject
(
self
,
*
args
):
traversal
=
G
raph
T
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
=
self
.
g
raph
_t
raversal
(
self
.
graph
,
self
.
traversal_strategies
,
Bytecode
(
self
.
bytecode
))
traversal
.
bytecode
.
add_step
(
"inject"
,
*
args
)
for
arg
in
args
:
if
isinstance
(
arg
,
tuple
)
and
2
==
len
(
arg
)
and
isinstance
(
arg
[
0
],
str
):
...
...
@@ -1684,6 +1687,3 @@ def where(*args):
return
__
.
where
(
*
args
)
statics
.
add_static
(
'where'
,
where
)
goblin/gremlin_python/process/groovy_translator.py
View file @
f80a5ab5
...
...
@@ -20,11 +20,11 @@ under the License.
import
sys
from
aenum
import
Enum
from
traversal
import
Bytecode
from
traversal
import
P
from
traversal
import
RawExpression
from
traversal
import
SymbolHelper
from
traversal
import
Translator
from
.
traversal
import
Bytecode
from
.
traversal
import
P
from
.
traversal
import
RawExpression
from
.
traversal
import
SymbolHelper
from
.
traversal
import
Translator
if
sys
.
version_info
.
major
>
2
:
long
=
int
...
...
goblin/gremlin_python/process/jython_translator.py
View file @
f80a5ab5
...
...
@@ -21,14 +21,14 @@ import inspect
import
sys
from
aenum
import
Enum
from
traversal
import
Barrier
from
traversal
import
Bytecode
from
traversal
import
Cardinality
from
traversal
import
Column
from
traversal
import
P
from
traversal
import
RawExpression
from
traversal
import
SymbolHelper
from
traversal
import
Translator
from
.
traversal
import
Barrier
from
.
traversal
import
Bytecode
from
.
traversal
import
Cardinality
from
.
traversal
import
Column
from
.
traversal
import
P
from
.
traversal
import
RawExpression
from
.
traversal
import
SymbolHelper
from
.
traversal
import
Translator
if
sys
.
version_info
.
major
>
2
:
long
=
int
...
...
@@ -57,7 +57,7 @@ class JythonTranslator(Translator):
if
isinstance
(
arg
,
str
):
return
"
\"
"
+
arg
+
"
\"
"
elif
isinstance
(
arg
,
long
):
return
str
(
arg
)
+
"L"
if
arg
>
9223372036854775807L
else
"Long("
+
str
(
arg
)
+
")"
return
str
(
arg
)
elif
isinstance
(
arg
,
Barrier
):
return
"Barrier"
+
"."
+
SymbolHelper
.
toJava
(
str
(
arg
.
name
))
elif
isinstance
(
arg
,
Column
):
...
...
goblin/gremlin_python/process/traversal.py
View file @
f80a5ab5
...
...
@@ -18,7 +18,7 @@ under the License.
'''
from
abc
import
abstractmethod
from
aenum
import
Enum
from
gremlin_python
import
statics
from
goblin.
gremlin_python
import
statics
class
Traversal
(
object
):
def
__init__
(
self
,
graph
,
traversal_strategies
,
bytecode
):
...
...
goblin/gremlin_python/structure/__init__.py
View file @
f80a5ab5
...
...
@@ -16,7 +16,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
'''
from
graph
import
Graph
from
remote_graph
import
RemoteGraph
from
.
graph
import
Graph
from
.
remote_graph
import
RemoteGraph
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
goblin/gremlin_python/structure/graph.py
View file @
f80a5ab5
...
...
@@ -19,8 +19,8 @@ under the License.
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
from
gremlin_python.process.graph_traversal
import
GraphTraversalSource
from
gremlin_python.process.traversal
import
TraversalStrategies
from
goblin.
gremlin_python.process.graph_traversal
import
GraphTraversalSource
from
goblin.
gremlin_python.process.traversal
import
TraversalStrategies
class
Graph
(
object
):
...
...
goblin/gremlin_python/structure/remote_graph.py
View file @
f80a5ab5
...
...
@@ -19,9 +19,9 @@ under the License.
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
from
graph
import
Graph
from
gremlin_python.process.traversal
import
TraversalStrategies
from
gremlin_python.process.traversal
import
TraversalStrategy
from
.
graph
import
Graph
from
goblin.
gremlin_python.process.traversal
import
TraversalStrategies
from
goblin.
gremlin_python.process.traversal
import
TraversalStrategy
class
RemoteGraph
(
Graph
):
...
...
goblin/query.py
View file @
f80a5ab5
...
...
@@ -2,7 +2,7 @@
import
asyncio
import
logging
from
goblin
import
gremlin_python
from
goblin
.
gremlin_python
import
process
from
goblin
import
mapper
...
...
@@ -35,7 +35,7 @@ class QueryResponse:
raise
StopAsyncIteration
class
GoblinTraversal
(
gremlin_python
.
Python
GraphTraversal
):
class
GoblinTraversal
(
process
.
GraphTraversal
):
def
__init__
(
self
,
translator
,
query
,
element_class
):
super
().
__init__
(
translator
,
remote_connection
=
None
)
...
...
@@ -57,7 +57,7 @@ class Query:
def
__init__
(
self
,
session
,
translator
,
loop
):
self
.
_session
=
session
self
.
_translator
=
translator
self
.
_traversal_source
=
gremlin_python
.
PythonGraphTraversalSource
(
self
.
_traversal_source
=
process
.
PythonGraphTraversalSource
(
self
.
_translator
)
self
.
_loop
=
loop
self
.
_binding
=
0
...
...
setup.py
View file @
f80a5ab5
...
...
@@ -9,7 +9,8 @@ setup(
author
=
"davebshow"
,
author_email
=
"davebshow@gmail.com"
,
description
=
"Python driver for TP3 Gremlin Server"
,
packages
=
[
"goblin"
,
"goblin.gremlin_python"
,
packages
=
[
"goblin"
,
"goblin.gremlin_python"
,
"goblin.gremlin_python.process"
,
"goblin.gremlin_python.driver"
,
"goblin.gremlin_python.structure"
,
"goblin.driver"
,
"tests"
],
install_requires
=
[
"aenum==1.4.5"
,
...
...
tests/test_driver.py
View file @
f80a5ab5
...
...
@@ -2,6 +2,8 @@ import asyncio
import
unittest
from
goblin
import
driver
from
goblin.driver
import
graph
from
goblin.gremlin_python
import
process
class
TestDriver
(
unittest
.
TestCase
):
...
...
@@ -42,3 +44,17 @@ class TestDriver(unittest.TestCase):
await
connection
.
close
()
self
.
loop
.
run_until_complete
(
go
())
def
test_async_graph
(
self
):
async
def
go
():
translator
=
process
.
GroovyTranslator
(
'g'
)
connection
=
await
driver
.
GremlinServer
.
open
(
"http://localhost:8182/"
,
self
.
loop
)
g
=
graph
.
AsyncRemoteGraph
(
translator
,
connection
)
traversal
=
g
.
traversal
()
resp
=
await
traversal
.
V
().
next
()
async
for
msg
in
resp
:
print
(
msg
)
await
connection
.
close
()
self
.
loop
.
run_until_complete
(
go
())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment