~ahasenack/landscape-client/landscape-client-11.02-0ubuntu0.8.04.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re

_tag_check = re.compile("^\w+[\w-]*$", re.UNICODE)

def is_valid_tag(tagname):
    """Return True if the tag meets our tag requirements."""
    return _tag_check.match(tagname)


def is_valid_tag_list(tag_list):
    """Validate a tag_list string.

    @param tag_list: string like london, server which will be split on the
    commas and each tag verified for validity.
    """
    if tag_list:
        tags = [tag.strip() for tag in tag_list.split(",")]
        for tag in tags:
            if not is_valid_tag(tag):
                return False
    return True