'Append a key-value pairs of dictionary to self._keyval_container in
TAP format. Once finished write out the keyval.tap file to the file
system.
If type_tag is None, then the key must be composed of alphanumeric
characters (or dashes + underscores). However, if type-tag is not
null then the keys must also have "{type_tag}" as a suffix. At
the moment the only valid values of type_tag are "attr" and "perf".
:param path: The full path of the keyval.tap file to be created
:param dictionary: The keys and values.
:param type_tag: The type of the values'

def record_keyval(self, path, dictionary, type_tag=None):

    self._keyval_container.setdefault(path, [0, []])
    self._keyval_container[path][0] += 1
    if (type_tag is None):
        key_regex = re.compile('^[-\\.\\w]+$')
    else:
        if (type_tag not in ('attr', 'perf')):
            raise ValueError(('Invalid    type    tag:    %s' % type_tag))
        escaped_tag = re.escape(type_tag)
        key_regex = re.compile(('^[-\\.\\w]+\\{%s\\}$' % escaped_tag))
    self._keyval_container[path][1].extend([self.tap_ok(True, self._keyval_container[path][0], 'results'), '\n        ---\n'])
    try:
        for key in sorted(dictionary.keys()):
            if (not key_regex.search(key)):
                raise ValueError(('Invalid    key:    %s' % key))
            self._keyval_container[path][1].append(('        %s:    %s\n' % (key.replace('{', '_').rstrip('}'), dictionary[key])))
    finally:
        self._keyval_container[path][1].append('        ...\n')
    self._write_keyval()
