Use True/False instead of 1/0 to represent bool values

Slightly more modern, readable, and Pythonic.
This commit is contained in:
Jon Dufresne 2019-03-12 19:46:23 -07:00 committed by Daniele Varrazzo
parent afbbdd18b6
commit 3f890f8bbe
2 changed files with 16 additions and 17 deletions

View File

@ -73,8 +73,8 @@ class DictCursorBase(_cursor):
raise NotImplementedError( raise NotImplementedError(
"DictCursorBase can't be instantiated without a row factory.") "DictCursorBase can't be instantiated without a row factory.")
super(DictCursorBase, self).__init__(*args, **kwargs) super(DictCursorBase, self).__init__(*args, **kwargs)
self._query_executed = 0 self._query_executed = False
self._prefetch = 0 self._prefetch = False
self.row_factory = row_factory self.row_factory = row_factory
def fetchone(self): def fetchone(self):
@ -135,23 +135,23 @@ class DictCursor(DictCursorBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['row_factory'] = DictRow kwargs['row_factory'] = DictRow
super(DictCursor, self).__init__(*args, **kwargs) super(DictCursor, self).__init__(*args, **kwargs)
self._prefetch = 1 self._prefetch = True
def execute(self, query, vars=None): def execute(self, query, vars=None):
self.index = OrderedDict() self.index = OrderedDict()
self._query_executed = 1 self._query_executed = True
return super(DictCursor, self).execute(query, vars) return super(DictCursor, self).execute(query, vars)
def callproc(self, procname, vars=None): def callproc(self, procname, vars=None):
self.index = OrderedDict() self.index = OrderedDict()
self._query_executed = 1 self._query_executed = True
return super(DictCursor, self).callproc(procname, vars) return super(DictCursor, self).callproc(procname, vars)
def _build_index(self): def _build_index(self):
if self._query_executed == 1 and self.description: if self._query_executed and self.description:
for i in range(len(self.description)): for i in range(len(self.description)):
self.index[self.description[i][0]] = i self.index[self.description[i][0]] = i
self._query_executed = 0 self._query_executed = False
class DictRow(list): class DictRow(list):
@ -237,22 +237,21 @@ class RealDictCursor(DictCursorBase):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs['row_factory'] = RealDictRow kwargs['row_factory'] = RealDictRow
super(RealDictCursor, self).__init__(*args, **kwargs) super(RealDictCursor, self).__init__(*args, **kwargs)
self._prefetch = 0
def execute(self, query, vars=None): def execute(self, query, vars=None):
self.column_mapping = [] self.column_mapping = []
self._query_executed = 1 self._query_executed = True
return super(RealDictCursor, self).execute(query, vars) return super(RealDictCursor, self).execute(query, vars)
def callproc(self, procname, vars=None): def callproc(self, procname, vars=None):
self.column_mapping = [] self.column_mapping = []
self._query_executed = 1 self._query_executed = True
return super(RealDictCursor, self).callproc(procname, vars) return super(RealDictCursor, self).callproc(procname, vars)
def _build_index(self): def _build_index(self):
if self._query_executed == 1 and self.description: if self._query_executed and self.description:
self.column_mapping = [d[0] for d in self.description] self.column_mapping = [d[0] for d in self.description]
self._query_executed = 0 self._query_executed = False
class RealDictRow(dict): class RealDictRow(dict):

View File

@ -528,7 +528,7 @@ parser.read('setup.cfg')
# Choose a datetime module # Choose a datetime module
have_pydatetime = True have_pydatetime = True
have_mxdatetime = False have_mxdatetime = False
use_pydatetime = int(parser.get('build_ext', 'use_pydatetime')) use_pydatetime = parser.getboolean('build_ext', 'use_pydatetime')
# check for mx package # check for mx package
mxincludedir = '' mxincludedir = ''
@ -576,14 +576,14 @@ else:
define_macros.append(('PSYCOPG_VERSION', PSYCOPG_VERSION_EX)) define_macros.append(('PSYCOPG_VERSION', PSYCOPG_VERSION_EX))
if parser.has_option('build_ext', 'have_ssl'): if parser.has_option('build_ext', 'have_ssl'):
have_ssl = int(parser.get('build_ext', 'have_ssl')) have_ssl = parser.getboolean('build_ext', 'have_ssl')
else: else:
have_ssl = 0 have_ssl = False
if parser.has_option('build_ext', 'static_libpq'): if parser.has_option('build_ext', 'static_libpq'):
static_libpq = int(parser.get('build_ext', 'static_libpq')) static_libpq = parser.getboolean('build_ext', 'static_libpq')
else: else:
static_libpq = 0 static_libpq = False
# And now... explicitly add the defines from the .cfg files. # And now... explicitly add the defines from the .cfg files.
# Looks like setuptools or some other cog doesn't add them to the command line # Looks like setuptools or some other cog doesn't add them to the command line