Skip to content

Commit 3c0302b

Browse files
author
Reggie Burnett
committed
Merge branch 'release/2.2.0' of myrepo.no.oracle.com:connector-python into release/2.2.0
2 parents 508f0a0 + 73c9c43 commit 3c0302b

File tree

8 files changed

+68
-31
lines changed

8 files changed

+68
-31
lines changed

lib/mysqlx/authentication.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of MySQL Authentication Plugin."""
25+
2426
import hashlib
2527

2628

lib/mysqlx/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24-
"""Implementation of MySQLx servers enabled communication."""
24+
"""Implementation of communication for MySQL X servers."""
2525

2626
import socket
2727

lib/mysqlx/crud.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of the CRUD database objects."""
25+
2426
from .statement import (FindStatement, AddStatement, RemoveStatement,
2527
ModifyStatement, SelectStatement, InsertStatement,
2628
DeleteStatement, UpdateStatement,

lib/mysqlx/dbdoc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of the DbDoc."""
25+
2426
import json
2527
import uuid
2628

lib/mysqlx/errors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24-
"""Python Database API Specification v2.0 exceptions implementation.
25-
"""
24+
"""Implementation of the Python Database API Specification v2.0 exceptions."""
2625

2726
import sys
2827
import struct

lib/mysqlx/protocol.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of the X protocol for MySQL servers."""
25+
2426
import struct
2527

2628
from .protobuf import mysqlx_pb2 as MySQLx

lib/mysqlx/result.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of the Result Set classes."""
25+
2426
import decimal
2527
import struct
2628
import sys
2729

2830
from datetime import datetime, timedelta
31+
2932
from .dbdoc import DbDoc
3033

34+
3135
def from_protobuf(col_type, payload):
3236
if len(payload) == 0:
3337
return None
@@ -69,7 +73,7 @@ def double_from_protobuf(payload):
6973

7074
def varint_from_protobuf_stream(payload):
7175
if len(payload) == 0:
72-
raise ValueError("payload is empty")
76+
raise ValueError("Payload is empty")
7377

7478
cur = 0
7579
i = 0
@@ -86,21 +90,21 @@ def varint_from_protobuf_stream(payload):
8690
cur += 1
8791
shift += 7
8892

89-
raise EOFError("payload too short")
93+
raise EOFError("Payload too short")
9094

9195

9296
def varint_from_protobuf(payload):
9397
i, payload = varint_from_protobuf_stream(payload)
9498
if len(payload) != 0:
95-
raise ValueError("payload too long")
99+
raise ValueError("Payload too long")
96100

97101
return i
98102

99103

100104
def varsint_from_protobuf(payload):
101105
i, payload = varint_from_protobuf_stream(payload)
102106
if len(payload) != 0:
103-
raise ValueError("payload too long")
107+
raise ValueError("Payload too long")
104108

105109
# Zigzag encoded, revert it
106110
if i & 0x1:
@@ -122,7 +126,7 @@ def set_from_protobuf(payload):
122126
if len(payload) == 0 and field_len == 1 and len(s) == 0:
123127
# Special case for empty set
124128
return []
125-
raise ValueError("invalid Set encoding")
129+
raise ValueError("Invalid Set encoding")
126130

127131
s.append(payload[:field_len])
128132
payload = payload[field_len:]
@@ -397,6 +401,7 @@ def is_padded(self):
397401
# TODO: To implement
398402
raise NotImplementedError
399403

404+
400405
class Warning(object):
401406
def __init__(self, level, code, msg):
402407
self._level = level
@@ -433,17 +438,18 @@ def get_string(self, str_index):
433438
if int_index >= len(self._fields):
434439
raise Exception("Argument out of range")
435440
if int_index == -1:
436-
raise Exception("Column name '" + str_index + "' not found")
441+
raise Exception("Column name '{0}' not found".format(str_index))
437442
return str(self._fields[int_index])
438443

444+
439445
class BaseResult(object):
440446
def __init__(self, connection):
441447
self._connection = connection
442448
self._protocol = self._connection.protocol
443449
self._closed = False
444450
self._rows_affected = 0
445451
self._warnings = []
446-
if connection._active_result != None:
452+
if connection._active_result is not None:
447453
connection._active_result.fetch_all()
448454
connection._active_result = None
449455

@@ -454,6 +460,7 @@ def get_warnings(self):
454460
def get_warnings_count(self):
455461
return len(self._warnings)
456462

463+
457464
class Result(BaseResult):
458465
def __init__(self, connection):
459466
super(Result, self).__init__(connection)
@@ -467,6 +474,7 @@ def get_affected_items_count(self):
467474
def get_autoincrement_value(self):
468475
pass
469476

477+
470478
class BufferingResult(BaseResult):
471479
def __init__(self, connection):
472480
super(BufferingResult, self).__init__(connection)
@@ -478,7 +486,7 @@ def _init_result(self):
478486
self._items = []
479487
self._page_size = 20
480488
self._position = -1
481-
self._connection._active_result = self if self._has_more_data == True else None
489+
self._connection._active_result = self if self._has_more_data else None
482490

483491
@property
484492
def count(self):
@@ -520,11 +528,12 @@ def _page_in_items(self):
520528
return count
521529

522530
def fetch_all(self):
523-
while (True):
531+
while True:
524532
if not self._page_in_items():
525533
break
526534
return self._items
527535

536+
528537
class RowResult(BufferingResult):
529538
def __init__(self, connection):
530539
super(RowResult, self).__init__(connection)
@@ -533,18 +542,20 @@ def __init__(self, connection):
533542
def columns(self):
534543
return self._columns
535544

545+
536546
class SqlResult(RowResult):
537547
def __init__(self, connection):
538548
super(SqlResult, self).__init__(connection)
539549
self._has_more_results = False
540550

541551
def next_result(self):
542-
if self._closed == True:
552+
if self._closed:
543553
return False
544554
self._has_more_results = False
545555
self._init_result()
546556
return True
547557

558+
548559
class DocResult(BufferingResult):
549560
def __init__(self, connection):
550561
super(DocResult, self).__init__(connection)
@@ -554,4 +565,3 @@ def _read_item(self, dumping):
554565
if row is None:
555566
return None
556567
return DbDoc(row[0])
557-

lib/mysqlx/statement.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121
# along with this program; if not, write to the Free Software
2222
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323

24+
"""Implementation of Statements."""
25+
2426
import json
2527
from .protobuf import mysqlx_crud_pb2 as MySQLxCrud
2628
from .result import SqlResult
2729
from .expr import ExprParser
2830
from .dbdoc import DbDoc
2931

32+
3033
class Statement(object):
3134
"""Provides base functionality for statement objects.
3235
@@ -103,7 +106,9 @@ def where(self, condition):
103106

104107
def _projection(self, *fields):
105108
self._has_projection = True
106-
self._projection_expr = ExprParser(",".join(fields), not self._doc_based).parse_table_select_projection()
109+
self._projection_expr = ExprParser(
110+
",".join(fields),
111+
not self._doc_based).parse_table_select_projection()
107112
return self
108113

109114
def limit(self, row_count, offset=0):
@@ -125,12 +130,14 @@ def sort(self, *sort_clauses):
125130
*sort_clauses: The expression strings defining the sort criteria.
126131
"""
127132
self._has_sort = True
128-
self._sort_expr = ExprParser(",".join(sort_clauses), not self._doc_based).parse_order_spec()
133+
self._sort_expr = ExprParser(",".join(sort_clauses),
134+
not self._doc_based).parse_order_spec()
129135
return self
130136

131137
def _group_by(self, *fields):
132138
self._has_group_by = True
133-
self._grouping = ExprParser(",".join(fields), not self._doc_based).parse_expr_list()
139+
self._grouping = ExprParser(",".join(fields),
140+
not self._doc_based).parse_expr_list()
134141

135142
def _having(self, condition):
136143
self._has_having = True
@@ -161,7 +168,7 @@ def execute(self):
161168
Raises:
162169
NotImplementedError: This method must be implemented.
163170
"""
164-
raise Exception("This should never be called")
171+
raise NotImplementedError
165172

166173

167174
class SqlStatement(Statement):
@@ -222,23 +229,26 @@ def execute(self):
222229
doc.ensure_id()
223230
return self._connection.send_insert(self)
224231

232+
225233
class UpdateSpec(object):
226-
def __init__(self, type, source, value=None):
227-
if type == MySQLxCrud.UpdateOperation.SET:
234+
def __init__(self, update_type, source, value=None):
235+
if update_type == MySQLxCrud.UpdateOperation.SET:
228236
self._table_set(source, value)
229237
else:
230-
self.update_type = type
238+
self.update_type = update_type
231239
self.source = source
232240
if len(source) > 0 and source[0] == '$':
233241
self.source = source[1:]
234-
self.source = ExprParser(self.source, False).document_field().identifier
242+
self.source = ExprParser(self.source,
243+
False).document_field().identifier
235244
self.value = value
236245

237246
def _table_set(self, source, value):
238247
self.update_type = MySQLxCrud.UpdateOperation.SET
239248
self.source = ExprParser(source, True).parse_table_update_field()
240249
self.value = value
241250

251+
242252
class ModifyStatement(FilterableStatement):
243253
"""A statement for document update operations on a Collection.
244254
@@ -248,7 +258,8 @@ class ModifyStatement(FilterableStatement):
248258
documents to be updated.
249259
"""
250260
def __init__(self, collection, condition=None):
251-
super(ModifyStatement, self).__init__(target=collection, condition=condition)
261+
super(ModifyStatement, self).__init__(target=collection,
262+
condition=condition)
252263
self._update_ops = []
253264

254265
def set(self, doc_path, value):
@@ -261,7 +272,8 @@ def set(self, doc_path, value):
261272
Returns:
262273
mysqlx.ModifyStatement: ModifyStatement object.
263274
"""
264-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_SET, doc_path, value))
275+
self._update_ops.append(
276+
UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_SET, doc_path, value))
265277
return self
266278

267279
def change(self, doc_path, value):
@@ -275,7 +287,9 @@ def change(self, doc_path, value):
275287
Returns:
276288
mysqlx.ModifyStatement: ModifyStatement object.
277289
"""
278-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_REPLACE, doc_path, value))
290+
self._update_ops.append(
291+
UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_REPLACE, doc_path,
292+
value))
279293
return self
280294

