Browse files

MB-5988: python 2.4 compat avoiding except-as idiom

Change-Id: I032ceece24187327e5028f0f3cfea857418279ba
Reviewed-on: http://review.couchbase.org/18738
Reviewed-by: Bin Cui <bin.cui@gmail.com>
Tested-by: Steve Yen <steve.yen@gmail.com>
  • Loading branch information...
1 parent 057c889 commit b4a272bb5fd947d3f8ff9b4e24a531bb30463eb0 @steveyen steveyen committed Jul 23, 2012
Showing with 20 additions and 20 deletions.
  1. +2 −2 pump.py
  2. +11 −11 pump_bfd.py
  3. +1 −1 pump_bson.py
  4. +2 −2 pump_cb.py
  5. +1 −1 pump_csv.py
  6. +3 −3 pump_mbf.py
View
4 pump.py
@@ -807,7 +807,7 @@ def rest_request(host, port, user, pswd, path, method='GET', body='', reason='')
conn = httplib.HTTPConnection(host, port)
try:
conn.request(method, path, body, rest_headers(user, pswd))
- except Exception as e:
+ except Exception, e:
return ("error: could not access REST API: %s:%s%s" +
"; please check source URL, username (-u) and password (-p)" +
"; exception: %s%s") % \
@@ -845,7 +845,7 @@ def rest_request_json(host, port, user, pswd, path, reason=''):
conn.close()
try:
return None, rest_json, json.loads(rest_json)
- except ValueError as e:
+ except ValueError, e:
return ("error: could not decode JSON from REST API: %s:%s%s" +
"; exception: %s" +
"; please check URL, username (-u) and password (-p)") % \
View
22 pump_bfd.py
@@ -108,7 +108,7 @@ def provide_design(opts, source_spec, source_bucket, source_map):
d = f.read()
f.close()
return 0, d
- except IOError as e:
+ except IOError, e:
return ("error: could not read design: %s" +
"; exception: %s") % (fname, e), None
return 0, None
@@ -171,7 +171,7 @@ def provide_batch(self):
return 0, batch
- except Exception as e:
+ except Exception, e:
self.done = True
if self.cursor_db:
self.cursor_db[0].close()
@@ -266,9 +266,9 @@ def run(self):
self.future_done(future, 0) # No return to keep looping.
- except sqlite3.Error as e:
+ except sqlite3.Error, e:
return self.future_done(future, "error: db error: " + str(e))
- except Exception as e:
+ except Exception, e:
return self.future_done(future, "error: db exception: " + str(e))
@staticmethod
@@ -315,7 +315,7 @@ def consume_design(opts, sink_spec, sink_map,
f = open(fname, 'w')
f.write(source_design)
f.close()
- except IOError as e:
+ except IOError, e:
return ("error: could not write design: %s" +
"; exception: %s") % (fname, e), None
return 0
@@ -349,9 +349,9 @@ def create_db(self, num):
cur.execute("INSERT INTO cbb_meta (key, val) VALUES (?, ?)",
("start.datetime", time.strftime("%Y/%m/%d-%H:%M:%S")))
db.commit()
- except sqlite3.Error as e:
+ except sqlite3.Error, e:
return "error: create_db error: " + str(e), None
- except Exception as e:
+ except Exception, e:
return "error: create_db exception: " + str(e), None
return 0, db
@@ -367,14 +367,14 @@ def mkdirs(self):
if not os.path.isdir(spec):
try:
os.mkdir(spec)
- except OSError as e:
+ except OSError, e:
return "error: could not mkdir: %s; exception: %s" % (spec, e)
d = BFD.db_dir(self.spec, self.bucket_name(), self.node_name())
if not os.path.isdir(d):
try:
os.makedirs(d)
- except OSError as e:
+ except OSError, e:
return "error: could not mkdirs: %s; exception: %s" % (d, e)
return 0
@@ -407,7 +407,7 @@ def create_db(db_path, opts):
return 0, db
- except Exception as e:
+ except Exception, e:
return "error: create_db exception: " + str(e), None
def connect_db(db_path, opts, version):
@@ -429,7 +429,7 @@ def connect_db(db_path, opts, version):
return 0, db
- except Exception as e:
+ except Exception, e:
return "error: connect_db exception: " + str(e), None
def cleanse(d):
View
2 pump_bson.py
@@ -42,7 +42,7 @@ def provide_batch(self):
if not self.f:
try:
self.f = open(self.spec.replace(BSON_SCHEME, ""))
- except IOError as e:
+ except IOError, e:
return "error: could not open bson: %s; exception: %s" % \
(self.spec, e), None
View
4 pump_cb.py
@@ -106,7 +106,7 @@ def consume_design(opts, sink_spec, sink_map,
try:
sd = json.loads(source_design)
- except ValueError as e:
+ except ValueError, e:
return "error: could not parse source design; exception: %s" % (e)
if not sd:
return 0
@@ -158,7 +158,7 @@ def consume_design(opts, sink_spec, sink_map,
if err:
return ("error: could not restore design doc id: %s" +
"; response: %s; err: %s") % (id, response, err)
- except Exception as e:
+ except Exception, e:
return ("error: design sink exception: %s" +
"; couch_api_base: %s") % (e, couch_api_base)
View
2 pump_csv.py
@@ -47,7 +47,7 @@ def provide_batch(self):
except StopIteration:
return ("error: could not read 1st line of csv: %s" %
(self.spec)), None
- except IOError as e:
+ except IOError, e:
return ("error: could not open csv: %s; exception: %s" %
(self.spec, e)), None
View
6 pump_mbf.py
@@ -76,7 +76,7 @@ def check(opts, spec):
'state': state,
'checkpoint_id': row[3]
}
- except sqlite3.DatabaseError as e:
+ except sqlite3.DatabaseError, e:
pass # A missing vbucket_states table is expected.
finally:
cur.close()
@@ -100,7 +100,7 @@ def db_file_versions(db_files):
def version(db_file):
try:
return int(MBFSource.run_sql(db_file, "PRAGMA user_version;")[0])
- except sqlite3.DatabaseError as e:
+ except sqlite3.DatabaseError, e:
logging.error("error: could not access user_version from: %s" +
"; exception: %s" +
"; perhaps it is being used by another program" +
@@ -216,7 +216,7 @@ def provide_batch(self):
self.cursor_todo = (db, sql, db_kv_names, None)
break # Close the batch; next pass hits new db_name/kv_name.
- except Exception as e:
+ except Exception, e:
self.cursor_done = True
self.cursor_todo = None
return "error: MBFSource exception: " + str(e), None

0 comments on commit b4a272b

Please sign in to comment.