]> git.phdru.name Git - bookmarks_db.git/commitdiff
Feat(Python3): `raise Error, value` -> `raise Error(value)`
authorOleg Broytman <phd@phdru.name>
Sat, 13 May 2017 16:20:21 +0000 (19:20 +0300)
committerOleg Broytman <phd@phdru.name>
Sat, 13 May 2017 16:39:59 +0000 (19:39 +0300)
Robots/bkmk_rurllib.py
Storage/bkmk_stflad.py
bkmk_parser.py
db2bkmk.py
set-title-list.py
subproc.py

index e0d5c2cba9cfdfae19d56a72057da8cd3c0867f5..b41722fade3af41f245429e11689c3ffae55bb58 100644 (file)
@@ -5,7 +5,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['robot_urllib']
 __license__ = "GNU GPL"
 
 __all__ = ['robot_urllib']
@@ -42,13 +42,13 @@ class MyURLopener(urllib.URLopener):
 
    # Error 401 -- authentication required
    def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): 
 
    # Error 401 -- authentication required
    def http_error_401(self, url, fp, errcode, errmsg, headers, data=None): 
-      raise IOError, ('http error', errcode, "Authentication required ", headers)
+      raise IOError(('http error', errcode, "Authentication required ", headers))
 
    def http_error_default(self, url, fp, errcode, errmsg, headers):
       if fp:
          void = fp.read()
          fp.close()
 
    def http_error_default(self, url, fp, errcode, errmsg, headers):
       if fp:
          void = fp.read()
          fp.close()
-      raise IOError, ('http error', errcode, errmsg, headers)
+      raise IOError(('http error', errcode, errmsg, headers))
 
 
 urllib._urlopener = MyURLopener()
 
 
 urllib._urlopener = MyURLopener()
