'Validates a single path segment of a URI template.
1. Ensure field names are valid Python identifiers, since they
will be passed as kwargs to responders.
2. Check that there are no duplicate names, since that causes
(at least) the following problems:
a. For simple nodes, values from deeper nodes overwrite
values from more shallow nodes.
b. For complex nodes, re.compile() raises a nasty error
3. Check that when the converter syntax is used, the named
converter exists.'

def _validate_template_segment(self, segment, used_names):

    for field in _FIELD_PATTERN.finditer(segment):
        name = field.group('fname')
        is_identifier = _IDENTIFIER_PATTERN.match(name)
        if ((not is_identifier) or (name in keyword.kwlist)):
            msg_template = 'Field    names    must    be    valid    identifiers    ("{0}"    is    not    valid)'
            msg = msg_template.format(name)
            raise ValueError(msg)
        if (name in used_names):
            msg_template = 'Field    names    may    not    be    duplicated    ("{0}"    was    used    more    than    once)'
            msg = msg_template.format(name)
            raise ValueError(msg)
        used_names.add(name)
        if (field.group('cname_sep') == ':'):
            msg = 'Missing    converter    for    field    "{0}"'.format(name)
            raise ValueError(msg)
        name = field.group('cname')
        if (name and (name not in self._converter_map)):
            msg = 'Unknown    converter:    "{0}"'.format(name)
            raise ValueError(msg)
