changeset 8528:fed0f839c260

fix: replace except: with except Exception: (by haosenwang1018@github) Remove bare 'except:' statements replace with 'except Exception'. In roundup_xmlrpc_server.py I changed Exception to BaseException so the database gets closed on signals as well. The rest of the changes do not look like they affect data integrity and are commited as supplied.
author John Rouillard <rouilj@ieee.org>
date Thu, 26 Feb 2026 09:46:02 -0500
parents d4a43d9da8ef
children a371ef0059d0
files CHANGES.txt frontends/ZRoundup/ZRoundup.py roundup/anypy/vendored/cgi.py roundup/backends/rdbms_common.py roundup/cgi/PageTemplates/PageTemplate.py roundup/cgi/PageTemplates/PythonExpr.py roundup/cgi/TAL/DummyEngine.py roundup/cgi/TAL/TALInterpreter.py roundup/cgi/ZTUtils/Iterator.py roundup/cgi/templating.py roundup/dist/command/build.py roundup/scripts/roundup_xmlrpc_server.py scripts/copy-user.py scripts/imapServer.py scripts/import_sf.py test/test_locking.py tools/load_tracker.py tools/migrate-queries.py
diffstat 18 files changed, 25 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Mon Feb 23 20:16:55 2026 -0500
+++ b/CHANGES.txt	Thu Feb 26 09:46:02 2026 -0500
@@ -45,6 +45,8 @@
   into Client(). (John Rouillard)
 - issue2551393 -  Named searches lose their name in title when next
   page is selected. (John Rouillard)
+- code cleanup replace bare except: with except Exception:. (patch by
+  Sense_wang (haosenwang1018) applied by John Rouillard)
 
 Features:
 
--- a/frontends/ZRoundup/ZRoundup.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/frontends/ZRoundup/ZRoundup.py	Thu Feb 26 09:46:02 2026 -0500
@@ -210,7 +210,7 @@
         except client.NotFound:
             raise Exception('NotFound ' + REQUEST.URL)
             pass
-        except:
+        except Exception:
             import traceback
             traceback.print_exc()
             # all other exceptions in roundup are valid
--- a/roundup/anypy/vendored/cgi.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/anypy/vendored/cgi.py	Thu Feb 26 09:46:02 2026 -0500
@@ -870,7 +870,7 @@
             f()
         print("<H3>What follows is a test, not an actual exception:</H3>")
         g()
-    except:
+    except Exception:
         print_exception()
 
     print("<H1>Second try with a small maxlen...</H1>")
@@ -883,7 +883,7 @@
         print_arguments()
         print_form(form)
         print_environ(environ)
-    except:
+    except Exception:
         print_exception()
 
 def print_exception(type=None, value=None, tb=None, limit=None):
--- a/roundup/backends/rdbms_common.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/backends/rdbms_common.py	Thu Feb 26 09:46:02 2026 -0500
@@ -2612,7 +2612,7 @@
             e.context['class'] = pln
             e.context['attr'] = prp
             raise
-        except:
+        except Exception:
             pass
         # Fallback to original code
         args = []
@@ -2693,7 +2693,7 @@
             e.context['class'] = classname
             e.context['attr'] = proptree.name
             raise
-        except:
+        except Exception:
             # fallback behavior when expression parsing above fails
             orclause = ''
             if '-1' in v:
--- a/roundup/cgi/PageTemplates/PageTemplate.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/PageTemplates/PageTemplate.py	Thu Feb 26 09:46:02 2026 -0500
@@ -106,7 +106,7 @@
         if not self.expand: return
         try:
             self.pt_render(source=1)
-        except:
+        except Exception:
             return ('Macro expansion failed', '%s: %s' % sys.exc_info()[:2])
 
     def pt_warnings(self):
@@ -147,7 +147,7 @@
                 return self._text
             try:
                 return self.pt_render(source=1)
-            except:
+            except Exception:
                 return ('%s\n Macro expansion failed\n %s\n-->\n%s' %
                         (self._error_start, "%s: %s" % sys.exc_info()[:2],
                          self._text) )
@@ -177,7 +177,7 @@
         try:
             parser.parseString(self._text)
             self._v_program, self._v_macros = parser.getCode()
-        except:
+        except Exception:
             self._v_errors = ["Compilation failed",
                               "%s: %s" % sys.exc_info()[:2]]
         self._v_warnings = parser.getWarnings()
--- a/roundup/cgi/PageTemplates/PythonExpr.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/PageTemplates/PythonExpr.py	Thu Feb 26 09:46:02 2026 -0500
@@ -36,7 +36,7 @@
             self.f_code = 'def f():\n return %s\n' % expr.strip()
             exec(self.f_code, d)
             self._f = d['f']
-        except:
+        except Exception:
             raise CompilerError(('Python expression error:\n'
                                  '%s: %s') % exc_info()[:2])
         self._get_used_names()
