Revision 93c6900c snf-django-lib/snf_django/lib/api/parsedate.py
b/snf-django-lib/snf_django/lib/api/parsedate.py | ||
---|---|---|
1 | 1 |
# Copyright (c) Django Software Foundation and individual contributors. |
2 | 2 |
# All rights reserved. |
3 |
#
|
|
4 |
# Redistribution and use in source and binary forms, with or without modification,
|
|
5 |
# are permitted provided that the following conditions are met: |
|
6 |
#
|
|
7 |
# 1. Redistributions of source code must retain the above copyright notice,
|
|
3 |
# |
|
4 |
# Redistribution and use in source and binary forms, with or without |
|
5 |
# modification, are permitted provided that the following conditions are met:
|
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above copyright notice, |
|
8 | 8 |
# this list of conditions and the following disclaimer. |
9 |
#
|
|
10 |
# 2. Redistributions in binary form must reproduce the above copyright
|
|
9 |
# |
|
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
|
11 | 11 |
# notice, this list of conditions and the following disclaimer in the |
12 | 12 |
# documentation and/or other materials provided with the distribution. |
13 |
#
|
|
14 |
# 3. Neither the name of Django nor the names of its contributors may be used
|
|
15 |
# to endorse or promote products derived from this software without |
|
13 |
# |
|
14 |
# 3. Neither the name of Django nor the names of its contributors may be |
|
15 |
# used to endorse or promote products derived from this software without
|
|
16 | 16 |
# specific prior written permission. |
17 |
#
|
|
18 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19 |
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
20 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
21 |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
22 |
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23 |
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24 |
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
25 |
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
27 |
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
17 |
# |
|
18 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
19 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21 |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
|
22 |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23 |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24 |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25 |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26 |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28 | 28 |
|
29 | 29 |
import re |
30 | 30 |
import datetime |
... | ... | |
41 | 41 |
RFC850_DATE = re.compile(r'^\w{6,9}, %s-%s-%s %s GMT$' % (__D, __M, __Y2, __T)) |
42 | 42 |
ASCTIME_DATE = re.compile(r'^\w{3} %s %s %s %s$' % (__M, __D2, __T, __Y)) |
43 | 43 |
|
44 |
|
|
44 | 45 |
def parse_http_date(date): |
45 | 46 |
""" |
46 | 47 |
Parses a date format as specified by HTTP RFC2616 section 3.3.1. |
... | ... | |
77 | 78 |
except Exception: |
78 | 79 |
raise ValueError("%r is not a valid date" % date) |
79 | 80 |
|
81 |
|
|
80 | 82 |
def parse_http_date_safe(date): |
81 | 83 |
""" |
82 | 84 |
Same as parse_http_date, but returns None if the input is invalid. |
Also available in: Unified diff