index 5b72b850d94208c6dfc4e060cf02bbb26cd06248..b936c4a723b5485295ace7ed958706d23fabaa84 100644 (file)
@@ -6,7 +6,7 @@ This file is a part of Bookmarks database and Internet robot.
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
 """
 
 __author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2000-2012 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
 __license__ = "GNU GPL"
 
 __all__ = ['storage_flad']
 __license__ = "GNU GPL"
 
 __all__ = ['storage_flad']
@@ -102,11 +102,11 @@ Charset: %s
             pass
          elif level == save_level + 1:
             if not got_folder:
             pass
          elif level == save_level + 1:
             if not got_folder:
-               raise ValueError, "indent without folder"
+               raise ValueError("indent without folder")
          elif level <= save_level - 1:
             self.unindent(save_level, level)
          else:
          elif level <= save_level - 1:
             self.unindent(save_level, level)
          else:
-            raise ValueError, "new level (%d) too big; must be %d - %d" % (level, save_level-1, save_level+1)
+            raise ValueError("new level (%d) too big; must be %d - %d" % (level, save_level-1, save_level+1))
 
          save_level = level
          got_folder = record.has_key("Folder") # Test here to save got_folder for next loop
 
          save_level = level
          got_folder = record.has_key("Folder") # Test here to save got_folder for next loop
@@ -130,11 +130,11 @@ Charset: %s
             self.current_folder.append(Ruler())
 
          else:
             self.current_folder.append(Ruler())
 
          else:
-            raise KeyError, "neither \"URL\" nor \"Folder\" nor \"Ruler\" in record " + str(record)
+            raise KeyError("neither \"URL\" nor \"Folder\" nor \"Ruler\" in record " + str(record))
 
       if save_level >= 0:
          self.unindent(save_level, 0)
       else:
 
       if save_level >= 0:
          self.unindent(save_level, 0)
       else:
-         raise ValueError, "new level (%d) too little - must be >= 0" % save_level
+         raise ValueError("new level (%d) too little - must be >= 0" % save_level)
 
       return root_folder
 
       return root_folder
index 7430c08044fb6abfbc11e275f78a05076e42d597..8f44f47f13bd1459a0f910dfbfd517e997ba6f46 100644 (file)
@@ -198,7 +198,7 @@ class BkmkParser(HTMLParser):
    def close(self):
       HTMLParser.close(self)
       if self.folder_stack:
    def close(self):
       HTMLParser.close(self)
       if self.folder_stack:
-         raise ValueError, "wrong folder stack: %s" % self.folder_stack
+         raise ValueError("wrong folder stack: %s" % self.folder_stack)
 
    def do_dd(self, attrs):
       pass
 
    def do_dd(self, attrs):
       pass
index 14b02e4b71cf3e96946662341ab13fb33d1b1282..28ebc76959e5fb6d470e4a1d3fb92be1fee4a7bf 100755 (executable)
@@ -77,7 +77,7 @@ def run():
          for record in transl_db:
             transl_d[record["URL2"]] = record["URL1"]
       else:
          for record in transl_db:
             transl_d[record["URL2"]] = record["URL1"]
       else:
-         raise ValueError, "transl (%d) must be 1 or 2" % transl
+         raise ValueError("transl (%d) must be 1 or 2" % transl)
 
       del transl_db # Save few bytes of memory
 
 
       del transl_db # Save few bytes of memory
 
index eb327d62b41b164b4fdfd57219e2dd8e668d976c..bd0da40c897660bb918c7e27bc670a3eeb5d835f 100755 (executable)
@@ -50,12 +50,12 @@ def run():
          title = line
 
       elif line: # the third line in every 3 lines must be empty
          title = line
 
       elif line: # the third line in every 3 lines must be empty
-         raise ValueError, "line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line)
+         raise ValueError("line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line))
 
       else: # We've got 3 lines - add new entry to the mapping
          if titles_dict.has_key(URL):
             if title <> titles_dict[URL]:
 
       else: # We've got 3 lines - add new entry to the mapping
          if titles_dict.has_key(URL):
             if title <> titles_dict[URL]:
-               raise ValueError, "titles are not identical for URL `%s': `%s' <> `%s'" % (URL, title, titles_dict[URL])
+               raise ValueError("titles are not identical for URL `%s': `%s' <> `%s'" % (URL, title, titles_dict[URL]))
 
          else:
             titles_dict[URL] = title
 
          else:
             titles_dict[URL] = title
index f5e89c5ffc75c003e22b8335ea4bdb9d9d39d9c9..a0099c290db088a168181802ee91153ac2b920c9 100644 (file)
@@ -135,22 +135,20 @@ class Subprocess:
                 pid, err = os.waitpid(self.pid, os.WNOHANG)
             except os.error, (errno, msg):
                 if errno == 10:
                 pid, err = os.waitpid(self.pid, os.WNOHANG)
             except os.error, (errno, msg):
                 if errno == 10:
-                    raise SubprocessError, \
-                          "Subprocess '%s' failed." % self.cmd
-                raise SubprocessError, \
-                      "Subprocess failed[%d]: %s" % (errno, msg)
+                    raise SubprocessError("Subprocess '%s' failed." % self.cmd)
+                raise SubprocessError("Subprocess failed[%d]: %s" % (errno, msg))
             if pid == self.pid:
                 # child exited already
                 self.pid == None
                 sig = err & 0xff
                 rc = (err & 0xff00) >> 8
                 if sig:
             if pid == self.pid:
                 # child exited already
                 self.pid == None
                 sig = err & 0xff
                 rc = (err & 0xff00) >> 8
                 if sig:
-                    raise SubprocessError(
+                    raise SubprocessError(
                     "child killed by signal %d with a return code of %d"
                     % (sig, rc))
                 if rc:
                     "child killed by signal %d with a return code of %d"
                     % (sig, rc))
                 if rc:
-                    raise SubprocessError, \
-                          "child exited with return code %d" % rc
+                    raise SubprocessError(
+                          "child exited with return code %d" % rc)
                 # Child may have exited, but not in error, so we won't say
                 # anything more at this point.
 
                 # Child may have exited, but not in error, so we won't say
                 # anything more at this point.
 
@@ -160,13 +158,13 @@ class Subprocess:
         """Write a STRING to the subprocess."""
 
         if not self.pid:
         """Write a STRING to the subprocess."""
 
         if not self.pid:
-            raise SubprocessError, "no child"                           # ===>
+            raise SubprocessError("no child")                           # ===>
         if select.select([],self.toChild_fdlist,[],0)[1]:
             self.toChild.write(str)
             self.toChild.flush()
         else:
             # XXX Can write-buffer full be handled better??
         if select.select([],self.toChild_fdlist,[],0)[1]:
             self.toChild.write(str)
             self.toChild.flush()
         else:
             # XXX Can write-buffer full be handled better??
-            raise IOError, "write to %s blocked" % self                 # ===>
+            raise IOError("write to %s blocked" % self)                 # ===>
 
     def writeline(self, line=''):
         """Write STRING, with added newline termination, to subprocess."""
 
     def writeline(self, line=''):
         """Write STRING, with added newline termination, to subprocess."""
@@ -217,7 +215,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readPendingChars()
         else:
         if self.control_stderr:
             return self.errbuf.readPendingChars()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     def readPendingLine(self):
         """Read currently pending subprocess output, up to a complete line
 
     def readPendingLine(self):
         """Read currently pending subprocess output, up to a complete line
@@ -229,7 +227,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readPendingLine()
         else:
         if self.control_stderr:
             return self.errbuf.readPendingLine()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     def readline(self):
         """Return next complete line of subprocess output, blocking until
 
     def readline(self):
         """Return next complete line of subprocess output, blocking until
@@ -241,7 +239,7 @@ class Subprocess:
         if self.control_stderr:
             return self.errbuf.readline()
         else:
         if self.control_stderr:
             return self.errbuf.readline()
         else:
-            raise SubprocessError, "Haven't grabbed subprocess error stream."
+            raise SubprocessError("Haven't grabbed subprocess error stream.")
 
     ### Subprocess Control ###
 
 
     ### Subprocess Control ###
 
@@ -297,9 +295,9 @@ class Subprocess:
         SubprocessError is raised if process is not successfully killed."""
 
         if not self.pid:
         SubprocessError is raised if process is not successfully killed."""
 
         if not self.pid:
-            raise SubprocessError, "No process"                         # ===>
+            raise SubprocessError("No process")                         # ===>
         elif not self.cont():
         elif not self.cont():
-            raise SubprocessError, "Can't signal subproc %s" % self     # ===>
+            raise SubprocessError("Can't signal subproc %s" % self)     # ===>
 
         # Try sending first a TERM and then a KILL signal.
         keep_trying = 1
 
         # Try sending first a TERM and then a KILL signal.
         keep_trying = 1
@@ -324,9 +322,9 @@ class Subprocess:
                     return None                                         # ===>
                 time.sleep(.1)
         # Only got here if subprocess is not gone:
                     return None                                         # ===>
                 time.sleep(.1)
         # Only got here if subprocess is not gone:
-        raise (SubprocessError,
-               ("Failed kill of subproc %d, '%s', with signals %s" %
-                (self.pid, self.cmd, map(lambda(x): x[0], sigs))))
+        raise SubprocessError(
+               "Failed kill of subproc %d, '%s', with signals %s" %
+                (self.pid, self.cmd, map(lambda(x): x[0], sigs)))
 
     def __del__(self):
         """Terminate the subprocess"""
 
     def __del__(self):
         """Terminate the subprocess"""
@@ -508,8 +506,8 @@ class RecordFile:
             try:
                 l = string.atoi(line)
             except ValueError:
             try:
                 l = string.atoi(line)
             except ValueError:
-                raise IOError("corrupt %s file structure"
-                                % self.__class__.__name__)
+                raise IOError(("corrupt %s file structure"
+                                % self.__class__.__name__))
             return f.read(l)
         else:
             # EOF.
             return f.read(l)
         else:
             # EOF.
@@ -521,7 +519,7 @@ class RecordFile:
         if hasattr(f, attr):
             return getattr(f, attr)
         else:
         if hasattr(f, attr):
             return getattr(f, attr)
         else:
-            raise AttributeError, attr
+            raise AttributeError(attr)
 
     def __repr__(self):
         return "<%s of %s at %s>" % (self.__class__.__name__,
 
     def __repr__(self):
         return "<%s of %s at %s>" % (self.__class__.__name__,
@@ -540,7 +538,7 @@ def record_trial(s):
     r = c.read()
     show = " start:\t %s\n end:\t %s\n" % (`s`, `r`)
     if r != s:
     r = c.read()
     show = " start:\t %s\n end:\t %s\n" % (`s`, `r`)
     if r != s:
-        raise IOError, "String distorted:\n%s" % show
+        raise IOError("String distorted:\n%s" % show)
 
 #############################################################################
 #####                   An example subprocess interfaces                #####
 
 #############################################################################
 #####                   An example subprocess interfaces                #####
@@ -562,7 +560,7 @@ class Ph:
         try:
             self.proc = Subprocess('ph', 1)
         except:
         try:
             self.proc = Subprocess('ph', 1)
         except:
-            raise SubprocessError('failure starting ph: %s' %         # ===>
+            raise SubprocessError('failure starting ph: %s' %         # ===>
                                     str(sys.exc_value))
 
     def query(self, q):
                                     str(sys.exc_value))
 
     def query(self, q):
@@ -585,7 +583,7 @@ class Ph:
             if not response:
                 return got                                              # ===>
             elif type(response) == types.StringType:
             if not response:
                 return got                                              # ===>
             elif type(response) == types.StringType:
-                raise ValueError, "ph failed match: '%s'" % response    # ===>
+                raise ValueError("ph failed match: '%s'" % response)    # ===>
             for line in response:
                 # convert to a dict:
                 line = string.splitfields(line, ':')
             for line in response:
                 # convert to a dict:
                 line = string.splitfields(line, ':')
@@ -603,7 +601,7 @@ class Ph:
 
         nextChar = self.proc.waitForPendingChar(60)
         if not nextChar:
 
         nextChar = self.proc.waitForPendingChar(60)
         if not nextChar:
-            raise SubprocessError, 'ph subprocess not responding'       # ===>
+            raise SubprocessError('ph subprocess not responding')       # ===>
         elif nextChar == '-':
             # dashed line - discard it, and continue reading:
             self.proc.readline()
         elif nextChar == '-':
             # dashed line - discard it, and continue reading:
             self.proc.readline()
@@ -636,7 +634,7 @@ class Ph:
             got = string.splitfields(got, '\n')[-1]
             if got == 'ph> ': return    # Ok.                             ===>
             time.sleep(pause)
             got = string.splitfields(got, '\n')[-1]
             if got == 'ph> ': return    # Ok.                             ===>
             time.sleep(pause)
-        raise SubprocessError('ph not responding within %s secs' %
+        raise SubprocessError('ph not responding within %s secs' %
                                 pause * maxIter)
 
 #############################################################################
                                 pause * maxIter)
 
 #############################################################################