Skip to content

Commit

Permalink
Use True/False instead of 1/0 to represent bool values
Browse files Browse the repository at this point in the history
Slightly more modern, readable, and Pythonic.
  • Loading branch information
jdufresne authored and dvarrazzo committed Mar 13, 2019
1 parent afbbdd1 commit 3f890f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
23 changes: 11 additions & 12 deletions lib/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def __init__(self, *args, **kwargs):
raise NotImplementedError(
"DictCursorBase can't be instantiated without a row factory.")
super(DictCursorBase, self).__init__(*args, **kwargs)
self._query_executed = 0
self._prefetch = 0
self._query_executed = False
self._prefetch = False
self.row_factory = row_factory

def fetchone(self):
Expand Down Expand Up @@ -135,23 +135,23 @@ class DictCursor(DictCursorBase):
def __init__(self, *args, **kwargs):
kwargs['row_factory'] = DictRow
super(DictCursor, self).__init__(*args, **kwargs)
self._prefetch = 1
self._prefetch = True

def execute(self, query, vars=None):
self.index = OrderedDict()
self._query_executed = 1
self._query_executed = True
return super(DictCursor, self).execute(query, vars)

def callproc(self, procname, vars=None):
self.index = OrderedDict()
self._query_executed = 1
self._query_executed = True
return super(DictCursor, self).callproc(procname, vars)

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)):
self.index[self.description[i][0]] = i
self._query_executed = 0
self._query_executed = False


class DictRow(list):
Expand Down Expand Up @@ -237,22 +237,21 @@ class RealDictCursor(DictCursorBase):
def __init__(self, *args, **kwargs):
kwargs['row_factory'] = RealDictRow
super(RealDictCursor, self).__init__(*args, **kwargs)
self._prefetch = 0

def execute(self, query, vars=None):
self.column_mapping = []
self._query_executed = 1
self._query_executed = True
return super(RealDictCursor, self).execute(query, vars)

def callproc(self, procname, vars=None):
self.column_mapping = []
self._query_executed = 1
self._query_executed = True
return super(RealDictCursor, self).callproc(procname, vars)

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._query_executed = 0
self._query_executed = False


class RealDictRow(dict):
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def is_py_64():
# Choose a datetime module
have_pydatetime = True
have_mxdatetime = False
use_pydatetime = int(parser.get('build_ext', 'use_pydatetime'))
use_pydatetime = parser.getboolean('build_ext', 'use_pydatetime')

# check for mx package
mxincludedir = ''
Expand Down Expand Up @@ -576,14 +576,14 @@ def is_py_64():
define_macros.append(('PSYCOPG_VERSION', PSYCOPG_VERSION_EX))

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:
have_ssl = 0
have_ssl = False

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:
static_libpq = 0
static_libpq = False

# 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
Expand Down

0 comments on commit 3f890f8

Please sign in to comment.