From a551272c70e3bde9642483f0c4c679827f074ecf Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Sun, 31 Jul 2016 20:38:18 +0900 Subject: [PATCH 1/9] Reorganize json module import --- simplesqlite/loader/json/core.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/simplesqlite/loader/json/core.py b/simplesqlite/loader/json/core.py index 02d658c..8ed7044 100644 --- a/simplesqlite/loader/json/core.py +++ b/simplesqlite/loader/json/core.py @@ -6,11 +6,7 @@ from __future__ import absolute_import - -try: - import json -except ImportError: - import simplejson as json +import json import path From 78f429f99fc4c8be71913d4507a50cdd6b5d0505 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Sun, 7 Aug 2016 10:00:27 +0900 Subject: [PATCH 2/9] Remove spaces --- simplesqlite/loader/formatter.py | 4 ++-- simplesqlite/loader/interface.py | 8 ++++---- simplesqlite/loader/json/formatter.py | 2 +- simplesqlite/loader/spreadsheet/core.py | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/simplesqlite/loader/formatter.py b/simplesqlite/loader/formatter.py index 8be81b4..fbfae27 100644 --- a/simplesqlite/loader/formatter.py +++ b/simplesqlite/loader/formatter.py @@ -21,11 +21,11 @@ class TableFormatterInterface(object): """ @abc.abstractmethod - def to_table_data(self): # pragma: no cover + def to_table_data(self): # pragma: no cover pass @abc.abstractmethod - def _validate_source_data(self): # pragma: no cover + def _validate_source_data(self): # pragma: no cover pass diff --git a/simplesqlite/loader/interface.py b/simplesqlite/loader/interface.py index c245ae6..95b4589 100644 --- a/simplesqlite/loader/interface.py +++ b/simplesqlite/loader/interface.py @@ -19,19 +19,19 @@ class TableLoaderInterface(object): """ @abc.abstractmethod - def load(self): # pragma: no cover + def load(self): # pragma: no cover pass @abc.abstractmethod - def _validate(self): # pragma: no cover + def _validate(self): # pragma: no cover pass @abc.abstractmethod - def _validate_table_name(self): # pragma: no cover + def _validate_table_name(self): # pragma: no cover pass @abc.abstractmethod - def _validate_source(self): # pragma: no cover + def _validate_source(self): # pragma: no cover pass diff --git a/simplesqlite/loader/json/formatter.py b/simplesqlite/loader/json/formatter.py index 30a70e1..454eea5 100644 --- a/simplesqlite/loader/json/formatter.py +++ b/simplesqlite/loader/json/formatter.py @@ -27,7 +27,7 @@ def __init__(self, json_buffer): self._buffer = json_buffer @abc.abstractproperty - def _schema(self): # pragma: no cover + def _schema(self): # pragma: no cover pass def _validate_source_data(self): diff --git a/simplesqlite/loader/spreadsheet/core.py b/simplesqlite/loader/spreadsheet/core.py index 42f6baf..ddbf7d7 100644 --- a/simplesqlite/loader/spreadsheet/core.py +++ b/simplesqlite/loader/spreadsheet/core.py @@ -35,23 +35,23 @@ def __init__(self, source): self._end_col_idx = None @abc.abstractproperty - def _sheet_name(self): # pragma: no cover + def _sheet_name(self): # pragma: no cover pass @abc.abstractproperty - def _row_count(self): # pragma: no cover + def _row_count(self): # pragma: no cover pass @abc.abstractproperty - def _col_count(self): # pragma: no cover + def _col_count(self): # pragma: no cover pass @abc.abstractmethod - def _is_empty_sheet(self): # pragma: no cover + def _is_empty_sheet(self): # pragma: no cover pass @abc.abstractmethod - def _get_start_row_idx(self): # pragma: no cover + def _get_start_row_idx(self): # pragma: no cover pass def make_table_name(self): From 64c3ebff1abed522bf67af3686380249f16f04af Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:08:39 +0900 Subject: [PATCH 3/9] Update docstring --- simplesqlite/loader/csv/core.py | 6 ++++-- simplesqlite/loader/error.py | 8 ++++++-- simplesqlite/loader/json/core.py | 4 ++++ simplesqlite/loader/json/formatter.py | 4 ++-- simplesqlite/loader/spreadsheet/excelloader.py | 3 ++- simplesqlite/loader/spreadsheet/gsloader.py | 3 ++- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/simplesqlite/loader/csv/core.py b/simplesqlite/loader/csv/core.py index 83ea2d2..dbaf404 100644 --- a/simplesqlite/loader/csv/core.py +++ b/simplesqlite/loader/csv/core.py @@ -106,7 +106,8 @@ def load(self): Table name is determined by :py:meth:`~.CsvTableFileLoader.make_table_name`. :rtype: iterator of |TableData| - :raises InvalidDataError: If the CSV data is invalid. + :raises simplesqlite.loader.InvalidDataError: + If the CSV data is invalid. .. seealso:: :py:func:`csv.reader` """ @@ -136,7 +137,8 @@ def load(self): :return: Loaded table data. :rtype: iterator of |TableData| - :raises InvalidDataError: If the CSV data is invalid. + :raises simplesqlite.loader.InvalidDataError: + If the CSV data is invalid. .. seealso:: :py:func:`csv.reader` """ diff --git a/simplesqlite/loader/error.py b/simplesqlite/loader/error.py index 5be82b7..5344222 100644 --- a/simplesqlite/loader/error.py +++ b/simplesqlite/loader/error.py @@ -9,8 +9,12 @@ class ValidationError(Exception): - pass + """ + Raised data is not properly formatted. + """ class InvalidDataError(Exception): - pass + """ + Raised when data is invalid to load. + """ diff --git a/simplesqlite/loader/json/core.py b/simplesqlite/loader/json/core.py index 8ed7044..b152fd9 100644 --- a/simplesqlite/loader/json/core.py +++ b/simplesqlite/loader/json/core.py @@ -89,6 +89,10 @@ def load(self): :return: Loaded table data. :rtype: iterator of |TableData| + :raises simplesqlite.loader.InvalidDataError: + If the data is invalid JSON. + :raises simplesqlite.loader.ValidationError: + If the data is not acceptable JSON format. """ self._validate() diff --git a/simplesqlite/loader/json/formatter.py b/simplesqlite/loader/json/formatter.py index 454eea5..92b56f7 100644 --- a/simplesqlite/loader/json/formatter.py +++ b/simplesqlite/loader/json/formatter.py @@ -68,7 +68,7 @@ def _schema(self): def to_table_data(self): """ :raises ValueError: - :raises ValidationError: + :raises simplesqlite.loader.ValidationError: """ self._validate_source_data() @@ -109,7 +109,7 @@ def _schema(self): def to_table_data(self): """ :raises ValueError: - :raises ValidationError: + :raises simplesqlite.loader.ValidationError: """ self._validate_source_data() diff --git a/simplesqlite/loader/spreadsheet/excelloader.py b/simplesqlite/loader/spreadsheet/excelloader.py index 862e864..1292057 100644 --- a/simplesqlite/loader/spreadsheet/excelloader.py +++ b/simplesqlite/loader/spreadsheet/excelloader.py @@ -66,7 +66,8 @@ def load(self): |load_return| :py:meth:`~.ExcelTableFileLoader.make_table_name`. :rtype: iterator of |TableData| - :raises InvalidDataError: If the header row is not found. + :raises simplesqlite.loader.InvalidDataError: + If the header row is not found. """ self._validate() diff --git a/simplesqlite/loader/spreadsheet/gsloader.py b/simplesqlite/loader/spreadsheet/gsloader.py index 8e4e47f..13c7174 100644 --- a/simplesqlite/loader/spreadsheet/gsloader.py +++ b/simplesqlite/loader/spreadsheet/gsloader.py @@ -76,7 +76,8 @@ def load(self): |load_return| :py:meth:`~.GoogleSheetsTableLoader.make_table_name`. :rtype: iterator of |TableData| - :raises InvalidDataError: If the header row is not found. + :raises simplesqlite.loader.InvalidDataError: + If the header row is not found. """ import gspread From 0dcd1c9db71b5098e29466f4c056b7ae5ac782a8 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:08:54 +0900 Subject: [PATCH 4/9] Add a requirement --- requirements/docs_requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/docs_requirements.txt b/requirements/docs_requirements.txt index 483a4e9..ab3f3dd 100644 --- a/requirements/docs_requirements.txt +++ b/requirements/docs_requirements.txt @@ -1 +1,2 @@ +Sphinx sphinx_rtd_theme From da997d3e7c8982ef6ecc79e4abf24a357759c8ef Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:09:14 +0900 Subject: [PATCH 5/9] Update docs --- docs/pages/reference/error.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/pages/reference/error.rst b/docs/pages/reference/error.rst index 4815072..ae91a55 100644 --- a/docs/pages/reference/error.rst +++ b/docs/pages/reference/error.rst @@ -12,3 +12,9 @@ Errors .. autoexception:: simplesqlite.SqlSyntaxError :show-inheritance: + +.. autoexception:: simplesqlite.loader.InvalidDataError + :show-inheritance: + +.. autoexception:: simplesqlite.loader.ValidationError + :show-inheritance: From e342d5295768c9716ab0580d04d558e162c75303 Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:25:34 +0900 Subject: [PATCH 6/9] Modifications to change string formatting to format method --- simplesqlite/_func.py | 6 ++-- simplesqlite/core.py | 63 ++++++++++++++++++++-------------------- simplesqlite/sqlquery.py | 44 ++++++++++++++-------------- 3 files changed, 58 insertions(+), 55 deletions(-) diff --git a/simplesqlite/_func.py b/simplesqlite/_func.py index 580919a..91170a4 100644 --- a/simplesqlite/_func.py +++ b/simplesqlite/_func.py @@ -54,9 +54,9 @@ def append_table(con_src, con_dst, table_name): if src_attr_list != dst_attr_list: raise ValueError(""" source and destination attribute is different from each other - src: %s - dst: %s - """ % (str(src_attr_list), str(dst_attr_list))) + src: {:s} + dst: {:s} + """.format(str(src_attr_list), str(dst_attr_list))) result = con_src.select(select="*", table_name=table_name) if result is None: diff --git a/simplesqlite/core.py b/simplesqlite/core.py index d2b470c..34232ed 100644 --- a/simplesqlite/core.py +++ b/simplesqlite/core.py @@ -228,11 +228,11 @@ def execute_query(self, query, caller=None): caller = logging.getLogger().findCaller() file_path, line_no, func_name = caller[:3] message_list = [ - "failed to execute query at %s(%d) %s" % ( + "failed to execute query at %{:s}({:d}) {:s}".format( file_path, line_no, func_name), - " - query: %s" % (query), - " - msg: %s" % (e), - " - db: %s" % (self.database_path), + " - query: {:s}".format(query), + " - msg: {:s}".format(str(e)), + " - db: {:s}".format(self.database_path), ] raise sqlite3.OperationalError(os.linesep.join(message_list)) @@ -328,12 +328,12 @@ def insert_many(self, table_name, insert_record_list): caller = logging.getLogger().findCaller() file_path, line_no, func_name = caller[:3] raise sqlite3.OperationalError( - "%s(%d) %s: failed to execute query:\n" % ( + "{:s}({:d}) {:s}: failed to execute query:\n".format( file_path, line_no, func_name) + - " query=%s\n" % (query) + - " msg='%s'\n" % (str(e)) + - " db=%s\n" % (self.database_path) + - " records=%s\n" % (record_list[:2]) + " query={:s}\n".format(query) + + " msg='{:s}'\n".format(str(e)) + + " db={:s}\n".format(self.database_path) + + " records={:s}\n".format(record_list[:2]) ) def update(self, table_name, set_query, where=None): @@ -476,7 +476,7 @@ def get_attribute_name_list(self, table_name): self.verify_table_existence(table_name) - query = "SELECT * FROM '%s'" % (table_name) + query = "SELECT * FROM '{:s}'".format(table_name) result = self.execute_query(query, logging.getLogger().findCaller()) return self.__get_list_from_fetch(result.description) @@ -498,7 +498,7 @@ def get_attr_type(self, table_name): self.verify_table_existence(table_name) result = self.execute_query( - "SELECT sql FROM sqlite_master WHERE type='table' and name=%s" % ( + "SELECT sql FROM sqlite_master WHERE type='table' and name={:s}".format( SqlQuery.to_value_str(table_name))) query = result.fetchone()[0] match = re.search("[(].*[)]", query) @@ -527,9 +527,9 @@ def get_attribute_type_list(self, table_name): self.verify_table_existence(table_name) attribute_name_list = self.get_attribute_name_list(table_name) - query = "SELECT DISTINCT %s FROM '%s'" % ( + query = "SELECT DISTINCT {:s} FROM '{:s}'".format( ",".join([ - "TYPEOF(%s)" % (SqlQuery.to_attr_str(attribute)) + "TYPEOF({:s})".format(SqlQuery.to_attr_str(attribute)) for attribute in attribute_name_list]), table_name) result = self.execute_query(query, logging.getLogger().findCaller()) @@ -583,9 +583,9 @@ def get_profile(self, profile_count=50): try: result = con_tmp.select( - select="%s,SUM(%s),SUM(%s)" % attribute_name_list, + select="{:s},SUM({:s}),SUM({:s})".format(*attribute_name_list), table_name=profile_table_name, - extra="GROUP BY %s ORDER BY %s DESC LIMIT %d" % ( + extra="GROUP BY {:s} ORDER BY {:s} DESC LIMIT {:d}".format( "query", "cumulative_time", profile_count)) except sqlite3.OperationalError: return [] @@ -832,7 +832,8 @@ def verify_table_existence(self, table_name): return raise TableNotFoundError( - "'%s' table not found in %s" % (table_name, self.database_path)) + "'{:s}' table not found in {:s}".format( + table_name, self.database_path)) def verify_attribute_existence(self, table_name, attribute_name): """ @@ -879,7 +880,7 @@ def verify_attribute_existence(self, table_name, attribute_name): return raise AttributeNotFoundError( - "'%s' attribute not found in '%s' table" % ( + "'{:s}' attribute not found in '{:s}' table".format( attribute_name, table_name)) def drop_table(self, table_name): @@ -893,7 +894,7 @@ def drop_table(self, table_name): self.validate_access_permission(["w", "a"]) if self.has_table(table_name): - query = "DROP TABLE IF EXISTS '%s'" % (table_name) + query = "DROP TABLE IF EXISTS '{:s}'".format(table_name) self.execute_query(query, logging.getLogger().findCaller()) self.commit() @@ -912,7 +913,7 @@ def create_table(self, table_name, attribute_description_list): if self.has_table(table_name): return True - query = "CREATE TABLE IF NOT EXISTS '%s' (%s)" % ( + query = "CREATE TABLE IF NOT EXISTS '{:s}' ({:s})".format( table_name, ", ".join(attribute_description_list)) if self.execute_query(query, logging.getLogger().findCaller()) is None: return False @@ -934,14 +935,14 @@ def create_index(self, table_name, attribute_name): self.verify_table_existence(table_name) self.validate_access_permission(["w", "a"]) - index_name = "%s_%s_index" % ( + index_name = "{:s}_{:s}_index".format( SqlQuery.sanitize(table_name), SqlQuery.sanitize(attribute_name)) if attribute_name.find("'") != -1: - query_format = 'CREATE INDEX IF NOT EXISTS %s ON %s("%s")' + query_format = 'CREATE INDEX IF NOT EXISTS {:s} ON {:s}("{:s})' else: - query_format = "CREATE INDEX IF NOT EXISTS %s ON %s('%s')" + query_format = "CREATE INDEX IF NOT EXISTS {:s} ON {:s}('{:s}')" - query = query_format % ( + query = query_format.format( index_name, SqlQuery.to_table_str(table_name), attribute_name) @@ -1000,7 +1001,7 @@ def create_table_with_data( self.validate_access_permission(["w", "a"]) if dataproperty.is_empty_sequence(data_matrix): - raise ValueError("input data is null: '%s (%s)'" % ( + raise ValueError("input data is null: '{:s} ({:s})'".format( table_name, ", ".join(attribute_name_list))) data_matrix = RecordConvertor.to_record_list( @@ -1209,10 +1210,10 @@ def __verify_value_matrix(field_list, value_matrix): raise ValueError( "miss match header length and value length:" + - " header: %d %s\n" % (len(field_list), str(field_list)) + - " # of miss match line: %d ouf of %d\n" % ( + " header: {:d} {:s}\n".format(len(field_list), str(field_list)) + + " # of miss match line: {:d} ouf of {:d}\n".format( len(miss_match_idx_list), len(value_matrix)) + - " e.g. value at line=%d, len=%d: %s\n" % ( + " e.g. value at line={:d}, len={:d}: {:s}\n".format( miss_match_idx_list[0], len(sample_miss_match_list), str(sample_miss_match_list)) ) @@ -1241,11 +1242,11 @@ def __get_attr_desc_list(self, attr_name_list, data_matrix): six.iteritems(self.__get_column_valuetype(data_matrix))): attr_name = attr_name_list[col] if attr_name.find("'") != -1: - desc_format = '"%s" %s' + desc_format = '"{:s}" {:s}' else: - desc_format = "'%s' %s" + desc_format = "'{:s}' {:s}" attr_description_list.append( - desc_format % (attr_name, value_type)) + desc_format.format(attr_name, value_type)) return attr_description_list @@ -1268,7 +1269,7 @@ def validate_access_permission(self, valid_permission_list): if self.mode not in valid_permission_list: raise IOError( - "invalid access: expected-mode='%s', current-mode='%s'" % ( + "invalid access: expected-mode='{:s}', current-mode='{:s}'".format( "' or '".join(valid_permission_list), self.mode)) @staticmethod diff --git a/simplesqlite/sqlquery.py b/simplesqlite/sqlquery.py index 988c0c9..c2323b2 100644 --- a/simplesqlite/sqlquery.py +++ b/simplesqlite/sqlquery.py @@ -22,11 +22,12 @@ class SqlQuery: """ __RE_SANITIZE = re.compile( - "[%s]" % (re.escape("%/()[]<>.:;'\"!\# -+=\n\r"))) - __RE_SANITIZE_ATTR = re.compile("[%s]" % (re.escape("'\""))) - __RE_TABLE_STR = re.compile("[%s]" % (re.escape("%()-+/."))) - __RE_TO_ATTR_QUOTE = re.compile("[%s]" % (re.escape("[_]"))) - __RE_TO_ATTR_BRACKET = re.compile("[%s0-9\s#]" % (re.escape("%()-+/.'\""))) + "[{:s}]".format(re.escape("%/()[]<>.:;'\"!\# -+=\n\r"))) + __RE_SANITIZE_ATTR = re.compile("[{:s}]".format(re.escape("'\""))) + __RE_TABLE_STR = re.compile("[{:s}]".format(re.escape("%()-+/."))) + __RE_TO_ATTR_QUOTE = re.compile("[{:s}]".format(re.escape("[_]"))) + __RE_TO_ATTR_BRACKET = re.compile( + "[{:s}0-9\s#]".format(re.escape("%()-+/.'\""))) __RE_SPACE = re.compile("[\s]+") __VALID_WHERE_OPERATION_LIST = [ @@ -80,10 +81,10 @@ def to_table_str(cls, name): """ if cls.__RE_TABLE_STR.search(name): - return "[%s]" % (name) + return "[{:s}]".format(name) if cls.__RE_SPACE.search(name): - return "'%s'" % (name) + return "'{:s}'".format(name) return name @@ -110,16 +111,16 @@ def to_attr_str(cls, name, operation_query=""): name = cls.sanitize_attr(name) if cls.__RE_TO_ATTR_QUOTE.search(name): - sql_name = '"%s"' % (name) + sql_name = '"{:s}"'.format(name) elif cls.__RE_TO_ATTR_BRACKET.search(name): - sql_name = "[%s]" % (name) + sql_name = "[{:s}]".format(name) elif name == "join": - sql_name = "[%s]" % (name) + sql_name = "[{:s}]".format(name) else: sql_name = name if dataproperty.is_not_empty_string(operation_query): - sql_name = "%s(%s)" % (operation_query, sql_name) + sql_name = "{:s}({:s})".format(operation_query, sql_name) return sql_name @@ -151,7 +152,7 @@ def to_attr_str_list(cls, name_list, operation_query=""): return list(map(cls.to_attr_str, name_list)) return [ - "%s(%s)" % (operation_query, cls.to_attr_str(name)) + "{:s}({:s})".format(operation_query, cls.to_attr_str(name)) for name in name_list ] @@ -186,7 +187,7 @@ def to_value_str(cls, value): ]): return str(value) - return "'%s'" % (value) + return "'{}'".format(value) @classmethod def to_value_str_list(cls, value_list): @@ -280,13 +281,13 @@ def make_insert(cls, table, insert_tuple, is_insert_many=False): value_list = ['?' for _i in insert_tuple] else: value_list = [ - "'%s'" % (value) + "'{:s}'".format(value) if isinstance(value, six.string_types) and value != "NULL" else str(value) for value in insert_tuple ] - return "INSERT INTO %s VALUES (%s)" % ( + return "INSERT INTO {:s} VALUES ({:s})".format( table, ",".join(value_list)) @classmethod @@ -349,16 +350,17 @@ def make_where(cls, key, value, operation="="): raise SqlSyntaxError("operation not supported: " + str(operation)) if value is not None: - return "%s %s %s" % ( + return "{:s} {:s} {:s}".format( cls.to_attr_str(key), operation, cls.to_value_str(value)) if operation == "=": - return "%s IS NULL" % (cls.to_attr_str(key)) + return "{:s} IS NULL".format(cls.to_attr_str(key)) elif operation == "!=": - return "%s IS NOT NULL" % (cls.to_attr_str(key)) + return "{:s} IS NOT NULL".format(cls.to_attr_str(key)) raise SqlSyntaxError( - "Invalid operation (%s) with None right-hand side" % (operation)) + "Invalid operation ({:s}) with None right-hand side".format( + operation)) @classmethod def make_where_in(cls, key, value_list): @@ -378,7 +380,7 @@ def make_where_in(cls, key, value_list): "key IN ('hoge', 'foo', 'bar')" """ - return "%s IN (%s)" % ( + return "{:s} IN ({:s})".format( cls.to_attr_str(key), ", ".join(cls.to_value_str_list(value_list))) @classmethod @@ -399,5 +401,5 @@ def make_where_not_in(cls, key, value_list): "key NOT IN ('hoge', 'foo', 'bar')" """ - return "%s NOT IN (%s)" % ( + return "{:s} NOT IN ({:s})".format( cls.to_attr_str(key), ", ".join(cls.to_value_str_list(value_list))) From 52d13e94ef8cb0cc12e895a40c6eb408492d058e Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:29:00 +0900 Subject: [PATCH 7/9] Modifications to change string formatting to format method --- docs/make_readme.py | 4 ++-- test/test_simplesqlite.py | 2 +- test/test_sqlquery.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/make_readme.py b/docs/make_readme.py index 225b45f..1477166 100644 --- a/docs/make_readme.py +++ b/docs/make_readme.py @@ -31,7 +31,7 @@ def write_examples(maker): maker.write_chapter("For more information") maker.write_line_list([ "More examples are available at ", - "http://%s.readthedocs.org/en/latest/pages/examples/index.html" % ( + "http://{:s}.readthedocs.org/en/latest/pages/examples/index.html".format( PROJECT_NAME.lower()), ]) @@ -54,7 +54,7 @@ def main(): maker.set_indent_level(0) maker.write_chapter("Documentation") maker.write_line_list([ - "http://%s.readthedocs.org/en/latest/" % (PROJECT_NAME.lower()), + "http://{:s}.readthedocs.org/en/latest/".format(PROJECT_NAME.lower()), ]) maker.write_chapter("Related project") diff --git a/test/test_simplesqlite.py b/test/test_simplesqlite.py index ffd6719..26c6992 100644 --- a/test/test_simplesqlite.py +++ b/test/test_simplesqlite.py @@ -643,7 +643,7 @@ class Test_SimpleSQLite_drop_table: def test_normal(self, con): attr_description_list = [ - "'%s' %s" % ("attr_name", "TEXT") + "'{:s}' {:s}".format("attr_name", "TEXT") ] table_name = "new_table" diff --git a/test/test_sqlquery.py b/test/test_sqlquery.py index d28521a..8f714e0 100644 --- a/test/test_sqlquery.py +++ b/test/test_sqlquery.py @@ -27,9 +27,9 @@ class Test_SqlQuery_sanitize: @pytest.mark.parametrize( ["value", "expected"], [ - ["AAA%s" % (re.escape(c)), "AAA"] for c in SANITIZE_CHAR_LIST + ["AAA{:s}".format(re.escape(c)), "AAA"] for c in SANITIZE_CHAR_LIST ] + [ - ["%sBBB" % (re.escape(c)), "BBB"] for c in SANITIZE_CHAR_LIST + ["{:s}BBB".format(re.escape(c)), "BBB"] for c in SANITIZE_CHAR_LIST ] + [ [ "%a/b(c)d[e]fh.i;j'k!l\\m#n _o-p+q=r\nstrvwxyz" + @@ -87,7 +87,11 @@ class Test_SqlQuery_to_attr_str: ["attr_a", 2, '"attr_a"'], ["attr_a", True, '"attr_a"'], ] + [ - ["te%sst" % (re.escape(c)), None, "[te%sst]" % (re.escape(c))] + [ + "te{:s}st".format(re.escape(c)), + None, + "[te{:s}st]".format(re.escape(c)), + ] for c in string.digits + "%(). -+#" ] ) From 49d0326ebcc24acc07e4277692d8baeec58d0f6d Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:32:13 +0900 Subject: [PATCH 8/9] Remove unnecessary code --- simplesqlite/core.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/simplesqlite/core.py b/simplesqlite/core.py index 34232ed..e24dcfa 100644 --- a/simplesqlite/core.py +++ b/simplesqlite/core.py @@ -222,8 +222,7 @@ def execute_query(self, query, caller=None): try: result = self.connection.execute(query) - except sqlite3.OperationalError: - _, e, _ = sys.exc_info() # for python 2.5 compatibility + except sqlite3.OperationalError as e: if caller is None: caller = logging.getLogger().findCaller() file_path, line_no, func_name = caller[:3] @@ -323,8 +322,7 @@ def insert_many(self, table_name, insert_record_list): try: self.connection.executemany(query, record_list) - except sqlite3.OperationalError: - _, e, _ = sys.exc_info() # for python 2.5 compatibility + except sqlite3.OperationalError as e: caller = logging.getLogger().findCaller() file_path, line_no, func_name = caller[:3] raise sqlite3.OperationalError( From 93a2a8d787c769742daace4e043f34b91b9e830f Mon Sep 17 00:00:00 2001 From: Tsuyoshi Hombashi Date: Thu, 11 Aug 2016 23:33:30 +0900 Subject: [PATCH 9/9] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 37384bd..958caf5 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setuptools.setup( name="SimpleSQLite", - version="0.4.4", + version="0.4.5", url="https://github.com/thombashi/SimpleSQLite", bugtrack_url="https://github.com/thombashi/SimpleSQLite/issues",