[Zope-Checkins] CVS: Zope/lib/python/Controller - SchemaHandler.py:1.1.2.3

Fred L. Drake, Jr. fred@zope.com
Fri, 6 Dec 2002 11:08:43 -0500


Update of /cvs-repository/Zope/lib/python/Controller
In directory cvs.zope.org:/tmp/cvs-serv7862

Modified Files:
      Tag: chrism-install-branch
	SchemaHandler.py 
Log Message:
- convert imports to Python Normal Form
- avoid bare except clauses
- reflect changes in the ZConfig package


=== Zope/lib/python/Controller/SchemaHandler.py 1.1.2.2 => 1.1.2.3 ===
--- Zope/lib/python/Controller/SchemaHandler.py:1.1.2.2	Mon Nov 25 02:39:37 2002
+++ Zope/lib/python/Controller/SchemaHandler.py	Fri Dec  6 11:08:41 2002
@@ -1,16 +1,20 @@
+import os
+import socket
+import types
+
+import ZConfig
+import ZODB     # :-( required to import user
+
 from ZConfig import SchemaParser
 from ZConfig.SchemaContext import SchemaContext
-import os
 from zLOG.AccessLogger import AccessLogger
-import ZODB # :-( required to import user
+
 from AccessControl.User import emergency_user
+
 if hasattr(emergency_user, '__null_user__'):
     emergency_user_pw = None
 else:
     emergency_user_pw = emergency_user._getPassword()
-import socket
-from ZConfig.Common import *
-import types
 
 class ZopeContext(SchemaContext):
     def hdl_root(self, zope_home, instance_home, software_home, client_home,
@@ -139,7 +143,7 @@
     def valid_locale(self, value):
         try:
             import locale
-        except:
+        except ImportError:
             msg = (
                 'The locale module could not be imported.\n'
                 'To use localization options, you must ensure\n'
@@ -152,7 +156,7 @@
         try:
             try:
                 locale.setlocale(locale.LC_ALL, value)
-            except:
+            except locale.Error:
                 msg = (
                 'The specified locale "%s" is not supported by your system.\n'
                 'See your operating system documentation for more\n'
@@ -171,7 +175,7 @@
     def valid_int(self, value):
         try:
             value = int(value)
-        except:
+        except ValueError:
             return '%s not a valid integer value' % value
 
     def hdl_int(self, value):
@@ -195,7 +199,7 @@
     def valid_constructor(self, value):
         try:
             klass, arglist = self.parse_constructor(value)
-        except ValueError,e:
+        except ValueError, e:
             msg = str(e)
             return msg
         try:
@@ -223,7 +227,7 @@
     def valid_arglist(self, value):
         try:
             pos, kw = self.get_arglist(value)
-        except:
+        except SyntaxError:
             return 'The arguments for "%s" could not be parsed' % value
 
     def make_instance(self, klass, pos, kw):
@@ -344,9 +348,7 @@
             arg = args.pop(0)
             try:
                 if '=' in arg:
-                    k,v=arg.split('=', 1)
-                    k = k.strip()
-                    v = v.strip()
+                    k, v = [s.strip() for s in arg.split('=', 1)]
                     kw[k] = eval(v)
                 else:
                     arg = arg.strip()
@@ -413,7 +415,7 @@
     def valid_port(self, port):
         try:
             self.hdl_port(port)
-        except ConfigurationError:
+        except ZConfig.ConfigurationError:
             return 'Invalid port %s' % port
 
     def hdl_port(self, port):
@@ -427,15 +429,11 @@
                 a, v = tup
         try:
             v = int(v)
-            if v < 0:
-                raise ConfigurationError, (
-                    'Invalid port %s'% v
-                    )
-        except:
-            raise ConfigurationError,(
-                'Invalid port %s' % v
-                )
-        return (a,v)
+        except ValueError:
+            raise ZConfig.ConfigurationError('Invalid port ' + `v`)
+        if v < 0:
+            raise ZConfig.ConfigurationError('Invalid port ' + `v`)
+        return a, v
 
     def get_dns_resolver(self):
         if not self.config.get('dns_ip_address'):
@@ -529,7 +527,7 @@
         try:
             ip, addr = self.hdl_port(port_or_path)
             return ip, addr
-        except ConfigurationError:
+        except ZConfig.ConfigurationError:
             if not self.valid_dirpath(port_or_path):
                 return port_or_path