mysqlx-connector-python 8.3.0__py2.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.
- mysqlx/__init__.py +136 -0
- mysqlx/authentication.py +186 -0
- mysqlx/charsets.py +620 -0
- mysqlx/connection.py +3364 -0
- mysqlx/constants.py +297 -0
- mysqlx/crud.py +776 -0
- mysqlx/dbdoc.py +120 -0
- mysqlx/errorcode.py +1877 -0
- mysqlx/errors.py +257 -0
- mysqlx/expr.py +1366 -0
- mysqlx/helpers.py +234 -0
- mysqlx/locales/__init__.py +80 -0
- mysqlx/locales/eng/__init__.py +30 -0
- mysqlx/locales/eng/client_error.py +152 -0
- mysqlx/logger.py +33 -0
- mysqlx/protobuf/__init__.py +627 -0
- mysqlx/protobuf/mysqlx_connection_pb2.py +74 -0
- mysqlx/protobuf/mysqlx_crud_pb2.py +108 -0
- mysqlx/protobuf/mysqlx_cursor_pb2.py +68 -0
- mysqlx/protobuf/mysqlx_datatypes_pb2.py +75 -0
- mysqlx/protobuf/mysqlx_expect_pb2.py +69 -0
- mysqlx/protobuf/mysqlx_expr_pb2.py +81 -0
- mysqlx/protobuf/mysqlx_notice_pb2.py +81 -0
- mysqlx/protobuf/mysqlx_pb2.py +71 -0
- mysqlx/protobuf/mysqlx_prepare_pb2.py +73 -0
- mysqlx/protobuf/mysqlx_resultset_pb2.py +75 -0
- mysqlx/protobuf/mysqlx_session_pb2.py +67 -0
- mysqlx/protobuf/mysqlx_sql_pb2.py +63 -0
- mysqlx/protocol.py +1214 -0
- mysqlx/py.typed +0 -0
- mysqlx/result.py +1177 -0
- mysqlx/statement.py +1542 -0
- mysqlx/types.py +92 -0
- mysqlx/utils.py +136 -0
- mysqlx/version.py +46 -0
- mysqlx_connector_python-8.3.0.dist-info/LICENSE.txt +4211 -0
- mysqlx_connector_python-8.3.0.dist-info/METADATA +43 -0
- mysqlx_connector_python-8.3.0.dist-info/RECORD +40 -0
- mysqlx_connector_python-8.3.0.dist-info/WHEEL +6 -0
- mysqlx_connector_python-8.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# This program is free software; you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License, version 2.0, as
|
|
5
|
+
# published by the Free Software Foundation.
|
|
6
|
+
#
|
|
7
|
+
# This program is also distributed with certain software (including
|
|
8
|
+
# but not limited to OpenSSL) that is licensed under separate terms,
|
|
9
|
+
# as designated in a particular file or component or in included license
|
|
10
|
+
# documentation. The authors of MySQL hereby grant you an
|
|
11
|
+
# additional permission to link the program and your derivative works
|
|
12
|
+
# with the separately licensed software that they have included with
|
|
13
|
+
# MySQL.
|
|
14
|
+
#
|
|
15
|
+
# Without limiting anything contained in the foregoing, this file,
|
|
16
|
+
# which is part of MySQL Connector/Python, is also subject to the
|
|
17
|
+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
|
|
18
|
+
# http://oss.oracle.com/licenses/universal-foss-exception.
|
|
19
|
+
#
|
|
20
|
+
# This program is distributed in the hope that it will be useful, but
|
|
21
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
22
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
23
|
+
# See the GNU General Public License, version 2.0, for more details.
|
|
24
|
+
#
|
|
25
|
+
# You should have received a copy of the GNU General Public License
|
|
26
|
+
# along with this program; if not, write to the Free Software Foundation, Inc.,
|
|
27
|
+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
28
|
+
|
|
29
|
+
# mypy: disable-error-code="attr-defined,union-attr"
|
|
30
|
+
|
|
31
|
+
"""Implementation of a helper class for MySQL X Protobuf messages."""
|
|
32
|
+
|
|
33
|
+
# pylint: disable=c-extension-no-member, no-member
|
|
34
|
+
|
|
35
|
+
from __future__ import annotations
|
|
36
|
+
|
|
37
|
+
from typing import Any, Dict, List, Optional, Tuple, Type, Union
|
|
38
|
+
|
|
39
|
+
from ..types import MessageType, ProtobufMessageCextType, ProtobufMessageType
|
|
40
|
+
|
|
41
|
+
_SERVER_MESSAGES_TUPLES: Tuple[Tuple[str, str], ...] = (
|
|
42
|
+
("Mysqlx.ServerMessages.Type.OK", "Mysqlx.Ok"),
|
|
43
|
+
("Mysqlx.ServerMessages.Type.ERROR", "Mysqlx.Error"),
|
|
44
|
+
(
|
|
45
|
+
"Mysqlx.ServerMessages.Type.CONN_CAPABILITIES",
|
|
46
|
+
"Mysqlx.Connection.Capabilities",
|
|
47
|
+
),
|
|
48
|
+
(
|
|
49
|
+
"Mysqlx.ServerMessages.Type.SESS_AUTHENTICATE_CONTINUE",
|
|
50
|
+
"Mysqlx.Session.AuthenticateContinue",
|
|
51
|
+
),
|
|
52
|
+
(
|
|
53
|
+
"Mysqlx.ServerMessages.Type.SESS_AUTHENTICATE_OK",
|
|
54
|
+
"Mysqlx.Session.AuthenticateOk",
|
|
55
|
+
),
|
|
56
|
+
("Mysqlx.ServerMessages.Type.NOTICE", "Mysqlx.Notice.Frame"),
|
|
57
|
+
(
|
|
58
|
+
"Mysqlx.ServerMessages.Type.RESULTSET_COLUMN_META_DATA",
|
|
59
|
+
"Mysqlx.Resultset.ColumnMetaData",
|
|
60
|
+
),
|
|
61
|
+
("Mysqlx.ServerMessages.Type.RESULTSET_ROW", "Mysqlx.Resultset.Row"),
|
|
62
|
+
(
|
|
63
|
+
"Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONE",
|
|
64
|
+
"Mysqlx.Resultset.FetchDone",
|
|
65
|
+
),
|
|
66
|
+
(
|
|
67
|
+
"Mysqlx.ServerMessages.Type.RESULTSET_FETCH_SUSPENDED",
|
|
68
|
+
"Mysqlx.Resultset.FetchSuspended",
|
|
69
|
+
),
|
|
70
|
+
(
|
|
71
|
+
"Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONE_MORE_RESULTSETS",
|
|
72
|
+
"Mysqlx.Resultset.FetchDoneMoreResultsets",
|
|
73
|
+
),
|
|
74
|
+
(
|
|
75
|
+
"Mysqlx.ServerMessages.Type.SQL_STMT_EXECUTE_OK",
|
|
76
|
+
"Mysqlx.Sql.StmtExecuteOk",
|
|
77
|
+
),
|
|
78
|
+
(
|
|
79
|
+
"Mysqlx.ServerMessages.Type.RESULTSET_FETCH_DONE_MORE_OUT_PARAMS",
|
|
80
|
+
"Mysqlx.Resultset.FetchDoneMoreOutParams",
|
|
81
|
+
),
|
|
82
|
+
(
|
|
83
|
+
"Mysqlx.ServerMessages.Type.COMPRESSION",
|
|
84
|
+
"Mysqlx.Connection.Compression",
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
PROTOBUF_VERSION: Optional[str] = None
|
|
89
|
+
PROTOBUF_REPEATED_TYPES: List[
|
|
90
|
+
Union[
|
|
91
|
+
Type[List[Dict[str, Any]]],
|
|
92
|
+
Type[RepeatedCompositeContainer],
|
|
93
|
+
Type[RepeatedCompositeFieldContainer],
|
|
94
|
+
]
|
|
95
|
+
] = [list]
|
|
96
|
+
|
|
97
|
+
try:
|
|
98
|
+
import _mysqlxpb
|
|
99
|
+
|
|
100
|
+
SERVER_MESSAGES = {
|
|
101
|
+
int(_mysqlxpb.enum_value(key)): val for key, val in _SERVER_MESSAGES_TUPLES
|
|
102
|
+
}
|
|
103
|
+
HAVE_MYSQLXPB_CEXT = True
|
|
104
|
+
except ImportError:
|
|
105
|
+
HAVE_MYSQLXPB_CEXT = False
|
|
106
|
+
|
|
107
|
+
from ..helpers import BYTE_TYPES, NUMERIC_TYPES, encode_to_bytes
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
from google import protobuf
|
|
111
|
+
from google.protobuf import (
|
|
112
|
+
descriptor_database,
|
|
113
|
+
descriptor_pb2,
|
|
114
|
+
descriptor_pool,
|
|
115
|
+
message_factory,
|
|
116
|
+
)
|
|
117
|
+
from google.protobuf.internal.containers import RepeatedCompositeFieldContainer
|
|
118
|
+
|
|
119
|
+
try:
|
|
120
|
+
from google.protobuf.pyext._message import RepeatedCompositeContainer
|
|
121
|
+
|
|
122
|
+
PROTOBUF_REPEATED_TYPES.append(RepeatedCompositeContainer)
|
|
123
|
+
except ImportError:
|
|
124
|
+
pass
|
|
125
|
+
|
|
126
|
+
PROTOBUF_REPEATED_TYPES.append(RepeatedCompositeFieldContainer)
|
|
127
|
+
if hasattr(protobuf, "__version__"):
|
|
128
|
+
# Only Protobuf versions >=3.0.0 provide `__version__`
|
|
129
|
+
PROTOBUF_VERSION = protobuf.__version__
|
|
130
|
+
|
|
131
|
+
from . import (
|
|
132
|
+
mysqlx_connection_pb2,
|
|
133
|
+
mysqlx_crud_pb2,
|
|
134
|
+
mysqlx_cursor_pb2,
|
|
135
|
+
mysqlx_datatypes_pb2,
|
|
136
|
+
mysqlx_expect_pb2,
|
|
137
|
+
mysqlx_expr_pb2,
|
|
138
|
+
mysqlx_notice_pb2,
|
|
139
|
+
mysqlx_pb2,
|
|
140
|
+
mysqlx_prepare_pb2,
|
|
141
|
+
mysqlx_resultset_pb2,
|
|
142
|
+
mysqlx_session_pb2,
|
|
143
|
+
mysqlx_sql_pb2,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# Dictionary with all messages descriptors
|
|
147
|
+
_MESSAGES: Dict[str, int] = {}
|
|
148
|
+
|
|
149
|
+
# Mysqlx
|
|
150
|
+
for key, val in mysqlx_pb2.ClientMessages.Type.items():
|
|
151
|
+
_MESSAGES[f"Mysqlx.ClientMessages.Type.{key}"] = val
|
|
152
|
+
for key, val in mysqlx_pb2.ServerMessages.Type.items():
|
|
153
|
+
_MESSAGES[f"Mysqlx.ServerMessages.Type.{key}"] = val
|
|
154
|
+
for key, val in mysqlx_pb2.Error.Severity.items():
|
|
155
|
+
_MESSAGES[f"Mysqlx.Error.Severity.{key}"] = val
|
|
156
|
+
|
|
157
|
+
# Mysqlx.Crud
|
|
158
|
+
for key, val in mysqlx_crud_pb2.DataModel.items():
|
|
159
|
+
_MESSAGES[f"Mysqlx.Crud.DataModel.{key}"] = val
|
|
160
|
+
for key, val in mysqlx_crud_pb2.Find.RowLock.items():
|
|
161
|
+
_MESSAGES[f"Mysqlx.Crud.Find.RowLock.{key}"] = val
|
|
162
|
+
for key, val in mysqlx_crud_pb2.Order.Direction.items():
|
|
163
|
+
_MESSAGES[f"Mysqlx.Crud.Order.Direction.{key}"] = val
|
|
164
|
+
for key, val in mysqlx_crud_pb2.UpdateOperation.UpdateType.items():
|
|
165
|
+
_MESSAGES[f"Mysqlx.Crud.UpdateOperation.UpdateType.{key}"] = val
|
|
166
|
+
|
|
167
|
+
# Mysqlx.Datatypes
|
|
168
|
+
for key, val in mysqlx_datatypes_pb2.Scalar.Type.items():
|
|
169
|
+
_MESSAGES[f"Mysqlx.Datatypes.Scalar.Type.{key}"] = val
|
|
170
|
+
for key, val in mysqlx_datatypes_pb2.Any.Type.items():
|
|
171
|
+
_MESSAGES[f"Mysqlx.Datatypes.Any.Type.{key}"] = val
|
|
172
|
+
|
|
173
|
+
# Mysqlx.Expect
|
|
174
|
+
for key, val in mysqlx_expect_pb2.Open.Condition.ConditionOperation.items():
|
|
175
|
+
_MESSAGES[f"Mysqlx.Expect.Open.Condition.ConditionOperation.{key}"] = val
|
|
176
|
+
for key, val in mysqlx_expect_pb2.Open.Condition.Key.items():
|
|
177
|
+
_MESSAGES[f"Mysqlx.Expect.Open.Condition.Key.{key}"] = val
|
|
178
|
+
for key, val in mysqlx_expect_pb2.Open.CtxOperation.items():
|
|
179
|
+
_MESSAGES[f"Mysqlx.Expect.Open.CtxOperation.{key}"] = val
|
|
180
|
+
|
|
181
|
+
# Mysqlx.Expr
|
|
182
|
+
for key, val in mysqlx_expr_pb2.Expr.Type.items():
|
|
183
|
+
_MESSAGES[f"Mysqlx.Expr.Expr.Type.{key}"] = val
|
|
184
|
+
for key, val in mysqlx_expr_pb2.DocumentPathItem.Type.items():
|
|
185
|
+
_MESSAGES[f"Mysqlx.Expr.DocumentPathItem.Type.{key}"] = val
|
|
186
|
+
|
|
187
|
+
# Mysqlx.Notice
|
|
188
|
+
for key, val in mysqlx_notice_pb2.Frame.Scope.items():
|
|
189
|
+
_MESSAGES[f"Mysqlx.Notice.Frame.Scope.{key}"] = val
|
|
190
|
+
for key, val in mysqlx_notice_pb2.Warning.Level.items():
|
|
191
|
+
_MESSAGES[f"Mysqlx.Notice.Warning.Level.{key}"] = val
|
|
192
|
+
for key, val in mysqlx_notice_pb2.SessionStateChanged.Parameter.items():
|
|
193
|
+
_MESSAGES[f"Mysqlx.Notice.SessionStateChanged.Parameter.{key}"] = val
|
|
194
|
+
|
|
195
|
+
# Mysql.Prepare
|
|
196
|
+
for key, val in mysqlx_prepare_pb2.Prepare.OneOfMessage.Type.items():
|
|
197
|
+
_MESSAGES[f"Mysqlx.Prepare.Prepare.OneOfMessage.Type.{key}"] = val
|
|
198
|
+
|
|
199
|
+
# Mysql.Resultset
|
|
200
|
+
for key, val in mysqlx_resultset_pb2.ColumnMetaData.FieldType.items():
|
|
201
|
+
_MESSAGES[f"Mysqlx.Resultset.ColumnMetaData.FieldType.{key}"] = val
|
|
202
|
+
|
|
203
|
+
# Add messages to the descriptor pool
|
|
204
|
+
_DESCRIPTOR_DB = descriptor_database.DescriptorDatabase()
|
|
205
|
+
_DESCRIPTOR_POOL = descriptor_pool.DescriptorPool(_DESCRIPTOR_DB)
|
|
206
|
+
|
|
207
|
+
_DESCRIPTOR_DB.Add(
|
|
208
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
209
|
+
mysqlx_connection_pb2.DESCRIPTOR.serialized_pb
|
|
210
|
+
)
|
|
211
|
+
)
|
|
212
|
+
_DESCRIPTOR_DB.Add(
|
|
213
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
214
|
+
mysqlx_crud_pb2.DESCRIPTOR.serialized_pb
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
_DESCRIPTOR_DB.Add(
|
|
218
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
219
|
+
mysqlx_cursor_pb2.DESCRIPTOR.serialized_pb
|
|
220
|
+
)
|
|
221
|
+
)
|
|
222
|
+
_DESCRIPTOR_DB.Add(
|
|
223
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
224
|
+
mysqlx_datatypes_pb2.DESCRIPTOR.serialized_pb
|
|
225
|
+
)
|
|
226
|
+
)
|
|
227
|
+
_DESCRIPTOR_DB.Add(
|
|
228
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
229
|
+
mysqlx_expect_pb2.DESCRIPTOR.serialized_pb
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
_DESCRIPTOR_DB.Add(
|
|
233
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
234
|
+
mysqlx_expr_pb2.DESCRIPTOR.serialized_pb
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
_DESCRIPTOR_DB.Add(
|
|
238
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
239
|
+
mysqlx_notice_pb2.DESCRIPTOR.serialized_pb
|
|
240
|
+
)
|
|
241
|
+
)
|
|
242
|
+
_DESCRIPTOR_DB.Add(
|
|
243
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
244
|
+
mysqlx_pb2.DESCRIPTOR.serialized_pb
|
|
245
|
+
)
|
|
246
|
+
)
|
|
247
|
+
_DESCRIPTOR_DB.Add(
|
|
248
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
249
|
+
mysqlx_prepare_pb2.DESCRIPTOR.serialized_pb
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
_DESCRIPTOR_DB.Add(
|
|
253
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
254
|
+
mysqlx_resultset_pb2.DESCRIPTOR.serialized_pb
|
|
255
|
+
)
|
|
256
|
+
)
|
|
257
|
+
_DESCRIPTOR_DB.Add(
|
|
258
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
259
|
+
mysqlx_session_pb2.DESCRIPTOR.serialized_pb
|
|
260
|
+
)
|
|
261
|
+
)
|
|
262
|
+
_DESCRIPTOR_DB.Add(
|
|
263
|
+
descriptor_pb2.FileDescriptorProto.FromString(
|
|
264
|
+
mysqlx_sql_pb2.DESCRIPTOR.serialized_pb
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
SERVER_MESSAGES = {_MESSAGES[key]: val for key, val in _SERVER_MESSAGES_TUPLES}
|
|
269
|
+
HAVE_PROTOBUF = True
|
|
270
|
+
HAVE_PROTOBUF_ERROR = None
|
|
271
|
+
|
|
272
|
+
class _mysqlxpb_pure: # pylint: disable=invalid-name
|
|
273
|
+
"""This class implements the methods in pure Python used by the
|
|
274
|
+
_mysqlxpb C++ extension."""
|
|
275
|
+
|
|
276
|
+
factory: message_factory.MessageFactory = message_factory.MessageFactory()
|
|
277
|
+
|
|
278
|
+
@staticmethod
|
|
279
|
+
def new_message(name: str) -> ProtobufMessageType:
|
|
280
|
+
"""Create new Protobuf message.
|
|
281
|
+
|
|
282
|
+
Args:
|
|
283
|
+
name (str): Message type name.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
object: Protobuf message.
|
|
287
|
+
"""
|
|
288
|
+
cls = _mysqlxpb_pure.factory.GetPrototype(
|
|
289
|
+
_DESCRIPTOR_POOL.FindMessageTypeByName(name)
|
|
290
|
+
)
|
|
291
|
+
return cls()
|
|
292
|
+
|
|
293
|
+
@staticmethod
|
|
294
|
+
def enum_value(enum_key: str) -> int:
|
|
295
|
+
"""Return enum value.
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
enum_key (str): Enum key.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
int: enum value.
|
|
302
|
+
"""
|
|
303
|
+
return _MESSAGES[enum_key]
|
|
304
|
+
|
|
305
|
+
@staticmethod
|
|
306
|
+
def serialize_message(msg: ProtobufMessageType) -> bytes:
|
|
307
|
+
"""Serialize message.
|
|
308
|
+
|
|
309
|
+
Args:
|
|
310
|
+
msg (object): Protobuf message.
|
|
311
|
+
|
|
312
|
+
Returns:
|
|
313
|
+
bytes: Serialized message bytes string.
|
|
314
|
+
"""
|
|
315
|
+
return msg.SerializeToString()
|
|
316
|
+
|
|
317
|
+
@staticmethod
|
|
318
|
+
def serialize_partial_message(msg: ProtobufMessageType) -> bytes:
|
|
319
|
+
"""Serialize partial message.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
msg (object): Protobuf message.
|
|
323
|
+
|
|
324
|
+
Returns:
|
|
325
|
+
bytes: Serialized partial message bytes string.
|
|
326
|
+
"""
|
|
327
|
+
return msg.SerializePartialToString()
|
|
328
|
+
|
|
329
|
+
@staticmethod
|
|
330
|
+
def parse_message(msg_type_name: str, payload: bytes) -> ProtobufMessageType:
|
|
331
|
+
"""Serialize partial message.
|
|
332
|
+
|
|
333
|
+
Args:
|
|
334
|
+
msg_type_name (str): Message type name.
|
|
335
|
+
payload (bytes): Payload.
|
|
336
|
+
|
|
337
|
+
Returns:
|
|
338
|
+
object: Message parsed from string.
|
|
339
|
+
"""
|
|
340
|
+
msg = _mysqlxpb_pure.new_message(msg_type_name)
|
|
341
|
+
msg.ParseFromString(payload)
|
|
342
|
+
return msg
|
|
343
|
+
|
|
344
|
+
@staticmethod
|
|
345
|
+
def parse_server_message(msg_type: int, payload: bytes) -> ProtobufMessageType:
|
|
346
|
+
"""Parse server message message.
|
|
347
|
+
|
|
348
|
+
Args:
|
|
349
|
+
msg_type (int): Message type.
|
|
350
|
+
payload (bytes): Payload.
|
|
351
|
+
|
|
352
|
+
Returns:
|
|
353
|
+
object: Server message parsed from string.
|
|
354
|
+
"""
|
|
355
|
+
msg_type_name = SERVER_MESSAGES.get(msg_type)
|
|
356
|
+
if not msg_type_name:
|
|
357
|
+
raise ValueError(f"Unknown msg_type: {msg_type}")
|
|
358
|
+
msg = _mysqlxpb_pure.new_message(msg_type_name)
|
|
359
|
+
msg.ParseFromString(payload)
|
|
360
|
+
return msg
|
|
361
|
+
|
|
362
|
+
except (ImportError, SyntaxError, TypeError) as err:
|
|
363
|
+
HAVE_PROTOBUF = False
|
|
364
|
+
HAVE_PROTOBUF_ERROR = (
|
|
365
|
+
err if PROTOBUF_VERSION is not None else "Protobuf >=3.11.0 is required"
|
|
366
|
+
)
|
|
367
|
+
if not HAVE_MYSQLXPB_CEXT:
|
|
368
|
+
raise ImportError(f"Protobuf is not available: {HAVE_PROTOBUF_ERROR}") from err
|
|
369
|
+
|
|
370
|
+
CRUD_PREPARE_MAPPING: Dict[str, Tuple[str, str]] = {
|
|
371
|
+
"Mysqlx.ClientMessages.Type.CRUD_FIND": (
|
|
372
|
+
"Mysqlx.Prepare.Prepare.OneOfMessage.Type.FIND",
|
|
373
|
+
"find",
|
|
374
|
+
),
|
|
375
|
+
"Mysqlx.ClientMessages.Type.CRUD_INSERT": (
|
|
376
|
+
"Mysqlx.Prepare.Prepare.OneOfMessage.Type.INSERT",
|
|
377
|
+
"insert",
|
|
378
|
+
),
|
|
379
|
+
"Mysqlx.ClientMessages.Type.CRUD_UPDATE": (
|
|
380
|
+
"Mysqlx.Prepare.Prepare.OneOfMessage.Type.UPDATE",
|
|
381
|
+
"update",
|
|
382
|
+
),
|
|
383
|
+
"Mysqlx.ClientMessages.Type.CRUD_DELETE": (
|
|
384
|
+
"Mysqlx.Prepare.Prepare.OneOfMessage.Type.DELETE",
|
|
385
|
+
"delete",
|
|
386
|
+
),
|
|
387
|
+
"Mysqlx.ClientMessages.Type.SQL_STMT_EXECUTE": (
|
|
388
|
+
"Mysqlx.Prepare.Prepare.OneOfMessage.Type.STMT",
|
|
389
|
+
"stmt_execute",
|
|
390
|
+
),
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
class Protobuf:
|
|
395
|
+
"""Protobuf class acts as a container of the Protobuf message class.
|
|
396
|
+
|
|
397
|
+
It allows the switch between the C extension and pure Python implementation
|
|
398
|
+
message handlers, by patching the `mysqlxpb` class attribute.
|
|
399
|
+
"""
|
|
400
|
+
|
|
401
|
+
mysqlxpb = _mysqlxpb if HAVE_MYSQLXPB_CEXT else _mysqlxpb_pure
|
|
402
|
+
use_pure: bool = not HAVE_MYSQLXPB_CEXT
|
|
403
|
+
|
|
404
|
+
@staticmethod
|
|
405
|
+
def set_use_pure(use_pure: bool) -> None:
|
|
406
|
+
"""Sets whether to use the C extension or pure Python implementation.
|
|
407
|
+
|
|
408
|
+
Args:
|
|
409
|
+
use_pure (bool): `True` to use pure Python implementation.
|
|
410
|
+
"""
|
|
411
|
+
if use_pure and not HAVE_PROTOBUF:
|
|
412
|
+
raise ImportError(f"Protobuf is not available: {HAVE_PROTOBUF_ERROR}")
|
|
413
|
+
if not use_pure and not HAVE_MYSQLXPB_CEXT:
|
|
414
|
+
raise ImportError("MySQL X Protobuf C extension is not available")
|
|
415
|
+
Protobuf.mysqlxpb = _mysqlxpb_pure if use_pure else _mysqlxpb
|
|
416
|
+
Protobuf.use_pure = use_pure
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
class Message:
|
|
420
|
+
"""Helper class for interfacing with the MySQL X Protobuf extension.
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
msg_type_name (string): Protobuf type name.
|
|
424
|
+
**kwargs: Arbitrary keyword arguments with values for the message.
|
|
425
|
+
"""
|
|
426
|
+
|
|
427
|
+
def __init__(self, msg_type_name: Optional[str] = None, **kwargs: Any) -> None:
|
|
428
|
+
# _msg is a protobuf message instance when use_pure=True,
|
|
429
|
+
# else is a dictionary instance.
|
|
430
|
+
self.__dict__["_msg"] = (
|
|
431
|
+
Protobuf.mysqlxpb.new_message(msg_type_name) if msg_type_name else None
|
|
432
|
+
)
|
|
433
|
+
for name, value in kwargs.items():
|
|
434
|
+
self.__setattr__(name, value)
|
|
435
|
+
|
|
436
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
437
|
+
if Protobuf.use_pure:
|
|
438
|
+
if isinstance(value, str):
|
|
439
|
+
setattr(self._msg, name, encode_to_bytes(value))
|
|
440
|
+
elif isinstance(value, (NUMERIC_TYPES, BYTE_TYPES)):
|
|
441
|
+
setattr(self._msg, name, value)
|
|
442
|
+
elif isinstance(value, list):
|
|
443
|
+
getattr(self._msg, name).extend(value)
|
|
444
|
+
elif isinstance(value, Message):
|
|
445
|
+
getattr(self._msg, name).MergeFrom(value.get_message())
|
|
446
|
+
else:
|
|
447
|
+
getattr(self._msg, name).MergeFrom(value)
|
|
448
|
+
else:
|
|
449
|
+
if isinstance(value, str):
|
|
450
|
+
self._msg[name] = encode_to_bytes(value)
|
|
451
|
+
else:
|
|
452
|
+
self._msg[name] = (
|
|
453
|
+
value.get_message() if isinstance(value, Message) else value
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
def __getattr__(self, name: str) -> Any:
|
|
457
|
+
try:
|
|
458
|
+
return (
|
|
459
|
+
self._msg[name] if not Protobuf.use_pure else getattr(self._msg, name)
|
|
460
|
+
)
|
|
461
|
+
except KeyError:
|
|
462
|
+
raise AttributeError from None
|
|
463
|
+
|
|
464
|
+
def __setitem__(self, name: str, value: Any) -> None:
|
|
465
|
+
self.__setattr__(name, value)
|
|
466
|
+
|
|
467
|
+
def __getitem__(self, name: str) -> Any:
|
|
468
|
+
return self.__getattr__(name)
|
|
469
|
+
|
|
470
|
+
def get(self, name: str, default: Any = None) -> Any:
|
|
471
|
+
"""Returns the value of an element of the message dictionary.
|
|
472
|
+
|
|
473
|
+
Args:
|
|
474
|
+
name (string): Key name.
|
|
475
|
+
default (object): The default value if the key does not exists.
|
|
476
|
+
|
|
477
|
+
Returns:
|
|
478
|
+
object: The value of the provided key name.
|
|
479
|
+
"""
|
|
480
|
+
return (
|
|
481
|
+
self.__dict__["_msg"].get(name, default)
|
|
482
|
+
if not Protobuf.use_pure
|
|
483
|
+
else getattr(self.__dict__["_msg"], name, default)
|
|
484
|
+
)
|
|
485
|
+
|
|
486
|
+
def set_message(
|
|
487
|
+
self, msg: Union[ProtobufMessageType, ProtobufMessageCextType]
|
|
488
|
+
) -> None:
|
|
489
|
+
"""Sets the message.
|
|
490
|
+
|
|
491
|
+
Args:
|
|
492
|
+
msg (dict): Dictionary representing a message.
|
|
493
|
+
"""
|
|
494
|
+
self.__dict__["_msg"] = msg
|
|
495
|
+
|
|
496
|
+
def get_message(self) -> Union[ProtobufMessageType, ProtobufMessageCextType]:
|
|
497
|
+
"""Returns the dictionary representing a message containing parsed
|
|
498
|
+
data.
|
|
499
|
+
|
|
500
|
+
Returns:
|
|
501
|
+
dict: The dictionary representing a message containing parsed data.
|
|
502
|
+
"""
|
|
503
|
+
return self.__dict__["_msg"]
|
|
504
|
+
|
|
505
|
+
def serialize_to_string(self) -> bytes:
|
|
506
|
+
"""Serializes a message to a string.
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
str: A string representing a message containing parsed data.
|
|
510
|
+
"""
|
|
511
|
+
return Protobuf.mysqlxpb.serialize_message(self._msg)
|
|
512
|
+
|
|
513
|
+
def serialize_partial_to_string(self) -> bytes:
|
|
514
|
+
"""Serializes the protocol message to a binary string.
|
|
515
|
+
|
|
516
|
+
This method is similar to serialize_to_string but doesn't check if the
|
|
517
|
+
message is initialized.
|
|
518
|
+
|
|
519
|
+
Returns:
|
|
520
|
+
str: A string representation of the partial message.
|
|
521
|
+
"""
|
|
522
|
+
return Protobuf.mysqlxpb.serialize_partial_message(self._msg)
|
|
523
|
+
|
|
524
|
+
@property
|
|
525
|
+
def type(self) -> str:
|
|
526
|
+
"""string: Message type name."""
|
|
527
|
+
return (
|
|
528
|
+
self._msg["_mysqlxpb_type_name"]
|
|
529
|
+
if not Protobuf.use_pure
|
|
530
|
+
else self._msg.DESCRIPTOR.full_name
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
@staticmethod
|
|
534
|
+
def parse(
|
|
535
|
+
msg_type_name: str, payload: bytes
|
|
536
|
+
) -> Union[ProtobufMessageType, ProtobufMessageCextType]:
|
|
537
|
+
"""Creates a new message, initialized with parsed data.
|
|
538
|
+
|
|
539
|
+
Args:
|
|
540
|
+
msg_type_name (string): Message type name.
|
|
541
|
+
payload (string): Serialized message data.
|
|
542
|
+
|
|
543
|
+
Returns:
|
|
544
|
+
dict: The dictionary representing a message containing parsed data.
|
|
545
|
+
|
|
546
|
+
.. versionadded:: 8.0.21
|
|
547
|
+
"""
|
|
548
|
+
return Protobuf.mysqlxpb.parse_message(msg_type_name, payload)
|
|
549
|
+
|
|
550
|
+
@staticmethod
|
|
551
|
+
def byte_size(msg: MessageType) -> int:
|
|
552
|
+
"""Returns the size of the message in bytes.
|
|
553
|
+
|
|
554
|
+
Args:
|
|
555
|
+
msg (mysqlx.protobuf.Message): MySQL X Protobuf Message.
|
|
556
|
+
|
|
557
|
+
Returns:
|
|
558
|
+
int: Size of the message in bytes.
|
|
559
|
+
|
|
560
|
+
.. versionadded:: 8.0.21
|
|
561
|
+
"""
|
|
562
|
+
return (
|
|
563
|
+
msg.ByteSize()
|
|
564
|
+
if Protobuf.use_pure
|
|
565
|
+
else len(encode_to_bytes(msg.serialize_to_string()))
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
@staticmethod
|
|
569
|
+
def parse_from_server(
|
|
570
|
+
msg_type: int, payload: bytes
|
|
571
|
+
) -> Union[ProtobufMessageType, ProtobufMessageCextType]:
|
|
572
|
+
"""Creates a new server-side message, initialized with parsed data.
|
|
573
|
+
|
|
574
|
+
Args:
|
|
575
|
+
msg_type (int): Message type.
|
|
576
|
+
payload (string): Serialized message data.
|
|
577
|
+
|
|
578
|
+
Returns:
|
|
579
|
+
dict: The dictionary representing a message containing parsed data.
|
|
580
|
+
"""
|
|
581
|
+
return Protobuf.mysqlxpb.parse_server_message(msg_type, payload)
|
|
582
|
+
|
|
583
|
+
@classmethod
|
|
584
|
+
def from_message(cls, msg_type_name: str, payload: bytes) -> MessageType:
|
|
585
|
+
"""Creates a new message, initialized with parsed data and returns a
|
|
586
|
+
:class:`mysqlx.protobuf.Message` object.
|
|
587
|
+
|
|
588
|
+
Args:
|
|
589
|
+
msg_type_name (string): Message type name.
|
|
590
|
+
payload (string): Serialized message data.
|
|
591
|
+
|
|
592
|
+
Returns:
|
|
593
|
+
mysqlx.protobuf.Message: The Message representing a message
|
|
594
|
+
containing parsed data.
|
|
595
|
+
"""
|
|
596
|
+
msg = cls()
|
|
597
|
+
msg.set_message(Protobuf.mysqlxpb.parse_message(msg_type_name, payload))
|
|
598
|
+
return msg
|
|
599
|
+
|
|
600
|
+
@classmethod
|
|
601
|
+
def from_server_message(cls, msg_type: int, payload: bytes) -> MessageType:
|
|
602
|
+
"""Creates a new server-side message, initialized with parsed data and
|
|
603
|
+
returns a :class:`mysqlx.protobuf.Message` object.
|
|
604
|
+
|
|
605
|
+
Args:
|
|
606
|
+
msg_type (int): Message type.
|
|
607
|
+
payload (string): Serialized message data.
|
|
608
|
+
|
|
609
|
+
Returns:
|
|
610
|
+
mysqlx.protobuf.Message: The Message representing a message
|
|
611
|
+
containing parsed data.
|
|
612
|
+
"""
|
|
613
|
+
msg = cls()
|
|
614
|
+
msg.set_message(Protobuf.mysqlxpb.parse_server_message(msg_type, payload))
|
|
615
|
+
return msg
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
def mysqlxpb_enum(name: str) -> int:
|
|
619
|
+
"""Returns the value of a MySQL X Protobuf enumerator.
|
|
620
|
+
|
|
621
|
+
Args:
|
|
622
|
+
name (string): MySQL X Protobuf numerator name.
|
|
623
|
+
|
|
624
|
+
Returns:
|
|
625
|
+
int: Value of the enumerator.
|
|
626
|
+
"""
|
|
627
|
+
return Protobuf.mysqlxpb.enum_value(name)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright (c) 2017, 2023, Oracle and/or its affiliates.
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License, version 2.0, as
|
|
6
|
+
# published by the Free Software Foundation.
|
|
7
|
+
#
|
|
8
|
+
# This program is also distributed with certain software (including
|
|
9
|
+
# but not limited to OpenSSL) that is licensed under separate terms,
|
|
10
|
+
# as designated in a particular file or component or in included license
|
|
11
|
+
# documentation. The authors of MySQL hereby grant you an
|
|
12
|
+
# additional permission to link the program and your derivative works
|
|
13
|
+
# with the separately licensed software that they have included with
|
|
14
|
+
# MySQL.
|
|
15
|
+
#
|
|
16
|
+
# Without limiting anything contained in the foregoing, this file,
|
|
17
|
+
# which is part of MySQL Connector/Python, is also subject to the
|
|
18
|
+
# Universal FOSS Exception, version 1.0, a copy of which can be found at
|
|
19
|
+
# http://oss.oracle.com/licenses/universal-foss-exception.
|
|
20
|
+
#
|
|
21
|
+
# This program is distributed in the hope that it will be useful, but
|
|
22
|
+
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
23
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
24
|
+
# See the GNU General Public License, version 2.0, for more details.
|
|
25
|
+
#
|
|
26
|
+
# You should have received a copy of the GNU General Public License
|
|
27
|
+
# along with this program; if not, write to the Free Software Foundation, Inc.,
|
|
28
|
+
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
29
|
+
|
|
30
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
31
|
+
# source: mysqlx_connection.proto
|
|
32
|
+
|
|
33
|
+
# type: ignore
|
|
34
|
+
|
|
35
|
+
"""Generated protocol buffer code."""
|
|
36
|
+
from google.protobuf import (
|
|
37
|
+
descriptor as _descriptor,
|
|
38
|
+
descriptor_pool as _descriptor_pool,
|
|
39
|
+
symbol_database as _symbol_database,
|
|
40
|
+
)
|
|
41
|
+
from google.protobuf.internal import builder as _builder
|
|
42
|
+
|
|
43
|
+
# @@protoc_insertion_point(imports)
|
|
44
|
+
|
|
45
|
+
_sym_db = _symbol_database.Default()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
from mysqlx.protobuf import (
|
|
49
|
+
mysqlx_datatypes_pb2 as mysqlx__datatypes__pb2,
|
|
50
|
+
mysqlx_pb2 as mysqlx__pb2,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(
|
|
54
|
+
b'\n\x17mysqlx_connection.proto\x12\x11Mysqlx.Connection\x1a\x16mysqlx_datatypes.proto\x1a\x0cmysqlx.proto"@\n\nCapability\x12\x0c\n\x04name\x18\x01 \x02(\t\x12$\n\x05value\x18\x02 \x02(\x0b\x32\x15.Mysqlx.Datatypes.Any"C\n\x0c\x43\x61pabilities\x12\x33\n\x0c\x63\x61pabilities\x18\x01 \x03(\x0b\x32\x1d.Mysqlx.Connection.Capability"\x11\n\x0f\x43\x61pabilitiesGet"H\n\x0f\x43\x61pabilitiesSet\x12\x35\n\x0c\x63\x61pabilities\x18\x01 \x02(\x0b\x32\x1f.Mysqlx.Connection.Capabilities"\x07\n\x05\x43lose"\xa5\x01\n\x0b\x43ompression\x12\x19\n\x11uncompressed_size\x18\x01 \x01(\x04\x12\x34\n\x0fserver_messages\x18\x02 \x01(\x0e\x32\x1b.Mysqlx.ServerMessages.Type\x12\x34\n\x0f\x63lient_messages\x18\x03 \x01(\x0e\x32\x1b.Mysqlx.ClientMessages.Type\x12\x0f\n\x07payload\x18\x04 \x02(\x0c\x42\x1b\n\x17\x63om.mysql.cj.x.protobufH\x03'
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
|
|
58
|
+
_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, "mysqlx_connection_pb2", globals())
|
|
59
|
+
if _descriptor._USE_C_DESCRIPTORS == False:
|
|
60
|
+
DESCRIPTOR._options = None
|
|
61
|
+
DESCRIPTOR._serialized_options = b"\n\027com.mysql.cj.x.protobufH\003"
|
|
62
|
+
_CAPABILITY._serialized_start = 84
|
|
63
|
+
_CAPABILITY._serialized_end = 148
|
|
64
|
+
_CAPABILITIES._serialized_start = 150
|
|
65
|
+
_CAPABILITIES._serialized_end = 217
|
|
66
|
+
_CAPABILITIESGET._serialized_start = 219
|
|
67
|
+
_CAPABILITIESGET._serialized_end = 236
|
|
68
|
+
_CAPABILITIESSET._serialized_start = 238
|
|
69
|
+
_CAPABILITIESSET._serialized_end = 310
|
|
70
|
+
_CLOSE._serialized_start = 312
|
|
71
|
+
_CLOSE._serialized_end = 319
|
|
72
|
+
_COMPRESSION._serialized_start = 322
|
|
73
|
+
_COMPRESSION._serialized_end = 487
|
|
74
|
+
# @@protoc_insertion_point(module_scope)
|