diff --git a/doc/conf.py b/doc/conf.py index 91da1f1b..3e96e59e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -# # Tarantool python client library documentation build configuration file, created by # sphinx-quickstart on Tue Nov 29 06:29:57 2011. # diff --git a/setup.py b/setup.py index 7d84f4fd..3ee55f05 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- + import codecs import os import re diff --git a/tarantool/__init__.py b/tarantool/__init__.py index c0b50cfc..9cef1d01 100644 --- a/tarantool/__init__.py +++ b/tarantool/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 import sys diff --git a/tarantool/connection.py b/tarantool/connection.py index 702254a1..eb11ab5a 100644 --- a/tarantool/connection.py +++ b/tarantool/connection.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 ''' This module provides low-level API for Tarantool @@ -18,10 +17,7 @@ import ctypes import ctypes.util -try: - from ctypes import c_ssize_t -except ImportError: - from ctypes import c_longlong as c_ssize_t +from ctypes import c_ssize_t import msgpack @@ -85,7 +81,6 @@ check_key, greeting_decode, version_id, - string_types, ENCODING_DEFAULT, ) @@ -640,7 +635,7 @@ def replace(self, space_name, values): :rtype: `Response` instance ''' - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid request = RequestReplace(self, space_name, values) return self._send_request(request) @@ -697,7 +692,7 @@ class JoinState: def _ops_process(self, space, update_ops): new_ops = [] for op in update_ops: - if isinstance(op[1], string_types): + if isinstance(op[1], str): op = list(op) op[1] = self.schema.get_field(space, op[1])['id'] new_ops.append(op) @@ -733,7 +728,7 @@ def insert(self, space_name, values): :rtype: `Response` instance ''' - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid request = RequestInsert(self, space_name, values) return self._send_request(request) @@ -754,9 +749,9 @@ def delete(self, space_name, key, **kwargs): index_name = kwargs.get("index", 0) key = check_key(key) - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid - if isinstance(index_name, string_types): + if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid request = RequestDelete(self, space_name, index_name, key) return self._send_request(request) @@ -826,9 +821,9 @@ def upsert(self, space_name, tuple_value, op_list, **kwargs): ''' index_name = kwargs.get("index", 0) - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid - if isinstance(index_name, string_types): + if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid op_list = self._ops_process(space_name, op_list) request = RequestUpsert(self, space_name, index_name, tuple_value, @@ -902,9 +897,9 @@ def update(self, space_name, key, op_list, **kwargs): index_name = kwargs.get("index", 0) key = check_key(key) - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid - if isinstance(index_name, string_types): + if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid op_list = self._ops_process(space_name, op_list) request = RequestUpdate(self, space_name, index_name, key, op_list) @@ -985,9 +980,9 @@ def select(self, space_name, key=None, **kwargs): # tuples) key = check_key(key, select=True) - if isinstance(space_name, string_types): + if isinstance(space_name, str): space_name = self.schema.get_space(space_name).sid - if isinstance(index_name, string_types): + if isinstance(index_name, str): index_name = self.schema.get_index(space_name, index_name).iid request = RequestSelect(self, space_name, index_name, key, offset, limit, iterator_type) diff --git a/tarantool/connection_pool.py b/tarantool/connection_pool.py index 6bf78a54..165d655e 100644 --- a/tarantool/connection_pool.py +++ b/tarantool/connection_pool.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import abc import itertools import queue diff --git a/tarantool/const.py b/tarantool/const.py index 476af38a..8035f479 100644 --- a/tarantool/const.py +++ b/tarantool/const.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 IPROTO_CODE = 0x00 diff --git a/tarantool/dbapi.py b/tarantool/dbapi.py index cda09948..515e4689 100644 --- a/tarantool/dbapi.py +++ b/tarantool/dbapi.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from tarantool.connection import Connection as BaseConnection from tarantool.error import * diff --git a/tarantool/error.py b/tarantool/error.py index 9ea49d71..6bbe012a 100644 --- a/tarantool/error.py +++ b/tarantool/error.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 ''' Python DB API compatible exceptions @@ -6,7 +5,7 @@ The PEP-249 says that database related exceptions must be inherited as follows: - StandardError + Exception |__Warning |__Error |__InterfaceError @@ -30,21 +29,13 @@ import warnings -try: - class Warning(StandardError): - '''Exception raised for important warnings - like data truncations while inserting, etc. ''' -except NameError: - class Warning(Exception): - '''Exception raised for important warnings - like data truncations while inserting, etc. ''' -try: - class Error(StandardError): - '''Base class for error exceptions''' -except NameError: - class Error(Exception): - '''Base class for error exceptions''' +class Warning(Exception): + '''Exception raised for important warnings + like data truncations while inserting, etc. ''' + +class Error(Exception): + '''Base class for error exceptions''' class InterfaceError(Error): diff --git a/tarantool/mesh_connection.py b/tarantool/mesh_connection.py index 09596d94..33387fd2 100644 --- a/tarantool/mesh_connection.py +++ b/tarantool/mesh_connection.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ''' This module provides the MeshConnection class with automatic switch between Tarantool instances by the basic round-robin strategy. @@ -33,11 +32,6 @@ RequestCall ) -try: - string_types = basestring -except NameError: - string_types = str - default_addr_opts = { 'transport': DEFAULT_TRANSPORT, 'ssl_key_file': DEFAULT_SSL_KEY_FILE, @@ -55,7 +49,7 @@ def parse_error(uri, msg): if not uri: return parse_error(uri, 'should not be None or empty string') - if not isinstance(uri, string_types): + if not isinstance(uri, str): return parse_error(uri, 'should be of a string type') if uri.count(':') != 1: return parse_error(uri, 'does not match host:port scheme') @@ -117,7 +111,7 @@ def format_error(address, err): if 'host' not in result or result['host'] is None: return format_error(result, 'host is mandatory for an inet result') - if not isinstance(result['host'], string_types): + if not isinstance(result['host'], str): return format_error(result, 'host must be a string for an inet result') @@ -131,7 +125,7 @@ def format_error(address, err): # Looks okay. return result, None - elif isinstance(result['port'], string_types): + elif isinstance(result['port'], str): # Looks like a unix address. # Expect no host. @@ -140,7 +134,7 @@ def format_error(address, err): result, 'host must be unset or None for a unix result') # Validate port. - if not isinstance(result['port'], string_types): + if not isinstance(result['port'], str): return format_error(result, 'port must be a string for a unix result') diff --git a/tarantool/request.py b/tarantool/request.py index 44fb5a3c..419f7832 100644 --- a/tarantool/request.py +++ b/tarantool/request.py @@ -1,18 +1,13 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 ''' Request types definitions ''' import sys -import collections import msgpack import hashlib -try: - collectionsAbc = collections.abc -except AttributeError: - collectionsAbc = collections +from collections.abc import Sequence, Mapping from tarantool.error import DatabaseError @@ -56,7 +51,6 @@ from tarantool.response import Response, ResponseExecute from tarantool.utils import ( strxor, - binary_types ) from tarantool.msgpack_ext.packer import default as packer_default @@ -87,9 +81,6 @@ def __init__(self, conn): # The option controls whether to pack binary (non-unicode) # string values as mp_bin or as mp_str. # - # The default behaviour of the Python 2 connector is to pack - # both bytes and Unicode strings as mp_str. - # # The default behaviour of the Python 3 connector (since # default encoding is "utf-8") is to pack bytes as mp_bin # and Unicode strings as mp_str. encoding=None mode must @@ -119,7 +110,7 @@ def __init__(self, conn): # just always set it for all msgpack versions to get rid # of the warning on msgpack-0.5.0 and to keep our # behaviour on msgpack-1.0.0. - if conn.encoding is None or sys.version_info.major == 2: + if conn.encoding is None: packer_kwargs['use_bin_type'] = False else: packer_kwargs['use_bin_type'] = True @@ -187,7 +178,7 @@ def sha1(values): sha = hashlib.sha1() for i in values: if i is not None: - if isinstance(i, binary_types): + if isinstance(i, bytes): sha.update(i) else: sha.update(i.encode()) @@ -408,9 +399,9 @@ class RequestExecute(Request): def __init__(self, conn, sql, args): super(RequestExecute, self).__init__(conn) - if isinstance(args, collectionsAbc.Mapping): + if isinstance(args, Mapping): args = [{":%s" % name: value} for name, value in args.items()] - elif not isinstance(args, collectionsAbc.Sequence): + elif not isinstance(args, Sequence): raise TypeError("Parameter type '%s' is not supported. " "Must be a mapping or sequence" % type(args)) diff --git a/tarantool/response.py b/tarantool/response.py index 3e367787..4566acd5 100644 --- a/tarantool/response.py +++ b/tarantool/response.py @@ -1,12 +1,6 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 -try: - # Python 3.3+ - from collections.abc import Sequence -except ImportError: - # Python 2 - from collections import Sequence +from collections.abc import Sequence import json import msgpack diff --git a/tarantool/schema.py b/tarantool/schema.py index ba34885a..3c06963d 100644 --- a/tarantool/schema.py +++ b/tarantool/schema.py @@ -1,14 +1,9 @@ -# -*- coding: utf-8 -*- # pylint: disable=R0903 ''' This module provides the :class:`~tarantool.schema.Schema` class. It is a Tarantool schema description. ''' -from tarantool.utils import ( - string_types, - integer_types, -) from tarantool.error import ( Error, SchemaError, @@ -151,7 +146,7 @@ def fetch_space(self, space): ) elif len(space_row) == 0 or not len(space_row[0]): # We can't find space with this name or id - temp_name = 'name' if isinstance(space, string_types) else 'id' + temp_name = 'name' if isinstance(space, str) else 'id' errmsg = "There's no space with {1} '{0}'".format(space, temp_name) raise SchemaError(errmsg) @@ -161,7 +156,7 @@ def fetch_space(self, space): def fetch_space_from(self, space): _index = None - if isinstance(space, string_types): + if isinstance(space, str): _index = const.INDEX_SPACE_NAME else: _index = const.INDEX_SPACE_PRIMARY @@ -212,7 +207,7 @@ def fetch_index(self, space_object, index): ) elif len(index_row) == 0 or not len(index_row[0]): # We can't find index with this name or id - temp_name = 'name' if isinstance(index, string_types) else 'id' + temp_name = 'name' if isinstance(index, str) else 'id' errmsg = ("There's no index with {2} '{0}'" " in space '{1}'").format(index, space_object.name, temp_name) @@ -229,7 +224,7 @@ def fetch_index_all(self): def fetch_index_from(self, space, index): _index = None - if isinstance(index, string_types): + if isinstance(index, str): _index = const.INDEX_INDEX_NAME else: _index = const.INDEX_INDEX_PRIMARY @@ -269,7 +264,7 @@ def get_field(self, space, field): try: return _space.format[field] except: - tp = 'name' if isinstance(field, string_types) else 'id' + tp = 'name' if isinstance(field, str) else 'id' errmsg = "There's no field with {2} '{0}' in space '{1}'".format( field, _space.name, tp ) diff --git a/tarantool/space.py b/tarantool/space.py index 9c3f9fdc..5ebe297c 100644 --- a/tarantool/space.py +++ b/tarantool/space.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # pylint: disable=C0301,W0105,W0401,W0614 ''' This module provides the :class:`~tarantool.space.Space` class. diff --git a/tarantool/utils.py b/tarantool/utils.py index 7909e12a..1427d9d0 100644 --- a/tarantool/utils.py +++ b/tarantool/utils.py @@ -1,39 +1,14 @@ -# -*- coding: utf-8 -*- import sys import uuid -# Compatibility layer for Python2/Python3 -if sys.version_info.major == 2: - string_types = (basestring, ) - integer_types = (int, long) - supported_types = integer_types + string_types + (float,) +supported_types = (int, str, bytes, float,) - ENCODING_DEFAULT = None +ENCODING_DEFAULT = "utf-8" - if sys.version_info.minor < 6: - binary_types = (str, ) - else: - binary_types = (bytes, ) - from base64 import decodestring as base64_decode +from base64 import decodebytes as base64_decode - def strxor(rhs, lhs): - return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(rhs, lhs)) - -elif sys.version_info.major == 3: - binary_types = (bytes, ) - string_types = (str, ) - integer_types = (int, ) - supported_types = integer_types + string_types + binary_types + (float,) - - ENCODING_DEFAULT = "utf-8" - - from base64 import decodebytes as base64_decode - - def strxor(rhs, lhs): - return bytes([x ^ y for x, y in zip(rhs, lhs)]) - -else: - pass # unreachable +def strxor(rhs, lhs): + return bytes([x ^ y for x, y in zip(rhs, lhs)]) def check_key(*args, **kwargs): if 'first' not in kwargs: diff --git a/test/setup_command.py b/test/setup_command.py index 1711e2d1..da0cb6c4 100755 --- a/test/setup_command.py +++ b/test/setup_command.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- + import os import sys import unittest diff --git a/test/suites/lib/remote_tarantool_server.py b/test/suites/lib/remote_tarantool_server.py index fa983f9b..5d6afd77 100644 --- a/test/suites/lib/remote_tarantool_server.py +++ b/test/suites/lib/remote_tarantool_server.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import sys import os import random diff --git a/test/suites/lib/tarantool_server.py b/test/suites/lib/tarantool_server.py index 2573a78a..d11ef623 100644 --- a/test/suites/lib/tarantool_server.py +++ b/test/suites/lib/tarantool_server.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os import os.path import errno diff --git a/test/suites/test_datetime.py b/test/suites/test_datetime.py index 17643f6d..a6ce0341 100644 --- a/test/suites/test_datetime.py +++ b/test/suites/test_datetime.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import re import unittest diff --git a/test/suites/test_dbapi.py b/test/suites/test_dbapi.py index 1435bb4f..3873fa84 100644 --- a/test/suites/test_dbapi.py +++ b/test/suites/test_dbapi.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest diff --git a/test/suites/test_decimal.py b/test/suites/test_decimal.py index ad633ddb..4745669f 100644 --- a/test/suites/test_decimal.py +++ b/test/suites/test_decimal.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import decimal diff --git a/test/suites/test_dml.py b/test/suites/test_dml.py index 6463778f..6c7808f6 100644 --- a/test/suites/test_dml.py +++ b/test/suites/test_dml.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import tarantool @@ -183,7 +179,7 @@ def test_07_call_16(self): ans = con.call('fiber.time64') self.assertEqual(len(ans), 1) self.assertEqual(len(ans[0]), 1) - self.assertIsInstance(ans[0][0], tarantool.utils.integer_types) + self.assertIsInstance(ans[0][0], int) ans = con.call('uuid.str') self.assertEqual(len(ans), 1) self.assertEqual(len(ans[0]), 1) @@ -207,7 +203,7 @@ def test_07_call_17(self): self.assertIsInstance(ans[0], float) ans = con.call('fiber.time64') self.assertEqual(len(ans), 1) - self.assertIsInstance(ans[0], tarantool.utils.integer_types) + self.assertIsInstance(ans[0], int) ans = con.call('uuid.str') self.assertEqual(len(ans), 1) self.assertIsInstance(ans[0], str) diff --git a/test/suites/test_encoding.py b/test/suites/test_encoding.py index f5f5f8c0..e434b2d5 100644 --- a/test/suites/test_encoding.py +++ b/test/suites/test_encoding.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import tarantool diff --git a/test/suites/test_execute.py b/test/suites/test_execute.py index 53fd9f2e..f90b2fc3 100644 --- a/test/suites/test_execute.py +++ b/test/suites/test_execute.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest diff --git a/test/suites/test_interval.py b/test/suites/test_interval.py index 0913dacb..63a3c0ca 100644 --- a/test/suites/test_interval.py +++ b/test/suites/test_interval.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import re import sys import unittest diff --git a/test/suites/test_mesh.py b/test/suites/test_mesh.py index df0b059a..cb0bce7c 100644 --- a/test/suites/test_mesh.py +++ b/test/suites/test_mesh.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import warnings diff --git a/test/suites/test_pool.py b/test/suites/test_pool.py index 12263d79..f10b6287 100644 --- a/test/suites/test_pool.py +++ b/test/suites/test_pool.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import time import unittest diff --git a/test/suites/test_protocol.py b/test/suites/test_protocol.py index 2e31f185..9442b0b0 100644 --- a/test/suites/test_protocol.py +++ b/test/suites/test_protocol.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest from tarantool.utils import greeting_decode, version_id diff --git a/test/suites/test_reconnect.py b/test/suites/test_reconnect.py index 403fd351..fc41cb57 100644 --- a/test/suites/test_reconnect.py +++ b/test/suites/test_reconnect.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import warnings diff --git a/test/suites/test_schema.py b/test/suites/test_schema.py index c5f12282..f289fe74 100644 --- a/test/suites/test_schema.py +++ b/test/suites/test_schema.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import tarantool diff --git a/test/suites/test_ssl.py b/test/suites/test_ssl.py index c2d4ba2b..977474f3 100644 --- a/test/suites/test_ssl.py +++ b/test/suites/test_ssl.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os import sys import unittest diff --git a/test/suites/test_uuid.py b/test/suites/test_uuid.py index c51c8c82..a0203538 100644 --- a/test/suites/test_uuid.py +++ b/test/suites/test_uuid.py @@ -1,7 +1,3 @@ -# -*- coding: utf-8 -*- - -from __future__ import print_function - import sys import unittest import uuid