Allow '@' in tag values
authorIustin Pop <iustin@google.com>
Mon, 26 Oct 2009 05:39:49 +0000 (14:39 +0900)
committerIustin Pop <iustin@google.com>
Mon, 26 Oct 2009 09:41:49 +0000 (18:41 +0900)
This allows using an email address (as is) as part of a tag. The main
problem that could arise is when parsing tags from a shell script, but
(AFAIK) '@' is not a special character when used in values (happy to be
corrected if not true).

The patch also moves the re to be compiled at class init time, should
use less resources; in my tests it is fine to use a compiled re from
multiple threads.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/objects.py

index 969901c..41bd713 100644 (file)
@@ -210,9 +210,10 @@ class TaggableObject(ConfigObject):
 
   """
   __slots__ = ConfigObject.__slots__ + ["tags"]
+  VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
 
-  @staticmethod
-  def ValidateTag(tag):
+  @classmethod
+  def ValidateTag(cls, tag):
     """Check if a tag is valid.
 
     If the tag is invalid, an errors.TagError will be raised. The
@@ -226,7 +227,7 @@ class TaggableObject(ConfigObject):
                             constants.MAX_TAG_LEN)
     if not tag:
       raise errors.TagError("Tags cannot be empty")
-    if not re.match("^[\w.+*/:-]+$", tag):
+    if not cls.VALID_TAG_RE.match(tag):
       raise errors.TagError("Tag contains invalid characters")
 
   def GetTags(self):