[et-mgmt-tools] [PATCH]: give a sensible diagnostic for an empty name

Jim Meyering jim at meyering.net
Fri Feb 23 13:47:37 UTC 2007


Hi Dan,

I noticed that get_name doesn't diagnose an empty name properly.
Instead, it says it must not be numeric only.

	Give a sensible diagnostic for an empty name.
	Even though the code now detects an empty name early, don't let
	subsequent tests for digit-only and non-alphanumeric names match
	on an empty name.

diff -r 982e9920511c -r c97207424b57 virtinst/Guest.py
--- a/virtinst/Guest.py	Wed Feb 21 11:42:53 2007 -0500
+++ b/virtinst/Guest.py	Fri Feb 23 14:42:50 2007 +0100
@@ -243,9 +243,11 @@ class Guest(object):
     def get_name(self):
         return self._name
     def set_name(self, val):
-        if re.match("^[0-9]*$", val):
+        if len(val) == 0:
+            raise ValueError, "Domain name must be nonempty"
+        if re.match("^[0-9]+$", val):
             raise ValueError, "Domain name must not be numeric only"
-        if re.match("^[a-zA-Z0-9_]*$", val) == None:
+        if re.match("^[a-zA-Z0-9_]+$", val) == None:
             raise ValueError, "Domain name must be alphanumeric or _"
         if len(val) > 50:
             raise ValueError, "Domain name must be less than 50 characters"




More information about the et-mgmt-tools mailing list