gremlinpython 3.6.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. gremlin_python/__init__.py +20 -0
  2. gremlin_python/__version__.py +20 -0
  3. gremlin_python/driver/__init__.py +20 -0
  4. gremlin_python/driver/aiohttp/__init__.py +18 -0
  5. gremlin_python/driver/aiohttp/transport.py +242 -0
  6. gremlin_python/driver/client.py +206 -0
  7. gremlin_python/driver/connection.py +106 -0
  8. gremlin_python/driver/driver_remote_connection.py +183 -0
  9. gremlin_python/driver/protocol.py +259 -0
  10. gremlin_python/driver/remote_connection.py +84 -0
  11. gremlin_python/driver/request.py +25 -0
  12. gremlin_python/driver/resultset.py +100 -0
  13. gremlin_python/driver/serializer.py +294 -0
  14. gremlin_python/driver/transport.py +45 -0
  15. gremlin_python/driver/useragent.py +37 -0
  16. gremlin_python/process/__init__.py +20 -0
  17. gremlin_python/process/anonymous_traversal.py +64 -0
  18. gremlin_python/process/graph_traversal.py +2301 -0
  19. gremlin_python/process/strategies.py +239 -0
  20. gremlin_python/process/translator.py +297 -0
  21. gremlin_python/process/traversal.py +875 -0
  22. gremlin_python/statics.py +117 -0
  23. gremlin_python/structure/__init__.py +20 -0
  24. gremlin_python/structure/graph.py +134 -0
  25. gremlin_python/structure/io/__init__.py +20 -0
  26. gremlin_python/structure/io/graphbinaryV1.py +1153 -0
  27. gremlin_python/structure/io/graphsonV2d0.py +646 -0
  28. gremlin_python/structure/io/graphsonV3d0.py +766 -0
  29. gremlin_python/structure/io/util.py +60 -0
  30. gremlinpython-3.6.8.data/data/LICENSE +202 -0
  31. gremlinpython-3.6.8.data/data/NOTICE +5 -0
  32. gremlinpython-3.6.8.dist-info/LICENSE +202 -0
  33. gremlinpython-3.6.8.dist-info/METADATA +147 -0
  34. gremlinpython-3.6.8.dist-info/NOTICE +5 -0
  35. gremlinpython-3.6.8.dist-info/RECORD +37 -0
  36. gremlinpython-3.6.8.dist-info/WHEEL +5 -0
  37. gremlinpython-3.6.8.dist-info/top_level.txt +1 -0
