def from_dict(cls, cookie_dict, ignore_bad_attributes=True):
        """Construct an instance from a dict of strings to parse.

        The main difference between this and Cookie(name, value, **kwargs) is
        that the values in the argument to this method are parsed.

        If ignore_bad_attributes=True (default), values which did not parse
        are set to '' in order to avoid passing bad data.
        """
        name = cookie_dict.get('name', None)
        if not name:
            raise InvalidCookieError("Cookie must have name")
        raw_value = cookie_dict.get('value', '')
        # Absence or failure of parser here is fatal; errors in present name
        # and value should be found by Cookie.__init__.
        value = cls.attribute_parsers['value'](raw_value)
        cookie = cls(name, value)

        # Parse values from serialized formats into objects
        parsed = {}
        for key, value in cookie_dict.items():
            # Don't want to pass name/value to _set_attributes
            if key in ('name', 'value'):
                continue
            parser = cls.attribute_parsers.get(key)
            if not parser:
                # Don't let totally unknown attributes pass silently
                if not ignore_bad_attributes:
                    raise InvalidCookieAttributeError(
                        key, value, "unknown cookie attribute '%s'" % key)
                _report_unknown_attribute(key)
                continue
            try:
                parsed_value = parser(value)
            except Exception as e:
                reason = "did not parse with %r: %r" % (parser, e)
                if not ignore_bad_attributes:
                    raise InvalidCookieAttributeError(
                        key, value, reason)
                _report_invalid_attribute(key, value, reason)
                parsed_value = ''
            parsed[key] = parsed_value

        # Set the parsed objects (does object validation automatically)
        cookie._set_attributes(parsed, ignore_bad_attributes)
        return cookie
def from_dict ( cls , cookie_dict , ignore_bad_attributes = True ) : name = cookie_dict . get ( 'name' , None ) if not name : raise InvalidCookieError ( "Cookie must have name" ) raw_value = cookie_dict . get ( 'value' , '' ) value = cls . attribute_parsers [ 'value' ] ( raw_value ) cookie = cls ( name , value ) parsed = { } for key , value in cookie_dict . items ( ) : if key in ( 'name' , 'value' ) : continue parser = cls . attribute_parsers . get ( key ) if not parser : if not ignore_bad_attributes : raise InvalidCookieAttributeError ( key , value , "unknown cookie attribute '%s'" % key ) _report_unknown_attribute ( key ) continue try : parsed_value = parser ( value ) except Exception as e : reason = "did not parse with %r: %r" % ( parser , e ) if not ignore_bad_attributes : raise InvalidCookieAttributeError ( key , value , reason ) _report_invalid_attribute ( key , value , reason ) parsed_value = '' parsed [ key ] = parsed_value cookie . _set_attributes ( parsed , ignore_bad_attributes ) return cookie
Construct an instance from a dict of strings to parse.

        The main difference between this and Cookie(name, value, **kwargs) is
        that the values in the argument to this method are parsed.

        If ignore_bad_attributes=True (default), values which did not parse
        are set to '' in order to avoid passing bad data.