(self, cookie, request)
return cookie_str
Given a dict consisting of cookie components, return its string representation.
        Decode from bytes if necessary.
Given a dict consisting of cookie components, return its string representation.
        Decode from bytes if necessary.
Given a dict consisting of cookie components return its string representation . Decode from bytes if necessary .
def _format_cookie(self, cookie, request):
        """
        Given a dict consisting of cookie components, return its string representation.
        Decode from bytes if necessary.
        """
        decoded = {}
        for key in ("name", "value", "path", "domain"):
            if cookie.get(key) is None:
                if key in ("name", "value"):
                    msg = "Invalid cookie found in request {}: {} ('{}' is missing)"
                    logger.warning(msg.format(request, cookie, key))
                    return
                continue
            if isinstance(cookie[key], (bool, float, int, str)):
                decoded[key] = str(cookie[key])
            else:
                try:
                    decoded[key] = cookie[key].decode("utf8")
                except UnicodeDecodeError:
                    logger.warning("Non UTF-8 encoded cookie found in request %s: %s",
                                   request, cookie)
                    decoded[key] = cookie[key].decode("latin1", errors="replace")

        cookie_str = f"{decoded.pop('name')}={decoded.pop('value')}"
        for key, value in decoded.items():  # path, domain
            cookie_str += f"; {key.capitalize()}={value}"
        return cookie_str
def _format_cookie ( self , cookie , request ) : decoded = { } for key in ( "name" , "value" , "path" , "domain" ) : if cookie . get ( key ) is None : if key in ( "name" , "value" ) : msg = "Invalid cookie found in request {}: {} ('{}' is missing)" logger . warning ( msg . format ( request , cookie , key ) ) return continue if isinstance ( cookie [ key ] , ( bool , float , int , str ) ) : decoded [ key ] = str ( cookie [ key ] ) else : try : decoded [ key ] = cookie [ key ] . decode ( "utf8" ) except UnicodeDecodeError : logger . warning ( "Non UTF-8 encoded cookie found in request %s: %s" , request , cookie ) decoded [ key ] = cookie [ key ] . decode ( "latin1" , errors = "replace" ) cookie_str = f"{decoded.pop('name')}={decoded.pop('value')}" for key , value in decoded . items ( ) : # path, domain cookie_str += f"; {key.capitalize()}={value}" return cookie_str