@@ -0,0 +1,294 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ import base64
21
+ import logging
22
+ import struct
23
+ import uuid
24
+ import io
25
+ try:
26
+ import ujson as json
27
+ if int(json.__version__[0]) < 2:
28
+ logging.warning("Detected ujson version below 2.0.0. This is not recommended as precision may be lost.")
29
+ except ImportError:
30
+ import json
31
+
32
+ from gremlin_python.structure.io import graphbinaryV1
33
+ from gremlin_python.structure.io import graphsonV2d0
34
+ from gremlin_python.structure.io import graphsonV3d0
35
+
36
+ __author__ = 'David M. Brown (davebshow@gmail.com), Lyndon Bauto (lyndonb@bitquilltech.com)'
37
+
38
+
39
+ class Processor:
40
+ """Base class for OpProcessor serialization system."""
41
+
42
+ def __init__(self, writer):
43
+ self._writer = writer
44
+
45
+ def get_op_args(self, op, args):
46
+ op_method = getattr(self, op, None)
47
+ if not op_method:
48
+ raise Exception("Processor does not support op: {}".format(op))
49
+ return op_method(args)
50
+
51
+
52
+ class Standard(Processor):
53
+
54
+ def authentication(self, args):
55
+ return args
56
+
57
+ def eval(self, args):
58
+ return args
59
+
60
+
61
+ class Session(Processor):
62
+
63
+ def authentication(self, args):
64
+ return args
65
+
66
+ def eval(self, args):
67
+ return args
68
+
69
+ def close(self, args):
70
+ return args
71
+
72
+ def bytecode(self, args):
73
+ gremlin = args['gremlin']
74
+ args['gremlin'] = self._writer.to_dict(gremlin)
75
+ aliases = args.get('aliases', '')
76
+ if not aliases:
77
+ aliases = {'g': 'g'}
78
+ args['aliases'] = aliases
79
+ return args
80
+
81
+
82
+ class Traversal(Processor):
83
+
84
+ def authentication(self, args):
85
+ return args
86
+
87
+ def bytecode(self, args):
88
+ gremlin = args['gremlin']
89
+ args['gremlin'] = self._writer.to_dict(gremlin)
90
+ aliases = args.get('aliases', '')
91
+ if not aliases:
92
+ aliases = {'g': 'g'}
93
+ args['aliases'] = aliases
94
+ return args
95
+
96
+
97
+ class GraphSONMessageSerializer(object):
98
+ """
99
+ Message serializer for GraphSON. Allow users to pass custom reader,
100
+ writer, and version kwargs for custom serialization. Otherwise,
101
+ use current GraphSON version as default.
102
+ """
103
+
104
+ # KEEP TRACK OF CURRENT DEFAULTS
105
+ DEFAULT_READER_CLASS = graphsonV3d0.GraphSONReader
106
+ DEFAULT_WRITER_CLASS = graphsonV3d0.GraphSONWriter
107
+ DEFAULT_VERSION = b"application/vnd.gremlin-v3.0+json"
108
+
109
+ def __init__(self, reader=None, writer=None, version=None):
110
+ if not version:
111
+ version = self.DEFAULT_VERSION
112
+ self._version = version
113
+ if not reader:
114
+ reader = self.DEFAULT_READER_CLASS()
115
+ self._graphson_reader = reader
116
+ if not writer:
117
+ writer = self.DEFAULT_WRITER_CLASS()
118
+ self.standard = Standard(writer)
119
+ self.traversal = Traversal(writer)
120
+ self.session = Session(writer)
121
+
122
+ @property
123
+ def version(self):
124
+ """Read only property"""
125
+ return self._version
126
+
127
+ def get_processor(self, processor):
128
+ processor = getattr(self, processor, None)
129
+ if not processor:
130
+ raise Exception("Unknown processor")
131
+ return processor
132
+
133
+ def serialize_message(self, request_id, request_message):
134
+ processor = request_message.processor
135
+ op = request_message.op
136
+ args = request_message.args
137
+ if not processor:
138
+ processor_obj = self.get_processor('standard')
139
+ else:
140
+ processor_obj = self.get_processor(processor)
141
+ args = processor_obj.get_op_args(op, args)
142
+ message = self.build_message(request_id, processor, op, args)
143
+ return message
144
+
145
+ def build_message(self, request_id, processor, op, args):
146
+ message = {
147
+ 'requestId': {'@type': 'g:UUID', '@value': request_id},
148
+ 'processor': processor,
149
+ 'op': op,
150
+ 'args': args
151
+ }
152
+ return self.finalize_message(message, b"\x21", self.version)
153
+
154
+ def finalize_message(self, message, mime_len, mime_type):
155
+ message = json.dumps(message)
156
+ message = b''.join([mime_len, mime_type, message.encode('utf-8')])
157
+ return message
158
+
159
+ def deserialize_message(self, message):
160
+ # for parsing string message via HTTP connections
161
+ msg = json.loads(message if isinstance(message, str) else message.decode('utf-8'))
162
+ return self._graphson_reader.to_object(msg)
163
+
164
+
165
+ class GraphSONSerializersV2d0(GraphSONMessageSerializer):
166
+ """Message serializer for GraphSON 2.0"""
167
+ def __init__(self):
168
+ reader = graphsonV2d0.GraphSONReader()
169
+ writer = graphsonV2d0.GraphSONWriter()
170
+ version = b"application/vnd.gremlin-v2.0+json"
171
+ super(GraphSONSerializersV2d0, self).__init__(reader, writer, version)
172
+
173
+
174
+ class GraphSONSerializersV3d0(GraphSONMessageSerializer):
175
+ """Message serializer for GraphSON 3.0"""
176
+ def __init__(self):
177
+ reader = graphsonV3d0.GraphSONReader()
178
+ writer = graphsonV3d0.GraphSONWriter()
179
+ version = b"application/vnd.gremlin-v3.0+json"
180
+ super(GraphSONSerializersV3d0, self).__init__(reader, writer, version)
181
+
182
+
183
+ class GraphBinarySerializersV1(object):
184
+ DEFAULT_READER_CLASS = graphbinaryV1.GraphBinaryReader
185
+ DEFAULT_WRITER_CLASS = graphbinaryV1.GraphBinaryWriter
186
+ DEFAULT_VERSION = b"application/vnd.graphbinary-v1.0"
187
+
188
+ max_int64 = 0xFFFFFFFFFFFFFFFF
189
+ header_struct = struct.Struct('>b32sBQQ')
190
+ header_pack = header_struct.pack
191
+ int_pack = graphbinaryV1.int32_pack
192
+ int32_unpack = struct.Struct(">i").unpack
193
+
194
+ def __init__(self, reader=None, writer=None, version=None):
195
+ if not version:
196
+ version = self.DEFAULT_VERSION
197
+ self._version = version
198
+ if not reader:
199
+ reader = self.DEFAULT_READER_CLASS()
200
+ self._graphbinary_reader = reader
201
+ if not writer:
202
+ writer = self.DEFAULT_WRITER_CLASS()
203
+ self._graphbinary_writer = writer
204
+ self.standard = Standard(writer)
205
+ self.traversal = Traversal(writer)
206
+ self.session = Session(writer)
207
+
208
+ @property
209
+ def version(self):
210
+ """Read only property"""
211
+ return self._version
212
+
213
+ def get_processor(self, processor):
214
+ processor = getattr(self, processor, None)
215
+ if not processor:
216
+ raise Exception("Unknown processor")
217
+ return processor
218
+
219
+ def serialize_message(self, request_id, request_message):
220
+ processor = request_message.processor
221
+ op = request_message.op
222
+ args = request_message.args
223
+ if not processor:
224
+ processor_obj = self.get_processor('standard')
225
+ else:
226
+ processor_obj = self.get_processor(processor)
227
+ args = processor_obj.get_op_args(op, args)
228
+ message = self.build_message(request_id, processor, op, args)
229
+ return message
230
+
231
+ def build_message(self, request_id, processor, op, args):
232
+ message = {
233
+ 'requestId': request_id,
234
+ 'processor': processor,
235
+ 'op': op,
236
+ 'args': args
237
+ }
238
+ return self.finalize_message(message, 0x20, self.version)
239
+
240
+ def finalize_message(self, message, mime_len, mime_type):
241
+ ba = bytearray()
242
+
243
+ request_id = uuid.UUID(str(message['requestId']))
244
+ ba.extend(self.header_pack(mime_len, mime_type, 0x81,
245
+ (request_id.int >> 64) & self.max_int64, request_id.int & self.max_int64))
246
+
247
+ op_bytes = message['op'].encode("utf-8")
248
+ ba.extend(self.int_pack(len(op_bytes)))
249
+ ba.extend(op_bytes)
250
+
251
+ processor_bytes = message['processor'].encode("utf-8")
252
+ ba.extend(self.int_pack(len(processor_bytes)))
253
+ ba.extend(processor_bytes)
254
+
255
+ args = message["args"]
256
+ ba.extend(self.int_pack(len(args)))
257
+ for k, v in args.items():
258
+ self._graphbinary_writer.to_dict(k, ba)
259
+
260
+ # processor_obj.get_op_args in serialize_message() seems to already handle bytecode. in python 3
261
+ # because bytearray isn't bound to a type in graphbinary it falls through the writeObject() and
262
+ # just works but python 2 bytearray is bound to ByteBufferType so it writes DataType.bytebuffer
263
+ # rather than DataType.bytecode and the server gets confused. special casing this for now until
264
+ # it can be refactored
265
+ if k == "gremlin" and isinstance(v, bytearray):
266
+ ba.extend(v)
267
+ else:
268
+ self._graphbinary_writer.to_dict(v, ba)
269
+
270
+ return bytes(ba)
271
+
272
+ def deserialize_message(self, message):
273
+ # for parsing string message via HTTP connections
274
+ b = io.BytesIO(base64.b64decode(message) if isinstance(message, str) else message)
275
+
276
+ b.read(1) # version
277
+
278
+ request_id = str(self._graphbinary_reader.to_object(b, graphbinaryV1.DataType.uuid))
279
+ status_code = self.int32_unpack(b.read(4))[0]
280
+ status_msg = self._graphbinary_reader.to_object(b, graphbinaryV1.DataType.string)
281
+ status_attrs = self._graphbinary_reader.to_object(b, graphbinaryV1.DataType.map, nullable=False)
282
+ meta_attrs = self._graphbinary_reader.to_object(b, graphbinaryV1.DataType.map, nullable=False)
283
+ result = self._graphbinary_reader.to_object(b)
284
+
285
+ b.close()
286
+
287
+ msg = {'requestId': request_id,
288
+ 'status': {'code': status_code,
289
+ 'message': status_msg,
290
+ 'attributes': status_attrs},
291
+ 'result': {'meta': meta_attrs,
292
+ 'data': result}}
293
+
294
+ return msg
@@ -0,0 +1,45 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+ import abc
20
+
21
+ __author__ = 'David M. Brown (davebshow@gmail.com)'
22
+
23
+
24
+ class AbstractBaseTransport(metaclass=abc.ABCMeta):
25
+
26
+ @abc.abstractmethod
27
+ def connect(self, url, headers=None):
28
+ pass
29
+
30
+ @abc.abstractmethod
31
+ def write(self, message):
32
+ pass
33
+
34
+ @abc.abstractmethod
35
+ def read(self):
36
+ pass
37
+
38
+ @abc.abstractmethod
39
+ def close(self):
40
+ pass
41
+
42
+ @property
43
+ @abc.abstractmethod
44
+ def closed(self):
45
+ pass
@@ -0,0 +1,37 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+ import platform
20
+
21
+ gremlin_version = "3.6.8" # DO NOT MODIFY - Configured automatically by Maven Replacer Plugin
22
+
23
+ def _generate_user_agent():
24
+ application_name = "NotAvailable"
25
+ runtime_version = platform.python_version().replace(" ", "_")
26
+ os_name = platform.system().replace(" ", "_")
27
+ os_version = platform.release().replace(" ", "_")
28
+ architecture = platform.machine().replace(" ", "_")
29
+ user_agent = "{appName} Gremlin-Python.{driverVersion} {runtimeVersion} {osName}.{osVersion} {cpuArch}".format(
30
+ appName=application_name, driverVersion=gremlin_version, runtimeVersion=runtime_version,
31
+ osName=os_name, osVersion=os_version, cpuArch=architecture)
32
+
33
+ return user_agent
34
+
35
+
36
+ userAgent = _generate_user_agent()
37
+ userAgentHeader = "User-Agent"
@@ -0,0 +1,20 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ __author__ = 'Marko A. Rodriguez (http://markorodriguez.com)'
@@ -0,0 +1,64 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one
3
+ # or more contributor license agreements. See the NOTICE file
4
+ # distributed with this work for additional information
5
+ # regarding copyright ownership. The ASF licenses this file
6
+ # to you under the Apache License, Version 2.0 (the
7
+ # "License"); you may not use this file except in compliance
8
+ # with the License. You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing,
13
+ # software distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ # KIND, either express or implied. See the License for the
16
+ # specific language governing permissions and limitations
17
+ # under the License.
18
+ #
19
+
20
+ __author__ = 'Stephen Mallette (http://stephen.genoprime.com)'
21
+
22
+ from gremlin_python.structure.graph import Graph
23
+ from gremlin_python.process.graph_traversal import GraphTraversalSource
24
+ from gremlin_python.process.traversal import TraversalStrategies
25
+ from .. import statics
26
+
27
+ import warnings
28
+
29
+
30
+ class AnonymousTraversalSource(object):
31
+
32
+ def __init__(self, traversal_source_class=GraphTraversalSource):
33
+ self.traversal_source_class = traversal_source_class
34
+
35
+ @classmethod
36
+ def traversal(cls, traversal_source_class=GraphTraversalSource):
37
+ return AnonymousTraversalSource(traversal_source_class)
38
+
39
+ def withGraph(self, graph):
40
+ warnings.warn(
41
+ "gremlin_python.process.AnonymousTraversalSource.withGraph will be replaced by "
42
+ "gremlin_python.process.AnonymousTraversalSource.with_graph.",
43
+ DeprecationWarning)
44
+ return self.with_graph(graph)
45
+
46
+ def with_graph(self, graph):
47
+ return self.traversal_source_class(graph, TraversalStrategies.global_cache[graph.__class__])
48
+
49
+ def withRemote(self, remote_connection):
50
+ warnings.warn(
51
+ "gremlin_python.process.AnonymousTraversalSource.withRemote will be replaced by "
52
+ "gremlin_python.process.AnonymousTraversalSource.with_remote.",
53
+ DeprecationWarning)
54
+ return self.with_remote(remote_connection)
55
+
56
+ def with_remote(self, remote_connection):
57
+ return self.with_graph(Graph()).with_remote(remote_connection)
58
+
59
+
60
+ def traversal(traversal_source_class=GraphTraversalSource):
61
+ return AnonymousTraversalSource.traversal(traversal_source_class)
62
+
63
+
64
+ statics.add_static('traversal', traversal)