def validate_key(k):
    """Validate a key as received on a stream.
    """
    typ = type(k)
    if typ is not str and typ is not bytes:
        raise TypeError('Unexpected key type %s (value: %r)' % (typ, k))