--- a/roundup/cgi/TAL/DummyEngine.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/TAL/DummyEngine.py	Thu Feb 26 09:46:02 2026 -0500
@@ -118,7 +118,7 @@
         if type == "python":
             try:
                 return eval(expr, self.globals, self.locals)
-            except:
+            except Exception:
                 raise TALESError("evaluation error in %s" % repr(expr))
         if type == "position":
             # Insert the current source file name, line number,
--- a/roundup/cgi/TAL/TALInterpreter.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/TAL/TALInterpreter.py	Thu Feb 26 09:46:02 2026 -0500
@@ -724,7 +724,7 @@
         self._stream_write = stream.write
         try:
             self.interpret(block)
-        except:
+        except Exception:
             exc = sys.exc_info()[1]
             self.restoreState(state)
             engine = self.engine
--- a/roundup/cgi/ZTUtils/Iterator.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/ZTUtils/Iterator.py	Thu Feb 26 09:46:02 2026 -0500
@@ -189,7 +189,7 @@
         try:
             if hasattr(ob, 'next') and (ob is iter(ob)):
                 return 1
-        except:
+        except Exception:
             return 0
 
     def prep_next(self, it):
--- a/roundup/cgi/templating.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/cgi/templating.py	Thu Feb 26 09:46:02 2026 -0500
@@ -2717,7 +2717,7 @@
             # ignore these errors to preserve user input
             try:
                 display_value.sort(key=keyfun)
-            except:
+            except Exception:
                 pass
             self._value = display_value
 
--- a/roundup/dist/command/build.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/dist/command/build.py	Thu Feb 26 09:46:02 2026 -0500
@@ -30,7 +30,7 @@
     manifest_file = 'roundup.egg-info/SOURCES.txt'
     try:
         f=open(manifest_file)
-    except:
+    except Exception:
         print('\n*** SOURCE WARNING: The MANIFEST file "%s" is missing!' % manifest_file)
         return
     try:
--- a/roundup/scripts/roundup_xmlrpc_server.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/roundup/scripts/roundup_xmlrpc_server.py	Thu Feb 26 09:46:02 2026 -0500
@@ -105,7 +105,7 @@
             SimpleXMLRPCRequestHandler.do_POST(self)
         except Unauthorised as message:
             self.send_error(403, '%s (%s)' % (self.path, message))
-        except:
+        except BaseException:
             if db:
                 db.close()
             exc, val, tb = sys.exc_info()
--- a/scripts/copy-user.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/scripts/copy-user.py	Thu Feb 26 09:46:02 2026 -0500
@@ -31,14 +31,14 @@
     try:
         instance1 = roundup.instance.open(home1)
         print("Opened source instance: %s" % home1)
-    except:
+    except Exception:
         print("Can't open source instance: %s" % home1)
         sys.exit(1)
 
     try:
         instance2 = roundup.instance.open(home2)
         print("Opened target instance: %s" % home2)
-    except:
+    except Exception:
         print("Can't open target instance: %s" % home2)
         sys.exit(1)
 
--- a/scripts/imapServer.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/scripts/imapServer.py	Thu Feb 26 09:46:02 2026 -0500
@@ -225,7 +225,7 @@
 
                             # We are done with this mailbox
                             serv.close()
-                    except:
+                    except Exception:
                         log.exception('Exception with server %s user %s',
                             server, user)
                         noErrors = False
@@ -233,7 +233,7 @@
                     serv.logout()
                     serv.shutdown()
                     del serv
-            except:
+            except Exception:
                 log.exception('Exception while connecting to %s', server)
                 noErrors = False
         return noErrors
--- a/scripts/import_sf.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/scripts/import_sf.py	Thu Feb 26 09:46:02 2026 -0500
@@ -299,7 +299,7 @@
                         f = open(os.path.join(file_dir, fid), 'rb')
                         content = f.read()
                         f.close()
-                    except:
+                    except Exception:
                         content = 'content missing'
                     file_data.append({
                         'id': fid,
--- a/test/test_locking.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/test/test_locking.py	Thu Feb 26 09:46:02 2026 -0500
@@ -33,7 +33,7 @@
         f = acquire_lock(self.path)
         try:
             acquire_lock(self.path, block=0)
-        except:
+        except Exception:
             pass
         else:
             raise AssertionError('no exception')
--- a/tools/load_tracker.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/tools/load_tracker.py	Thu Feb 26 09:46:02 2026 -0500
@@ -55,7 +55,7 @@
 try:
     try:
         db.user.lookup('alpha0')
-    except:
+    except Exception:
         # add some users
         M = N//100
         for i in range(M):
--- a/tools/migrate-queries.py	Mon Feb 23 20:16:55 2026 -0500
+++ b/tools/migrate-queries.py	Thu Feb 26 09:46:02 2026 -0500
@@ -22,7 +22,7 @@
     # Do some basic exception handling to catch bad arguments.
     try:
         instance = roundup.instance.open(home)
-    except:
+    except Exception:
         print('Cannot open instance home directory %s!' % home)
         continue
 

Roundup Issue Tracker: http://roundup-tracker.org/