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
Guy Rozendorn
AIO Gremlin
Commits
f3204153
Commit
f3204153
authored
Jun 08, 2017
by
davebshow
Browse files
implement aiogremlin as an async 'dsl'
parent
33567e96
Changes
53
Expand all
Hide whitespace changes
Inline
Side-by-side
aiogremlin/__init__.py
View file @
f3204153
from
aiogremlin.driver.cluster
import
Cluster
from
aiogremlin.remote.driver_remote_connection
import
DriverRemoteConnection
from
aiogremlin.
gremlin_python.
structure.graph
import
Graph
from
aiogremlin.structure.graph
import
Graph
__version__
=
"3.2.4"
aiogremlin/driver/aiohttp/transport.py
View file @
f3204153
import
aiohttp
from
aiogremlin.
gremlin_python.driver
import
transport
from
gremlin_python.driver
import
transport
class
AiohttpTransport
(
transport
.
AbstractBaseTransport
):
...
...
aiogremlin/driver/client.py
View file @
f3204153
"""Client for the Tinkerpop 3 Gremlin Server."""
from
aiogremlin
import
exception
from
aiogremlin.gremlin_python.driver
import
request
from
aiogremlin.gremlin_python.process
import
traversal
from
gremlin_python.driver
import
request
from
gremlin_python.process
import
traversal
class
Client
:
...
...
@@ -58,8 +59,8 @@ class Client:
**coroutine** Submit a script and bindings to the Gremlin Server.
:param message: Can be an instance of
`Message<
aiogremlin.
gremlin_python.request.RequestMessage>` or
`Bytecode<
aiogremlin.
gremlin_python.process.traversal.Bytecode>`
`Message<gremlin_python.request.RequestMessage>` or
`Bytecode<gremlin_python.process.traversal.Bytecode>`
or a `str` representing a raw Gremlin script
:param dict bindings: Optional bindings used with raw Grelmin
:returns: :py:class:`ResultSet<aiogremlin.driver.resultset.ResultSet>`
...
...
aiogremlin/driver/cluster.py
View file @
f3204153
...
...
@@ -12,7 +12,7 @@ import yaml
from
aiogremlin
import
exception
from
aiogremlin
import
driver
from
aiogremlin.
gremlin_python.driver
import
serializer
from
gremlin_python.driver
import
serializer
def
my_import
(
name
):
...
...
@@ -52,7 +52,7 @@ class Cluster:
'min_conns'
:
1
,
'max_times_acquired'
:
16
,
'max_inflight'
:
64
,
'message_serializer'
:
'
aiogremlin.
gremlin_python.driver.serializer.GraphSONMessageSerializer'
,
'message_serializer'
:
'gremlin_python.driver.serializer.GraphSONMessageSerializer'
,
'provider'
:
'aiogremlin.driver.provider.TinkerGraph'
}
...
...
aiogremlin/driver/connection.py
View file @
f3204153
...
...
@@ -15,7 +15,7 @@ except ImportError:
from
aiogremlin.driver
import
provider
,
resultset
from
aiogremlin.driver.protocol
import
GremlinServerWSProtocol
from
aiogremlin.driver.aiohttp.transport
import
AiohttpTransport
from
aiogremlin.
gremlin_python.driver
import
serializer
from
gremlin_python.driver
import
serializer
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -28,9 +28,9 @@ class Connection:
:py:meth:`Connection.open<aiogremlin.connection.Connection.open>`.
:param str url: url for host Gremlin Server
:param
aiogremlin.
gremlin_python.driver.transport.AbstractBaseTransport transport:
:param gremlin_python.driver.transport.AbstractBaseTransport transport:
Transport implementation
:param
aiogremlin.
gremlin_python.driver.protocol.AbstractBaseProtocol protocol:
:param gremlin_python.driver.protocol.AbstractBaseProtocol protocol:
Protocol implementation
:param asyncio.BaseEventLoop loop:
:param str username: Username for database auth
...
...
@@ -74,7 +74,7 @@ class Connection:
:param str url: url for host Gremlin Server
:param asyncio.BaseEventLoop loop:
:param
aiogremlin.
gremlin_python.driver.protocol.AbstractBaseProtocol protocol:
:param gremlin_python.driver.protocol.AbstractBaseProtocol protocol:
Protocol implementation
:param func transport_factory: Factory function for transports
:param ssl.SSLContext ssl_context:
...
...
@@ -125,7 +125,7 @@ class Connection:
"""
Submit a script and bindings to the Gremlin Server
:param `RequestMessage<
aiogremlin.
gremlin_python.driver.request.RequestMessage>` message:
:param `RequestMessage<gremlin_python.driver.request.RequestMessage>` message:
:returns: :py:class:`ResultSet<aiogremlin.driver.resultset.ResultSet>`
object
"""
...
...
aiogremlin/driver/protocol.py
View file @
f3204153
...
...
@@ -9,7 +9,7 @@ try:
except
ImportError
:
import
json
from
aiogremlin.
gremlin_python.driver
import
protocol
,
request
,
serializer
from
gremlin_python.driver
import
protocol
,
request
,
serializer
__author__
=
'David M. Brown (davebshow@gmail.com)'
...
...
aiogremlin/gremlin_python/__init__.py
deleted
100644 → 0
View file @
33567e96
'''
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.
'''
'''THIS FILE HAS BEEN MODIFIED BY DAVID M. BROWN TO SUPPORT PEP 492'''
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
from
aiogremlin.gremlin_python.statics
import
*
from
aiogremlin.gremlin_python.process.graph_traversal
import
__
from
aiogremlin.gremlin_python.process.strategies
import
*
from
aiogremlin.gremlin_python.process.traversal
import
Binding
,
Cardinality
aiogremlin/gremlin_python/driver/__init__.py
deleted
100644 → 0
View file @
33567e96
'''
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.
'''
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
aiogremlin/gremlin_python/driver/protocol.py
deleted
100644 → 0
View file @
33567e96
"""
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
abc
import
base64
import
collections
import
uuid
try
:
import
ujson
as
json
except
ImportError
:
import
json
__author__
=
'David M. Brown (davebshow@gmail.com)'
class
AbstractBaseProtocol
(
metaclass
=
abc
.
ABCMeta
):
@
abc
.
abstractmethod
def
connection_made
(
self
,
transport
):
self
.
_transport
=
transport
@
abc
.
abstractmethod
def
data_received
(
self
,
message
):
pass
@
abc
.
abstractmethod
def
write
(
self
,
request_id
,
request_message
):
pass
aiogremlin/gremlin_python/driver/request.py
deleted
100644 → 0
View file @
33567e96
"""
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
collections
__author__
=
'David M. Brown (davebshow@gmail.com)'
RequestMessage
=
collections
.
namedtuple
(
'RequestMessage'
,
[
'processor'
,
'op'
,
'args'
])
aiogremlin/gremlin_python/driver/serializer.py
deleted
100644 → 0
View file @
33567e96
"""
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.
"""
'''THIS FILE HAS BEEN MODIFIED BY DAVID M. BROWN TO SUPPORT PEP 492'''
try
:
import
ujson
as
json
except
ImportError
:
import
json
from
aiogremlin.gremlin_python.structure.io
import
graphson
__author__
=
'David M. Brown (davebshow@gmail.com)'
class
Processor
:
"""Base class for OpProcessor serialization system."""
def
__init__
(
self
,
writer
):
self
.
_graphson_writer
=
writer
def
get_op_args
(
self
,
op
,
args
):
op_method
=
getattr
(
self
,
op
,
None
)
if
not
op_method
:
raise
Exception
(
"Processor does not support op: {}"
.
format
(
op
))
return
op_method
(
args
)
class
Standard
(
Processor
):
def
authentication
(
self
,
args
):
return
args
def
eval
(
self
,
args
):
return
args
class
Traversal
(
Processor
):
def
authentication
(
self
,
args
):
return
args
def
bytecode
(
self
,
args
):
gremlin
=
args
[
'gremlin'
]
args
[
'gremlin'
]
=
self
.
_graphson_writer
.
toDict
(
gremlin
)
aliases
=
args
.
get
(
'aliases'
,
''
)
if
not
aliases
:
aliases
=
{
'g'
:
'g'
}
args
[
'aliases'
]
=
aliases
return
args
def
close
(
self
,
args
):
return
self
.
keys
(
args
)
def
gather
(
self
,
args
):
side_effect
=
args
[
'sideEffect'
]
args
[
'sideEffect'
]
=
{
'@type'
:
'g:UUID'
,
'@value'
:
side_effect
}
aliases
=
args
.
get
(
'aliases'
,
''
)
if
not
aliases
:
aliases
=
{
'g'
:
'g'
}
args
[
'aliases'
]
=
aliases
return
args
def
keys
(
self
,
args
):
side_effect
=
args
[
'sideEffect'
]
args
[
'sideEffect'
]
=
{
'@type'
:
'g:UUID'
,
'@value'
:
side_effect
}
return
args
class
GraphSONMessageSerializer
:
"""Message serializer for GraphSON"""
def
__init__
(
self
,
reader
=
None
,
writer
=
None
):
if
not
reader
:
reader
=
graphson
.
GraphSONReader
()
self
.
_graphson_reader
=
reader
if
not
writer
:
writer
=
graphson
.
GraphSONWriter
()
self
.
standard
=
Standard
(
writer
)
self
.
traversal
=
Traversal
(
writer
)
def
get_processor
(
self
,
processor
):
processor
=
getattr
(
self
,
processor
,
None
)
if
not
processor
:
raise
Exception
(
"Unknown processor"
)
return
processor
def
serialize_message
(
self
,
request_id
,
request_message
):
processor
=
request_message
.
processor
op
=
request_message
.
op
args
=
request_message
.
args
if
not
processor
:
processor_obj
=
self
.
get_processor
(
'standard'
)
else
:
processor_obj
=
self
.
get_processor
(
processor
)
args
=
processor_obj
.
get_op_args
(
op
,
args
)
message
=
self
.
build_message
(
request_id
,
processor
,
op
,
args
)
return
message
def
build_message
(
self
,
request_id
,
processor
,
op
,
args
):
message
=
{
'requestId'
:
{
'@type'
:
'g:UUID'
,
'@value'
:
request_id
},
'processor'
:
processor
,
'op'
:
op
,
'args'
:
args
}
return
self
.
finalize_message
(
message
,
b
"
\x21
"
,
b
"application/vnd.gremlin-v2.0+json"
)
def
finalize_message
(
self
,
message
,
mime_len
,
mime_type
):
message
=
json
.
dumps
(
message
)
message
=
b
''
.
join
([
mime_len
,
mime_type
,
message
.
encode
(
'utf-8'
)])
return
message
def
deserialize_message
(
self
,
message
):
return
self
.
_graphson_reader
.
toObject
(
message
)
aiogremlin/gremlin_python/driver/transport.py
deleted
100644 → 0
View file @
33567e96
"""
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
abc
__author__
=
'David M. Brown (davebshow@gmail.com)'
class
AbstractBaseTransport
(
metaclass
=
abc
.
ABCMeta
):
@
abc
.
abstractmethod
def
connect
(
self
,
url
,
*
,
ssl_context
=
None
):
pass
@
abc
.
abstractmethod
def
write
(
self
,
message
):
pass
@
abc
.
abstractmethod
def
read
(
self
):
pass
@
abc
.
abstractmethod
def
close
(
self
):
pass
@
abc
.
abstractproperty
def
closed
(
self
):
pass
aiogremlin/gremlin_python/process/__init__.py
deleted
100644 → 0
View file @
33567e96
'''
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.
'''
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
aiogremlin/gremlin_python/process/graph_traversal.py
deleted
100644 → 0
View file @
33567e96
This diff is collapsed.
Click to expand it.
aiogremlin/gremlin_python/process/strategies.py
deleted
100644 → 0
View file @
33567e96
'''
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.
'''
'''THIS FILE HAS BEEN MODIFIED BY DAVID M. BROWN TO SUPPORT PEP 492'''
__author__
=
'Marko A. Rodriguez (http://markorodriguez.com)'
from
aiogremlin.gremlin_python.process.traversal
import
TraversalStrategy
#########################
# DECORATION STRATEGIES #
#########################
class
ConnectiveStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
ElementIdStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
# EventStrategy doesn't make sense outside JVM traversal machine
class
HaltedTraverserStrategy
(
TraversalStrategy
):
def
__init__
(
self
,
halted_traverser_factory
=
None
):
TraversalStrategy
.
__init__
(
self
)
if
halted_traverser_factory
is
not
None
:
self
.
configuration
[
"haltedTraverserFactory"
]
=
halted_traverser_factory
class
PartitionStrategy
(
TraversalStrategy
):
def
__init__
(
self
,
partition_key
=
None
,
write_partition
=
None
,
read_partitions
=
None
,
include_meta_properties
=
None
):
TraversalStrategy
.
__init__
(
self
)
if
partition_key
is
not
None
:
self
.
configuration
[
"partitionKey"
]
=
partition_key
if
write_partition
is
not
None
:
self
.
configuration
[
"writePartition"
]
=
write_partition
if
write_partition
is
not
None
:
self
.
configuration
[
"readPartitions"
]
=
read_partitions
if
include_meta_properties
is
not
None
:
self
.
configuration
[
"includeMetaProperties"
]
=
include_meta_properties
class
SubgraphStrategy
(
TraversalStrategy
):
def
__init__
(
self
,
vertices
=
None
,
edges
=
None
,
vertex_properties
=
None
):
TraversalStrategy
.
__init__
(
self
)
if
vertices
is
not
None
:
self
.
configuration
[
"vertices"
]
=
vertices
if
edges
is
not
None
:
self
.
configuration
[
"edges"
]
=
edges
if
vertex_properties
is
not
None
:
self
.
configuration
[
"vertexProperties"
]
=
vertex_properties
class
VertexProgramStrategy
(
TraversalStrategy
):
def
__init__
(
self
,
graph_computer
=
None
,
workers
=
None
,
persist
=
None
,
result
=
None
,
vertices
=
None
,
edges
=
None
,
configuration
=
None
):
TraversalStrategy
.
__init__
(
self
)
if
graph_computer
is
not
None
:
self
.
configuration
[
"graphComputer"
]
=
graph_computer
if
workers
is
not
None
:
self
.
configuration
[
"workers"
]
=
workers
if
persist
is
not
None
:
self
.
configuration
[
"persist"
]
=
persist
if
result
is
not
None
:
self
.
configuration
[
"result"
]
=
result
if
vertices
is
not
None
:
self
.
configuration
[
"vertices"
]
=
vertices
if
edges
is
not
None
:
self
.
configuration
[
"edges"
]
=
edges
if
configuration
is
not
None
:
self
.
configuration
.
update
(
configuration
)
###########################
# FINALIZATION STRATEGIES #
###########################
class
MatchAlgorithmStrategy
(
TraversalStrategy
):
def
__init__
(
self
,
match_algorithm
=
None
):
TraversalStrategy
.
__init__
(
self
)
if
match_algorithm
is
not
None
:
self
.
configuration
[
"matchAlgorithm"
]
=
match_algorithm
###########################
# OPTIMIZATION STRATEGIES #
###########################
class
AdjacentToIncidentStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
FilterRankingStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
IdentityRemoveStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
IncidentToAdjacentStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
InlineFilterStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
LazyBarrierStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
MatchPredicateStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
OrderLimitStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
PathProcessorStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
PathRetractionStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
RangeByIsCountStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
RepeatUnrollStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
class
GraphFilterStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)
###########################
# VERIFICATION STRATEGIES #
###########################
class
LambdaRestrictionStrategy
(
TraversalStrategy
):
def
__init__
(
self
):
TraversalStrategy
.
__init__
(
self
)