From 606214eb664b62587d5fe6b2503ee4a48cc192b7 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Fri, 13 Apr 2012 17:10:32 -0400 Subject: [PATCH] * Changing all `isinstance(STUFF, str)' to `isinstance(STUFF, basestring)' for future-proofing this code. --- db/file_db.py | 2 +- db/result_base.py | 2 +- db/tables.py | 2 +- file/file_utils.py | 2 +- iofmt/fortbin.py | 4 ++-- iofmt/text_input.py | 2 +- shell_tools.py | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db/file_db.py b/db/file_db.py index 5db8946..45e47df 100644 --- a/db/file_db.py +++ b/db/file_db.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): diff --git a/db/result_base.py b/db/result_base.py index 1172e06..dd2e413 100644 --- a/db/result_base.py +++ b/db/result_base.py @@ -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) diff --git a/db/tables.py b/db/tables.py index 9f45b72..f0b36f9 100644 --- a/db/tables.py +++ b/db/tables.py @@ -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): diff --git a/file/file_utils.py b/file/file_utils.py index ee7885c..b80ddb4 100644 --- a/file/file_utils.py +++ b/file/file_utils.py @@ -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) diff --git a/iofmt/fortbin.py b/iofmt/fortbin.py index 0e3940d..387fbd7 100644 --- a/iofmt/fortbin.py +++ b/iofmt/fortbin.py @@ -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]) diff --git a/iofmt/text_input.py b/iofmt/text_input.py index c1fd7c2..28ab69c 100644 --- a/iofmt/text_input.py +++ b/iofmt/text_input.py @@ -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 diff --git a/shell_tools.py b/shell_tools.py index c6c3d2f..476f3c3 100644 --- a/shell_tools.py +++ b/shell_tools.py @@ -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: