* Changing all `isinstance(STUFF, str)' to `isinstance(STUFF, basestring)'

for future-proofing this code.
master
Wirawan Purwanto 13 years ago
parent 6656d3d5e3
commit 606214eb66
  1. 2
      db/file_db.py
  2. 2
      db/result_base.py
  3. 2
      db/tables.py
  4. 2
      file/file_utils.py
  5. 4
      iofmt/fortbin.py
  6. 2
      iofmt/text_input.py
  7. 4
      shell_tools.py

@ -48,7 +48,7 @@ class file_table(object):
def __init__(self, src_name, table_name='filedb', extra_fields=[]):
self.src_name = src_name
self.table_name = table_name
if isinstance(src_name, str): # os.path.isfile(src_name):
if isinstance(src_name, basestring): # os.path.isfile(src_name):
self.db = sqlite3.connect(src_name)
self.dbc = self.db.cursor()
elif isinstance(src_name, sqlite3.Connection):

@ -62,7 +62,7 @@ class result_base(dict):
if isinstance(src, dict):
self.clear()
self.update(src)
elif isinstance(src, str):
elif isinstance(src, basestring):
# WARNING: Awaiting future definition of parse_text_file_().
# This must be specified in the derived class.
self.parse_file_(src)

@ -37,7 +37,7 @@ class simple_table(object):
def __init__(self, src_name, table_name, dtypes=None):
self.src_name = src_name
self.table_name = table_name
if isinstance(src_name, str): # os.path.isfile(src_name):
if isinstance(src_name, basestring): # os.path.isfile(src_name):
self.db = sqlite3.connect(src_name)
self.dbc = self.db.cursor()
elif isinstance(src_name, sqlite3.Connection):

@ -86,7 +86,7 @@ def glob_files(filespec):
When globbing is done, the result is sorted for predictability.'''
if getattr(filespec, "__iter__", False):
return filespec # no re-sorting
elif isinstance(filespec, str):
elif isinstance(filespec, basestring):
return sorted(glob.glob(filespec))
else:
raise ValueError, "Don't know how to glob for an object of " + type(filespec)

@ -159,7 +159,7 @@ class fortran_bin_file(object):
v2 = self.default_float(v)
# FIXME: check for overflow error like in integer conversion above
vals.append(v2)
elif isinstance(v, str):
elif isinstance(v, basestring):
v2 = self.default_str(v)
vals.append(v2)
elif "itemsize" in dir(v):
@ -199,7 +199,7 @@ class fortran_bin_file(object):
vals = []
for f in fields:
if isinstance(f, str):
if isinstance(f, basestring):
vals.append(getval(src, f))
elif isinstance(f, (list, tuple)):
v = getval(src, f[0])

@ -119,7 +119,7 @@ class text_input(object):
regular expression object.'''
if regex:
if isinstance(regex, str):
if isinstance(regex, basestring):
Regexp = re.compile(regex)
else:
Regexp = regex

@ -186,7 +186,7 @@ else:
This is my customary shortcut for backtick operator.
The result is either a single string (if split==False) or a list of strings
with EOLs removed (if split==True)."""
if shell or isinstance(args, str):
if shell or isinstance(args, basestring):
# BEWARE: args should be a string in this case
p = os.popen(args, "r")
else:
@ -203,7 +203,7 @@ else:
"""Executes a shell command, piping in the stdin from python for driving.
This is the reverse of pipe_out.
Commands are given through file-like write() or writelines() methods."""
if shell or isinstance(args, str):
if shell or isinstance(args, basestring):
# BEWARE: args should be a string in this case
p = os.popen(args, "w")
else:

Loading…
Cancel
Save