diff --git a/vertica_python/tests/integration_tests/test_column.py b/vertica_python/tests/integration_tests/test_column.py index d5977b5e..f4c22071 100644 --- a/vertica_python/tests/integration_tests/test_column.py +++ b/vertica_python/tests/integration_tests/test_column.py @@ -40,11 +40,11 @@ class ColumnTestCase(VerticaPythonIntegrationTestCase): def test_column_names_query(self): - columns = ['isocode', 'name', u'\uFF04'] + columns = ['isocode', 'name', '\uFF04'] with self._connect() as conn: cur = conn.cursor() - cur.execute(u""" + cur.execute(""" SELECT 'US' AS {0}, 'United States' AS {1}, 'USD' AS {2} UNION ALL SELECT 'CA', 'Canada', 'CAD' UNION ALL SELECT 'MX', 'Mexico', 'MXN' """.format(*columns)) diff --git a/vertica_python/tests/integration_tests/test_cursor.py b/vertica_python/tests/integration_tests/test_cursor.py index 5dd6f2ea..cb2b7242 100644 --- a/vertica_python/tests/integration_tests/test_cursor.py +++ b/vertica_python/tests/integration_tests/test_cursor.py @@ -776,16 +776,16 @@ def test_qmark_paramstyle(self): def test_execute_parameters(self): with self._connect() as conn: cur = conn.cursor() - all_chars = u"".join(chr(i) for i in range(1, 128)) - backslash_data = u"\\backslash\\ \\data\\\\" + all_chars = "".join(chr(i) for i in range(1, 128)) + backslash_data = "\\backslash\\ \\data\\\\" cur.execute("SELECT :a, :b", parameters={"a": all_chars, "b": backslash_data}) self.assertEqual([all_chars, backslash_data], cur.fetchone()) def test_execute_percent_parameters(self): with self._connect() as conn: cur = conn.cursor() - all_chars = u"".join(chr(i) for i in range(1, 128)) - backslash_data = u"\\backslash\\ \\data\\\\" + all_chars = "".join(chr(i) for i in range(1, 128)) + backslash_data = "\\backslash\\ \\data\\\\" cur.execute("SELECT %s, %s", parameters=[all_chars, backslash_data]) self.assertEqual([all_chars, backslash_data], cur.fetchone()) @@ -898,16 +898,16 @@ def test_copy_local_stdin_multistat(self): # Check rejected files with open(rej1, 'r', encoding='utf-8') as f: - self.assertEqual(f.read(), u'x\u00f1,bla\n') + self.assertEqual(f.read(), 'x\u00f1,bla\n') with open(except1, 'r', encoding='utf-8') as f: content = f.read() - self.assertTrue(u"Invalid integer format 'x\u00f1' for column 1 (a)" in content) + self.assertTrue("Invalid integer format 'x\u00f1' for column 1 (a)" in content) with open(rej2, 'r', encoding='utf-8') as f: - self.assertEqual(f.read(), u'10,kkkkkkkkkkkk\nxx,corge\n') + self.assertEqual(f.read(), '10,kkkkkkkkkkkk\nxx,corge\n') with open(except2, 'r', encoding='utf-8') as f: content = f.read() - self.assertTrue(u"The 12-byte value is too long for type Varchar(9), column 2 (b)" in content) - self.assertTrue(u"Invalid integer format 'xx' for column 1 (a)" in content) + self.assertTrue("The 12-byte value is too long for type Varchar(9), column 2 (b)" in content) + self.assertTrue("Invalid integer format 'xx' for column 1 (a)" in content) # Delete data files try: @@ -1004,18 +1004,18 @@ def test_copy_local_file_multistat(self, fetch_results): # Check rejected files with open(rej1, 'r', encoding='utf-8') as f: - self.assertEqual(f.read(), u'x\u00f1,bla\n5,aaaaaaaaaa\n') + self.assertEqual(f.read(), 'x\u00f1,bla\n5,aaaaaaaaaa\n') with open(except1, 'r', encoding='utf-8') as f: content = f.read() - self.assertTrue(u"Invalid integer format 'x\u00f1' for column 1 (a)" in content) - self.assertTrue(u"The 10-byte value is too long for type Varchar(9), column 2 (b)" in content) + self.assertTrue("Invalid integer format 'x\u00f1' for column 1 (a)" in content) + self.assertTrue("The 10-byte value is too long for type Varchar(9), column 2 (b)" in content) with open(rej2, 'r', encoding='utf-8') as f: - self.assertEqual(f.read(), u'10,kkkkkkkkkkkk\nxx,corge\nf,quux\n') + self.assertEqual(f.read(), '10,kkkkkkkkkkkk\nxx,corge\nf,quux\n') with open(except2, 'r', encoding='utf-8') as f: content = f.read() - self.assertTrue(u"The 12-byte value is too long for type Varchar(9), column 2 (b)" in content) - self.assertTrue(u"Invalid integer format 'xx' for column 1 (a)" in content) - self.assertTrue(u"Invalid integer format 'f' for column 1 (a)" in content) + self.assertTrue("The 12-byte value is too long for type Varchar(9), column 2 (b)" in content) + self.assertTrue("Invalid integer format 'xx' for column 1 (a)" in content) + self.assertTrue("Invalid integer format 'f' for column 1 (a)" in content) # Delete files try: @@ -1059,7 +1059,7 @@ def test_copy_local_rejected_as_table(self): cur.execute("SELECT rejected_data, rejected_reason FROM test_loader_rejects ORDER BY row_number ASC") self.assertListOfListsEqual(cur.fetchall(), [['5,aaaaaaaaaa', 'The 10-byte value is too long for type Varchar(9), column 2 (b)'], - [u'x\u00f1,bla', u"Invalid integer format 'x\u00f1' for column 1 (a)"]]) + ['x\u00f1,bla', "Invalid integer format 'x\u00f1' for column 1 (a)"]]) cur.execute("SELECT * FROM {0} ORDER BY a ASC".format(self._table)) self.assertListOfListsEqual(cur.fetchall(), [[None, 'baz'], [1, 'foo'], [2, 'bar'], [4, None]]) @@ -1141,7 +1141,7 @@ def test_executemany_quoted_path(self): self._test_executemany(table, [(1, 'aa'), (2, 'bb')]) def test_executemany_utf8(self): - self._test_executemany(self._table, [(1, u'a\xfc'), (2, u'bb')]) + self._test_executemany(self._table, [(1, 'a\xfc'), (2, 'bb')]) # test for #292 def test_executemany_autocommit(self): @@ -1283,8 +1283,8 @@ def test_named_paramstyle(self): self.assertListOfListsEqual(res, [[1, 'varchar']]) def test_executemany(self): - values = ((None, 'foo'), [1, 'aa'], (2, None), [2, u'a\xfc']) - expected = [[None, 'foo'], [1, 'aa'], [2, None], [2, u'a\xfc']] + values = ((None, 'foo'), [1, 'aa'], (2, None), [2, 'a\xfc']) + expected = [[None, 'foo'], [1, 'aa'], [2, None], [2, 'a\xfc']] with self._connect() as conn: cur = conn.cursor() cur.execute("CREATE TABLE {} (a int, b varchar)".format(self._table)) @@ -1312,7 +1312,7 @@ def test_executemany(self): self.assertIsNone(cur.fetchone()) self.assertTrue(cur.nextset()) - self.assertListOfListsEqual(cur.fetchall(), [[2, u'a\xfc'], [2, None]]) + self.assertListOfListsEqual(cur.fetchall(), [[2, 'a\xfc'], [2, None]]) self.assertIsNone(cur.fetchone()) self.assertTrue(cur.nextset()) @@ -1353,8 +1353,8 @@ def test_bind_datetime(self): self.assertListOfListsEqual(res, [values]) def test_bind_binary(self): - values = [b'binary data', b'\\backslash data\\', u'\\backslash data\\', - u'\u00f1 encoding', 'raw data', 'long varbinary data', None] + values = [b'binary data', b'\\backslash data\\', '\\backslash data\\', + '\u00f1 encoding', 'raw data', 'long varbinary data', None] expected = [[b'binary data\x00\x00\x00', b'\\backslash data\\', b'\\backslash data\\', b'\xc3\xb1 encoding', b'raw data', b'long varbinary data', None]] @@ -1398,9 +1398,9 @@ def test_bind_numeric(self): def test_bind_character(self): values = ['char data', b'raw varchar data', - u'long varbinary data \u00f1', None, None, None] + 'long varbinary data \u00f1', None, None, None] expected = [['char data ', 'raw varchar data', - u'long varbinary data \u00f1', None, None, None]] + 'long varbinary data \u00f1', None, None, None]] with self._connect() as conn: cur = conn.cursor() cur.execute("""CREATE TABLE {} ( diff --git a/vertica_python/tests/integration_tests/test_datatypes.py b/vertica_python/tests/integration_tests/test_datatypes.py index d23ac893..95d8c2fa 100644 --- a/vertica_python/tests/integration_tests/test_datatypes.py +++ b/vertica_python/tests/integration_tests/test_datatypes.py @@ -136,10 +136,10 @@ def test_Array_numeric_type(self): None, [], [None]], test_executemany=True) def test_Array_char_type(self): - self._test_insert_complex_type('ARRAY[CHAR(3)]', [['a', u'\u16b1', None, 'foo'], None, [], [None]], [['a ', u'\u16b1', None, 'foo'], None, [], [None]], test_executemany=True) + self._test_insert_complex_type('ARRAY[CHAR(3)]', [['a', '\u16b1', None, 'foo'], None, [], [None]], [['a ', '\u16b1', None, 'foo'], None, [], [None]], test_executemany=True) def test_Array_varchar_type(self): - self._test_insert_complex_type('ARRAY[VARCHAR(10)]', [['', u'\u16b1\nb', None, 'foo'], None, [], [None]], test_executemany=True) + self._test_insert_complex_type('ARRAY[VARCHAR(10)]', [['', '\u16b1\nb', None, 'foo'], None, [], [None]], test_executemany=True) self._test_insert_complex_type('ARRAY[VARCHAR]', [[chr(i)] for i in range(1, 128)], test_executemany=True) def test_Array_date_type(self): @@ -178,10 +178,10 @@ def test_1DSet_numeric_type(self): None, set(), {None}], test_executemany=True) def test_1DSet_char_type(self): - self._test_insert_complex_type('SET[CHAR(3)]', [{'a ', u'\u16b1', None, 'foo'}, None, set(), {None}], test_executemany=True) + self._test_insert_complex_type('SET[CHAR(3)]', [{'a ', '\u16b1', None, 'foo'}, None, set(), {None}], test_executemany=True) def test_1DSet_varchar_type(self): - self._test_insert_complex_type('SET[VARCHAR(10)]', [{'', u'\u16b1\nb', None, 'foo'}, None, set(), {None}], test_executemany=True) + self._test_insert_complex_type('SET[VARCHAR(10)]', [{'', '\u16b1\nb', None, 'foo'}, None, set(), {None}], test_executemany=True) self._test_insert_complex_type('SET[VARCHAR]', [{chr(i)} for i in range(1, 128)], test_executemany=True) def test_1DSet_date_type(self): @@ -339,16 +339,16 @@ def test_1DArray_numeric_type(self): self.assertEqual(res[2], None) def test_1DArray_char_type(self): - query = u"SELECT ARRAY['a', '\u16b1b', null, 'foo']::ARRAY[CHAR(3)], ARRAY[]::ARRAY[CHAR(4)], null::ARRAY[CHAR(5)]" + query = "SELECT ARRAY['a', '\u16b1b', null, 'foo']::ARRAY[CHAR(3)], ARRAY[]::ARRAY[CHAR(4)], null::ARRAY[CHAR(5)]" res = self._query_and_fetchone(query) - self.assertEqual(res[0], ['a ', u'\u16b1', None, 'foo']) + self.assertEqual(res[0], ['a ', '\u16b1', None, 'foo']) self.assertEqual(res[1], []) self.assertEqual(res[2], None) def test_1DArray_varchar_type(self): - query = u"SELECT ARRAY['', '\u16b1\nb', null, 'foo']::ARRAY[VARCHAR(10),4], ARRAY[]::ARRAY[VARCHAR(4)], null::ARRAY[VARCHAR]" + query = "SELECT ARRAY['', '\u16b1\nb', null, 'foo']::ARRAY[VARCHAR(10),4], ARRAY[]::ARRAY[VARCHAR(4)], null::ARRAY[VARCHAR]" res = self._query_and_fetchone(query) - self.assertEqual(res[0], ['', u'\u16b1\nb', None, 'foo']) + self.assertEqual(res[0], ['', '\u16b1\nb', None, 'foo']) self.assertEqual(res[1], []) self.assertEqual(res[2], None) @@ -564,16 +564,16 @@ def test_1DSet_numeric_type(self): self.assertEqual(res[2], None) def test_1DSet_char_type(self): - query = u"SELECT SET['a', '\u16b1b', null, 'foo']::SET[CHAR(3)], SET[]::SET[CHAR(4)], null::SET[CHAR(5)]" + query = "SELECT SET['a', '\u16b1b', null, 'foo']::SET[CHAR(3)], SET[]::SET[CHAR(4)], null::SET[CHAR(5)]" res = self._query_and_fetchone(query) - self.assertEqual(res[0], {'a ', u'\u16b1', None, 'foo'}) + self.assertEqual(res[0], {'a ', '\u16b1', None, 'foo'}) self.assertEqual(res[1], set()) self.assertEqual(res[2], None) def test_1DSet_varchar_type(self): - query = u"SELECT SET['', '\u16b1\nb', null, 'foo']::SET[VARCHAR(10),4], SET[]::SET[VARCHAR(4)], null::SET[VARCHAR]" + query = "SELECT SET['', '\u16b1\nb', null, 'foo']::SET[VARCHAR(10),4], SET[]::SET[VARCHAR(4)], null::SET[VARCHAR]" res = self._query_and_fetchone(query) - self.assertEqual(res[0], {'', u'\u16b1\nb', None, 'foo'}) + self.assertEqual(res[0], {'', '\u16b1\nb', None, 'foo'}) self.assertEqual(res[1], set()) self.assertEqual(res[2], None) @@ -594,7 +594,7 @@ def test_1DSet_time_type(self): def test_1DSet_timetz_type(self): query = "SELECT SET['22:36:33.12345+0630', null, '800-02-03 22:36:33.123456 America/Cayman']::SET[TIMETZ(3)], SET[]::SET[TIMETZ(4)], null::SET[TIMETZ]" res = self._query_and_fetchone(query) - self.assertEqual(res[0], {time(22, 36, 33, 123000, tzinfo=tzoffset(None, 23400)), None, + self.assertEqual(res[0], {time(22, 36, 33, 123000, tzinfo=tzoffset(None, 23400)), None, time(22, 36, 33, 123000, tzinfo=tzoffset(None, -19176))}) self.assertEqual(res[1], set()) self.assertEqual(res[2], None) diff --git a/vertica_python/tests/integration_tests/test_transfer_format.py b/vertica_python/tests/integration_tests/test_transfer_format.py index 30403683..31b07a6c 100644 --- a/vertica_python/tests/integration_tests/test_transfer_format.py +++ b/vertica_python/tests/integration_tests/test_transfer_format.py @@ -37,7 +37,7 @@ def tearDownClass(cls): def _test_equal_value(self, sql_type, data_list, assert_almost_equal=False): for data in data_list: - query = u"SELECT {}{}".format(data, "::" + sql_type if sql_type else '') + query = "SELECT {}{}".format(data, "::" + sql_type if sql_type else '') self.text_cursor.execute(query) self.binary_cursor.execute(query) text_val = self.text_cursor.fetchone()[0] @@ -67,9 +67,9 @@ def test_numeric_type(self): self._test_equal_value("DECIMAL", ["123456789.98765"]) def test_char_type(self): - self._test_equal_value("CHAR(8)", [u"'\u16b1'"]) - self._test_equal_value("VARCHAR", [u"'foo\u16b1'"]) - self._test_equal_value("LONG VARCHAR", [u"'foo \u16b1 bar'"]) + self._test_equal_value("CHAR(8)", ["'\u16b1'"]) + self._test_equal_value("VARCHAR", ["'foo\u16b1'"]) + self._test_equal_value("LONG VARCHAR", ["'foo \u16b1 bar'"]) def test_datetime_type(self): self._test_equal_value("DATE", ["'0340-01-20'", "'2001-12-01'", "'9999-12-31'"]) @@ -98,9 +98,9 @@ def test_UUID_type(self): self._test_equal_value("UUID", ["'00010203-0405-0607-0809-0a0b0c0d0e0f'", "'123e4567-e89b-12d3-a456-426655440a00'"]) def test_binary_type(self): - self._test_equal_value("BINARY(2)", [u"'\303\261'"]) - self._test_equal_value("VARBINARY", [u"'\303\261'"]) - self._test_equal_value("LONG VARBINARY", [u"'\303\261\303\260'"]) + self._test_equal_value("BINARY(2)", ["'\303\261'"]) + self._test_equal_value("VARBINARY", ["'\303\261'"]) + self._test_equal_value("LONG VARBINARY", ["'\303\261\303\260'"]) def test_array_type(self): self._test_equal_value("ARRAY[INT]", ["ARRAY[1,2,3]"]) diff --git a/vertica_python/tests/integration_tests/test_unicode.py b/vertica_python/tests/integration_tests/test_unicode.py index 1d44df1a..2bc3306f 100644 --- a/vertica_python/tests/integration_tests/test_unicode.py +++ b/vertica_python/tests/integration_tests/test_unicode.py @@ -40,8 +40,8 @@ class UnicodeTestCase(VerticaPythonIntegrationTestCase): def test_unicode_query(self): - value = u'\u16a0' - query = u"SELECT '{0}'".format(value) + value = '\u16a0' + query = "SELECT '{0}'".format(value) with self._connect() as conn: cur = conn.cursor() @@ -51,8 +51,8 @@ def test_unicode_query(self): self.assertResultEqual(value, res[0]) def test_unicode_list_parameter(self): - values = [u'\u00f1', 'foo', 3] - query = u"SELECT {0}".format(", ".join(["%s"] * len(values))) + values = ['\u00f1', 'foo', 3] + query = "SELECT {0}".format(", ".join(["%s"] * len(values))) with self._connect() as conn: cur = conn.cursor() @@ -63,10 +63,10 @@ def test_unicode_list_parameter(self): self.assertResultEqual(val, res) def test_unicode_named_parameter_binding(self): - values = [u'\u16b1', 'foo', 3] - keys = [u'\u16a0', 'foo', 3] + values = ['\u16b1', 'foo', 3] + keys = ['\u16a0', 'foo', 3] - query = u"SELECT {0}".format(", ".join([u":{0}".format(key) for key in keys])) + query = "SELECT {0}".format(", ".join([":{0}".format(key) for key in keys])) with self._connect() as conn: cur = conn.cursor() @@ -77,8 +77,8 @@ def test_unicode_named_parameter_binding(self): self.assertResultEqual(val, res) def test_string_query(self): - value = u'test' - query = u"SELECT '{0}'".format(value) + value = 'test' + query = "SELECT '{0}'".format(value) with self._connect() as conn: cur = conn.cursor() @@ -88,9 +88,9 @@ def test_string_query(self): self.assertEqual(value, res[0]) def test_string_named_parameter_binding(self): - key = u'test' - value = u'value' - query = u"SELECT :{0}".format(key) + key = 'test' + value = 'value' + query = "SELECT :{0}".format(key) with self._connect() as conn: cur = conn.cursor() @@ -101,9 +101,9 @@ def test_string_named_parameter_binding(self): # unit test for issue #160 def test_null_named_parameter_binding(self): - key = u'test' + key = 'test' value = None - query = u"SELECT :{0}".format(key) + query = "SELECT :{0}".format(key) with self._connect() as conn: cur = conn.cursor() @@ -114,8 +114,8 @@ def test_null_named_parameter_binding(self): # unit test for issue #160 def test_null_list_parameter(self): - values = [u'\u00f1', 'foo', None] - query = u"SELECT {0}".format(", ".join(["%s"] * len(values))) + values = ['\u00f1', 'foo', None] + query = "SELECT {0}".format(", ".join(["%s"] * len(values))) with self._connect() as conn: cur = conn.cursor() diff --git a/vertica_python/tests/unit_tests/test_sql_literal.py b/vertica_python/tests/unit_tests/test_sql_literal.py index 250dea01..1c4fb30e 100644 --- a/vertica_python/tests/unit_tests/test_sql_literal.py +++ b/vertica_python/tests/unit_tests/test_sql_literal.py @@ -47,13 +47,13 @@ def test_default_adapters(self): self.assertEqual(cursor.object_to_sql_literal(datetime.date(2018, 9, 7)), "'2018-09-07'") self.assertEqual(cursor.object_to_sql_literal(datetime.time(13, 50, 9)), "'13:50:09'") # String - self.assertEqual(cursor.object_to_sql_literal(u"string'1"), "'string''1'") + self.assertEqual(cursor.object_to_sql_literal("string'1"), "'string''1'") self.assertEqual(cursor.object_to_sql_literal(b"string'1"), "'string''1'") # Tuple and namedtuple self.assertEqual(cursor.object_to_sql_literal( - (123, u"string'1", None)), "(123,'string''1',NULL)") + (123, "string'1", None)), "(123,'string''1',NULL)") self.assertEqual(cursor.object_to_sql_literal( - ((1, u"a"), (2, u"b"), (3, u"c"))), "((1,'a'),(2,'b'),(3,'c'))") + ((1, "a"), (2, "b"), (3, "c"))), "((1,'a'),(2,'b'),(3,'c'))") Point = namedtuple('Point', ['x', 'y', 'z']) p = Point(x=11, y=22, z=33) self.assertEqual(cursor.object_to_sql_literal(p), "(11,22,33)") diff --git a/vertica_python/vertica/cursor.py b/vertica_python/vertica/cursor.py index 9ce23e7c..fea7e2ea 100644 --- a/vertica_python/vertica/cursor.py +++ b/vertica_python/vertica/cursor.py @@ -125,12 +125,12 @@ ) -RE_NAME_BASE = u"[0-9a-zA-Z_][\\w\\d\\$_]*" -RE_NAME = u'(("{0}")|({0}))'.format(RE_NAME_BASE) +RE_NAME_BASE = "[0-9a-zA-Z_][\\w\\d\\$_]*" +RE_NAME = '(("{0}")|({0}))'.format(RE_NAME_BASE) RE_BASIC_INSERT_STAT = ( - u"\\s*INSERT\\s+INTO\\s+(?P({0}\\.)?{0})" - u"\\s*\\(\\s*(?P{0}(\\s*,\\s*{0})*)\\s*\\)" - u"\\s+VALUES\\s*\\(\\s*(?P(.|\\s)*)\\s*\\)").format(RE_NAME) + "\\s*INSERT\\s+INTO\\s+(?P({0}\\.)?{0})" + "\\s*\\(\\s*(?P{0}(\\s*,\\s*{0})*)\\s*\\)" + "\\s+VALUES\\s*\\(\\s*(?P(.|\\s)*)\\s*\\)").format(RE_NAME) END_OF_RESULT_RESPONSES = (messages.CommandComplete, messages.PortalSuspended) END_OF_BATCH_RESPONSES = (messages.WriteFile, messages.EndOfBatchResponse) DEFAULT_BUFFER_SIZE = 131072 @@ -320,9 +320,9 @@ def executemany(self, data = "\n".join(seq_of_values) copy_statement = ( - u"COPY {0} ({1}) FROM STDIN " - u"ENCLOSED BY '''' " # '/r' will have trouble if ENCLOSED BY is not set - u"ENFORCELENGTH ABORT ON ERROR{2}").format(target, variables, + "COPY {0} ({1}) FROM STDIN " + "ENCLOSED BY '''' " # '/r' will have trouble if ENCLOSED BY is not set + "ENFORCELENGTH ABORT ON ERROR{2}").format(target, variables, " NO COMMIT" if not self.connection.autocommit else '') self.copy(copy_statement, data) @@ -491,7 +491,7 @@ def copy(self, sql: str, data: Union[IO[AnyStr], bytes, str], **kwargs: Any) -> else: raise TypeError("Not valid type of data {0}".format(type(data))) - self._logger.info(u'Execute COPY statement: [{}]'.format(sql)) + self._logger.info('Execute COPY statement: [{}]'.format(sql)) # Execute a `COPY FROM STDIN` SQL statement self.connection.write(messages.Query(sql)) @@ -726,7 +726,7 @@ def format_operation_with_parameters(self, operation: str, parameters: Union[Lis # Using a regex with word boundary to correctly handle params with similar names # such as :s and :start - match_str = u":{0}\\b".format(key) + match_str = ":{0}\\b".format(key) operation = re.sub(match_str, lambda _: value, operation, flags=re.U) elif isinstance(parameters, (tuple, list)): @@ -751,21 +751,21 @@ def format_quote(self, param: str, is_copy_data: bool, is_collection: bool) -> s for i, c in enumerate(param): if c in '\\\n\"': s[i] = "\\" + c - return u'"{0}"'.format(u"".join(s)) + return '"{0}"'.format("".join(s)) elif is_copy_data: # COPY ENCLOSED BY s = list(param) for i, c in enumerate(param): if c in '\\|\n\'': s[i] = "\\" + c - return u"'{0}'".format(u"".join(s)) + return "'{0}'".format("".join(s)) else: - return u"'{0}'".format(param.replace(u"'", u"''")) + return "'{0}'".format(param.replace("'", "''")) def _execute_simple_query(self, query: str) -> None: """ Send the query to the server using the simple query protocol. """ - self._logger.info(u'Execute simple query: [{}]'.format(query)) + self._logger.info('Execute simple query: [{}]'.format(query)) # All of the statements in the query are sent here in a single message self.connection.write(messages.Query(query)) @@ -950,7 +950,7 @@ def _prepare(self, query: str) -> None: Send the query to be prepared to the server. The server will parse the query and return some metadata. """ - self._logger.info(u'Prepare a statement: [{}]'.format(query)) + self._logger.info('Prepare a statement: [{}]'.format(query)) # Send Parse message to server # We don't need to tell the server the parameter types yet @@ -1004,7 +1004,7 @@ def _execute_prepared_statement(self, list_of_parameter_values: Sequence[Any]) - for parameter_values in list_of_parameter_values: if parameter_values is None: parameter_values = () - self._logger.info(u'Bind parameters: {}'.format(parameter_values)) + self._logger.info('Bind parameters: {}'.format(parameter_values)) if len(parameter_values) != parameter_count: msg = ("Invalid number of parameters for {}: {} given, {} expected" .format(parameter_values, len(parameter_values), parameter_count))