From e75d2c94f9bd326ebaace635a06599a1be35b024 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 25 Jul 2016 19:05:26 +0300 Subject: [PATCH] Raise Error(message) for Py3 compatibility --- m_lib/flad/flad.py | 4 ++-- m_lib/flad/fladc.py | 4 ++-- m_lib/flad/fladm.py | 4 ++-- m_lib/flad/fladw.py | 18 +++++++++--------- m_lib/hash/MKhash.py | 4 ++-- m_lib/m_shutil.py | 2 +- m_lib/net/ftp/ftpscan.py | 4 ++-- m_lib/net/sms.py | 10 +++++----- m_lib/opdate.py | 4 ++-- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/m_lib/flad/flad.py b/m_lib/flad/flad.py index b2e91c8..cfa6ff6 100644 --- a/m_lib/flad/flad.py +++ b/m_lib/flad/flad.py @@ -40,7 +40,7 @@ class Flad(UserList): if callable(self.check_record_func): return self.check_record_func(self, record) else: - raise TypeError, "non-callable restriction function" + raise TypeError("non-callable restriction function") else: return 1 @@ -105,7 +105,7 @@ class Flad(UserList): # so it is not ready to be checked :( # And, of course, two keys with the same name # cannot be added to dictionary - raise KeyError, "field key \"" + key + "\" already in record" + raise KeyError("field key \"" + key + "\" already in record") record[key] = value diff --git a/m_lib/flad/fladc.py b/m_lib/flad/fladc.py index 6fd2f60..d30aa44 100644 --- a/m_lib/flad/fladc.py +++ b/m_lib/flad/fladc.py @@ -35,7 +35,7 @@ class Flad_Conf(dict): db.load_file(f) if len(db) != 1: - raise error, "incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db)) + raise error("incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db))) self.data = db[0] @@ -45,7 +45,7 @@ class Flad_Conf(dict): db.load_from_file(f) if len(db) != 1: - raise error, "incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db)) + raise error("incorrect number of records in config file `%s'; expected 1, got %d" % (str(f), len(db))) self.data = db[0] diff --git a/m_lib/flad/fladm.py b/m_lib/flad/fladm.py index c0e2886..3705a30 100644 --- a/m_lib/flad/fladm.py +++ b/m_lib/flad/fladm.py @@ -71,11 +71,11 @@ def check_record(data, record): if must_keys and (key in must_keys): del copy_must[copy_must.index(key)] # Remove the key from copied list elif (must_keys and (key not in must_keys) and (other_keys and (key not in other_keys))) or (other_keys and (key not in other_keys)): - raise KeyError, "field key \"" + key + "\" is not in list of allowed keys" + raise KeyError("field key \"" + key + "\" is not in list of allowed keys") if copy_must: # If there is at least one key - it is an error: # not all "must" keys are in record - raise KeyError, "not all \"must\" keys are in record; keys: " + str(copy_must) + raise KeyError("not all \"must\" keys are in record; keys: " + str(copy_must)) return 1 diff --git a/m_lib/flad/fladw.py b/m_lib/flad/fladw.py index 0acc34d..781c472 100644 --- a/m_lib/flad/fladw.py +++ b/m_lib/flad/fladw.py @@ -34,7 +34,7 @@ class Flad_WIni(flad.Flad): if self.first_section: if string.strip(line) != '': - raise error, "non-empty line before 1st section" + raise error("non-empty line before 1st section") elif (string.strip(line) == '') or (string.lstrip(line)[0] == ';') : # Empty line or comment record[0].append(line) @@ -46,7 +46,7 @@ class Flad_WIni(flad.Flad): # so it is not ready to be checked :( # And, of course, two keys with the same name # cannot be added to dictionary - raise KeyError, "field key \"" + key + "\" already in record" + raise KeyError("field key \"" + key + "\" already in record") record[0].append(key) record[1][key] = value @@ -73,7 +73,7 @@ class Flad_WIni(flad.Flad): else: if self.first_section and (string.strip(line) != ''): - raise error, "non-empty line before 1st section" + raise error("non-empty line before 1st section") # else: line had been appended to section in __parse_line() else: # This called after last line of the source file @@ -131,7 +131,7 @@ class Flad_WIni(flad.Flad): def add_section(self, section): rec_no = self.find_section(section) if rec_no >= 0: - raise section_error, "section [%s] already exists" % section + raise section_error("section [%s] already exists" % section) self.append((section, [], {})) @@ -139,7 +139,7 @@ class Flad_WIni(flad.Flad): def del_section(self, section): rec_no = self.find_section(section) if rec_no < 0: - raise section_error, "section [%s] does not exists" % section + raise section_error("section [%s] does not exists" % section) del self[rec_no] @@ -160,11 +160,11 @@ class Flad_WIni(flad.Flad): def get_keyvalue(self, section, key): rec_no = self.find_section(section) if rec_no < 0: - raise section_error, "section [%s] does not exists" % section + raise section_error("section [%s] does not exists" % section) record = self[rec_no] if key not in record[1]: - raise KeyError, "section [%s] does not has `%s' key" % (section, key) + raise KeyError("section [%s] does not has `%s' key" % (section, key)) return record[2][key] @@ -184,11 +184,11 @@ class Flad_WIni(flad.Flad): def del_key(self, section, key): rec_no = self.find_section(section) if rec_no < 0: - raise section_error, "section [%s] does not exists" % section + raise section_error("section [%s] does not exists" % section) record = self[rec_no] if key not in record[1]: - raise KeyError, "section [%s] does not has `%s' key" % (section, key) + raise KeyError("section [%s] does not has `%s' key" % (section, key)) klist = record[1] del klist[klist.index(key)] diff --git a/m_lib/hash/MKhash.py b/m_lib/hash/MKhash.py index 812a14a..d11a701 100644 --- a/m_lib/hash/MKhash.py +++ b/m_lib/hash/MKhash.py @@ -57,7 +57,7 @@ class MKhash: vw = self.vw ix = vw.find(key=key) if ix == -1: - raise KeyError, key + raise KeyError(key) return vw[ix].value def __setitem__(self, key, value): @@ -73,7 +73,7 @@ class MKhash: vw = self.vw ix = vw.find(key=key) if ix == -1: - raise KeyError, key + raise KeyError(key) vw.delete(ix) self._add_tran() diff --git a/m_lib/m_shutil.py b/m_lib/m_shutil.py index 7546b0d..f1034e0 100755 --- a/m_lib/m_shutil.py +++ b/m_lib/m_shutil.py @@ -15,7 +15,7 @@ def mkhier(path): # Python implementation of UNIX' mkdir -p /path/to/dir return # It's Ok to have the directory already created if os.path.exists(path): - raise mkhier_error, "`%s' is file" % path + raise mkhier_error("`%s' is file" % path) list_dirs = string.split(path, os.sep) #print(list_dirs) diff --git a/m_lib/net/ftp/ftpscan.py b/m_lib/net/ftp/ftpscan.py index 469e44b..c3a4b5e 100755 --- a/m_lib/net/ftp/ftpscan.py +++ b/m_lib/net/ftp/ftpscan.py @@ -165,7 +165,7 @@ def ftpscanrecursive(ftp_server, ftp_port=None, login=None, password=None, # The server does not implement LIST -R and # treats -R as a name of a directory (-: ftp.quit() - raise FtpScanError, "the server does not implement recursive listing" + raise FtpScanError("the server does not implement recursive listing") ftp.quit() tree = [] @@ -193,7 +193,7 @@ def ftpscanrecursive(ftp_server, ftp_port=None, login=None, password=None, tree.append((current_dir, files)) if len(tree) == 1: - raise FtpScanError, "the server ignores -R in LIST" + raise FtpScanError("the server ignores -R in LIST") return tree diff --git a/m_lib/net/sms.py b/m_lib/net/sms.py index 9b73390..c3df737 100644 --- a/m_lib/net/sms.py +++ b/m_lib/net/sms.py @@ -249,7 +249,7 @@ class SendmailTransport(EMailTransport): sendmail = self.find_sendmail() if not sendmail: - raise ValueError, "cannot find sendmail binary" + raise ValueError("cannot find sendmail binary") self.sendmail = sendmail def find_sendmail(self): @@ -359,7 +359,7 @@ class BeeOnLine(CP1251HTTPTransport): reply_to=''): # send reply to this e-mail Transport.__init__(self, phone, message) if mode not in ('GSM', 'DAMPS'): - raise ValueError, "mode (%s) must be either 'GSM' or 'DAMPS'" % mode + raise ValueError("mode (%s) must be either 'GSM' or 'DAMPS'" % mode) self.mode = mode self.transliterate = transliterate self.reply_to = reply_to @@ -382,7 +382,7 @@ class BeeOnLine(CP1251HTTPTransport): elif prf == '7901': dict['network_code'] = '1' else: - raise RuntimeError, "incorrect combination of mode (%s) and prefix (%s)" % (self.mode, prf) + raise RuntimeError("incorrect combination of mode (%s) and prefix (%s)" % (self.mode, prf)) dict['phone'] = self.phone[4:] dict['message'] = text @@ -561,9 +561,9 @@ def Phone2Provider(phone): prefix = phone[1:4] if prefix in ("095", "901"): # 901 is being used by Beeline and SkyLink - raise SMSError, "unknown provider for phone %s" % phone + raise SMSError("unknown provider for phone %s" % phone) if Prefix2Provider.has_key(prefix): return Prefix2Provider[prefix] - raise SMSError, "bad prefix for phone %s" % phone + raise SMSError("bad prefix for phone %s" % phone) diff --git a/m_lib/opdate.py b/m_lib/opdate.py index 46b9916..6d23086 100755 --- a/m_lib/opdate.py +++ b/m_lib/opdate.py @@ -75,7 +75,7 @@ def DaysInMonth(Month, Year): return 28+IsLeapYear(_setYear(Year)) else: - raise opdate_error, "bad month `%s'" % str(Month) + raise opdate_error("bad month `%s'" % str(Month)) def ValidDate(Day, Month, Year): @@ -235,7 +235,7 @@ def DateDiff(Date1, Date2): def DayOfWeek(Julian): """ Return the day of the week for the date. Returns DayType(7) if Julian == BadDate. """ if Julian == BadDate: - raise opdate_error, "bad date `%s'" % str(Julian) + raise opdate_error("bad date `%s'" % str(Julian)) else: return (Julian+FirstDayOfWeek) % 7 -- 2.39.5