def parse_labels(labels_str):
    """Parse label keys and values following the Resource spec.

    >>> parse_labels("k=v")
    {'k': 'v'}
    >>> parse_labels("k1=v1, k2=v2")
    {'k1': 'v1', 'k2': 'v2'}
    >>> parse_labels("k1='v1,=z1'")
    {'k1': 'v1,=z1'}
    """
    if not _LABELS_RE.match(labels_str):
        return None
    labels = {}
    for kv in _KV_RE.finditer(labels_str):
        gd = kv.groupdict()
        key = unquote(gd['key'])
        if key in labels:
            logger.warning('Duplicate label key "%s"', key)
        labels[key] = unquote(gd['val'])
    return labels
Parse label keys and values following the Resource spec.

    >>> parse_labels("k=v")
    {'k': 'v'}
    >>> parse_labels("k1=v1, k2=v2")
    {'k1': 'v1', 'k2': 'v2'}
    >>> parse_labels("k1='v1,=z1'")
    {'k1': 'v1,=z1'}