Source code for fresco.cookie

# Copyright 2015 Oliver Cope
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#     Unless required by applicable law or agreed to in writing, software
#     distributed under the License is distributed on an "AS IS" BASIS,
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.
#
from datetime import datetime, timedelta
from typing import Any
from urllib.parse import quote, unquote











[docs]def format_date(utctimetuple): """ Format a date for inclusion in a Set-Cookie header, eg 'Sun, 06 Nov 1994 08:49:37 GMT'. According to RFC6265, this must be an "rfc1123-date, defined in RFC2616, Section 3.3.1" RFC2616 says in turn: HTTP applications have historically allowed three different formats for the representation of date/time stamps: Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format The first format is preferred as an Internet standard[...] """ return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ( ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")[utctimetuple[6]], utctimetuple[2], ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", )[utctimetuple[1] - 1], utctimetuple[0], utctimetuple[3], utctimetuple[4], utctimetuple[5], )