def cookie_to_dict(cookie):
    """Return cookie attributes as dict."""
    attrs = (
        'version', 'name', 'value', 'port', 'domain', 'path', 'secure',
        'expires', 'discard', 'comment', 'comment_url', 'rfc2109')
    attr_dict = {}
    for attr in attrs:
        attr_val = getattr(cookie, attr, None)
        if attr_val is not None:
            attr_dict[attr] = attr_val

    attr_dict['rest'] = getattr(cookie, '_rest', {})

    return attr_dict