]> git.phdru.name Git - m_lib.git/blobdiff - m_lib/flad/fladw.py
Fix exceptions for Py3 compatibility
[m_lib.git] / m_lib / flad / fladw.py
index 0acc34de0c7530697841b442dd08e6d37d96ee12..5901925db43eadca8e2628f958096b2fda2ec24a 100644 (file)
@@ -3,12 +3,16 @@
 """
 
 
-import string, re
-import flad
+import re
+from m_lib.flad import flad
 
 
-error = "fladw.error"
-section_error = "fladw.section_error"
+from .flad import checking_error
+class error(checking_error):
+    pass
+
+class section_error(checking_error):
+    pass
 
 
 re_section = re.compile("^ *\[(.+)\] *$")
@@ -33,10 +37,10 @@ class Flad_WIni(flad.Flad):
          return match.group(1) # Signal to stop filling the record (section) and start a new one
 
       if self.first_section:
-         if string.strip(line) != '':
-            raise error, "non-empty line before 1st section"
+         if line.strip() != '':
+            raise error("non-empty line before 1st section")
 
-      elif (string.strip(line) == '') or (string.lstrip(line)[0] == ';') : # Empty line or comment
+      elif (line.strip() == '') or (line.lstrip()[0] == ';') : # Empty line or comment
          record[0].append(line)
 
       else:
@@ -46,7 +50,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
@@ -72,8 +76,8 @@ class Flad_WIni(flad.Flad):
                self.section = section
 
          else:
-            if self.first_section and (string.strip(line) != ''):
-               raise error, "non-empty line before 1st section"
+            if self.first_section and (line.strip() != ''):
+               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
@@ -85,7 +89,7 @@ class Flad_WIni(flad.Flad):
             klist = record[1]
             if klist:
                l = len(klist) - 1
-               if string.strip(klist[l]) == '':
+               if klist[l].strip() == '':
                   del klist[l]
 
       return 0
@@ -110,7 +114,7 @@ class Flad_WIni(flad.Flad):
 
          if record[1]:
             for key in record[1]:
-               if string.strip(key) == '' or string.lstrip(key)[0] == ';' :
+               if key.strip() == '' or key.lstrip()[0] == ';' :
                   outfile.write(key)
                else:
                   outfile.write(key + self.key_sep + record[2][key] + '\n')
@@ -131,7 +135,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 +143,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 +164,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 +188,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)]