def get_proto_attr(proto, name):
    """ A more safe access method for protobuf. It checks that the name is ASCII (A defensive safeguard against any
        encoding issues with protobuf: python getattr calls take a string, but protobuf attributes are utf-8), and that
        the protobuf has the field. Note that the HasField checks might break in proto3, but ONNX doesn't use this yet.
    """
    def is_ascii(s):
        try:
            s.encode('ascii')
        except UnicodeEncodeError:
            return False
        else:
            return True

    if not is_ascii(name):
        raise ValueError(
            "Attempted to access non-ASCII property name '{}' on protobuf {} (type {})."
            " Please open an issue".format(name, proto, type(proto)))

    return getattr(proto, name)