281295
def unset(self, doc_path):
@@ -288,7 +302,8 @@ def unset(self, doc_path):
288302
Returns:
289303
mysqlx.ModifyStatement: ModifyStatement object.
290304
"""
291-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_REMOVE, doc_path))
305+
self._update_ops.append(
306+
UpdateSpec(MySQLxCrud.UpdateOperation.ITEM_REMOVE, doc_path))
292307
return self
293308

294309
def array_insert(self, field, value):
@@ -303,7 +318,8 @@ def array_insert(self, field, value):
303318
Returns:
304319
mysqlx.ModifyStatement: ModifyStatement object.
305320
"""
306-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.ARRAY_INSERT, field, value))
321+
self._update_ops.append(
322+
UpdateSpec(MySQLxCrud.UpdateOperation.ARRAY_INSERT, field, value))
307323
return self
308324

309325
def array_append(self, doc_path, value):
@@ -319,7 +335,9 @@ def array_append(self, doc_path, value):
319335
Returns:
320336
mysqlx.ModifyStatement: ModifyStatement object.
321337
"""
322-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.UpdateType.ARRAY_APPEND, doc_path, value))
338+
self._update_ops.append(
339+
UpdateSpec(MySQLxCrud.UpdateOperation.UpdateType.ARRAY_APPEND,
340+
doc_path, value))
323341
return self
324342

325343
def execute(self):
@@ -466,6 +484,7 @@ def execute(self):
466484
"""
467485
return self._connection.send_insert(self)
468486

487+
469488
class UpdateStatement(FilterableStatement):
470489
"""A statement for record update operations on a Table.
471490
@@ -484,7 +503,8 @@ def set(self, field, value):
484503
field (string): The column name to be updated.
485504
value (object): The value to be set on the specified column.
486505
"""
487-
self._update_ops.append(UpdateSpec(MySQLxCrud.UpdateOperation.SET, field, value))
506+
self._update_ops.append(
507+
UpdateSpec(MySQLxCrud.UpdateOperation.SET, field, value))
488508
return self
489509

490510
def execute(self):
@@ -524,8 +544,8 @@ class DeleteStatement(FilterableStatement):
524544
"""
525545
def __init__(self, table, condition=None):
526546
super(DeleteStatement, self).__init__(target=table,
527-
condition=condition,
528-
doc_based=False)
547+
condition=condition,
548+
doc_based=False)
529549

530550
def execute(self):
531551
"""Execute the statement.

0 commit comments

Comments
 (0)