Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
6d63757e
Commit
6d63757e
authored
Nov 10, 2000
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged fix to prevent locale from affecting http date headers
parent
dd44b034
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
158 additions
and
142 deletions
+158
-142
ZServer/medusa/http_date.py
ZServer/medusa/http_date.py
+79
-71
lib/python/ZServer/medusa/http_date.py
lib/python/ZServer/medusa/http_date.py
+79
-71
No files found.
ZServer/medusa/http_date.py
View file @
6d63757e
...
@@ -5,13 +5,13 @@ import string
...
@@ -5,13 +5,13 @@ import string
import
time
import
time
def
concat
(
*
args
):
def
concat
(
*
args
):
return
string
.
joinfields
(
args
,
''
)
return
string
.
joinfields
(
args
,
''
)
def
join
(
seq
,
field
=
' '
):
def
join
(
seq
,
field
=
' '
):
return
string
.
joinfields
(
seq
,
field
)
return
string
.
joinfields
(
seq
,
field
)
def
group
(
s
):
def
group
(
s
):
return
'
\
\
('
+
s
+
'
\
\
)'
return
'
\
\
('
+
s
+
'
\
\
)'
short_days
=
[
'sun'
,
'mon'
,
'tue'
,
'wed'
,
'thu'
,
'fri'
,
'sat'
]
short_days
=
[
'sun'
,
'mon'
,
'tue'
,
'wed'
,
'thu'
,
'fri'
,
'sat'
]
long_days
=
[
'sunday'
,
'monday'
,
'tuesday'
,
'wednesday'
,
'thursday'
,
'friday'
,
'saturday'
]
long_days
=
[
'sunday'
,
'monday'
,
'tuesday'
,
'wednesday'
,
'thursday'
,
'friday'
,
'saturday'
]
...
@@ -21,8 +21,8 @@ long_day_reg = group (join (long_days, '\\|'))
...
@@ -21,8 +21,8 @@ long_day_reg = group (join (long_days, '\\|'))
daymap
=
{}
daymap
=
{}
for
i
in
range
(
7
):
for
i
in
range
(
7
):
daymap
[
short_days
[
i
]]
=
i
daymap
[
short_days
[
i
]]
=
i
daymap
[
long_days
[
i
]]
=
i
daymap
[
long_days
[
i
]]
=
i
hms_reg
=
join
(
3
*
[
group
(
'[0-9][0-9]'
)],
':'
)
hms_reg
=
join
(
3
*
[
group
(
'[0-9][0-9]'
)],
':'
)
...
@@ -30,7 +30,7 @@ months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec
...
@@ -30,7 +30,7 @@ months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec
monmap
=
{}
monmap
=
{}
for
i
in
range
(
12
):
for
i
in
range
(
12
):
monmap
[
months
[
i
]]
=
i
+
1
monmap
[
months
[
i
]]
=
i
+
1
months_reg
=
group
(
join
(
months
,
'
\
\
|'
))
months_reg
=
group
(
join
(
months
,
'
\
\
|'
))
...
@@ -41,83 +41,91 @@ months_reg = group (join (months, '\\|'))
...
@@ -41,83 +41,91 @@ months_reg = group (join (months, '\\|'))
# rfc822 format
# rfc822 format
rfc822_date
=
join
(
rfc822_date
=
join
(
[
concat
(
short_day_reg
,
','
),
# day
[
concat
(
short_day_reg
,
','
),
# day
group
(
'[0-9][0-9]?'
),
# date
group
(
'[0-9][0-9]?'
),
# date
months_reg
,
# month
months_reg
,
# month
group
(
'[0-9]+'
),
# year
group
(
'[0-9]+'
),
# year
hms_reg
,
# hour minute second
hms_reg
,
# hour minute second
'gmt'
'gmt'
],
],
' '
' '
)
)
rfc822_reg
=
regex
.
compile
(
rfc822_date
)
rfc822_reg
=
regex
.
compile
(
rfc822_date
)
def
unpack_rfc822
():
def
unpack_rfc822
():
g
=
rfc822_reg
.
group
g
=
rfc822_reg
.
group
a
=
string
.
atoi
a
=
string
.
atoi
return
(
return
(
a
(
g
(
4
)),
# year
a
(
g
(
4
)),
# year
monmap
[
g
(
3
)],
# month
monmap
[
g
(
3
)],
# month
a
(
g
(
2
)),
# day
a
(
g
(
2
)),
# day
a
(
g
(
5
)),
# hour
a
(
g
(
5
)),
# hour
a
(
g
(
6
)),
# minute
a
(
g
(
6
)),
# minute
a
(
g
(
7
)),
# second
a
(
g
(
7
)),
# second
0
,
0
,
0
,
0
,
0
0
)
)
# rfc850 format
# rfc850 format
rfc850_date
=
join
(
rfc850_date
=
join
(
[
concat
(
long_day_reg
,
','
),
[
concat
(
long_day_reg
,
','
),
join
(
join
(
[
group
(
'[0-9][0-9]?'
),
[
group
(
'[0-9][0-9]?'
),
months_reg
,
months_reg
,
group
(
'[0-9]+'
)
group
(
'[0-9]+'
)
],
],
'-'
'-'
),
),
hms_reg
,
hms_reg
,
'gmt'
'gmt'
],
],
' '
' '
)
)
rfc850_reg
=
regex
.
compile
(
rfc850_date
)
rfc850_reg
=
regex
.
compile
(
rfc850_date
)
# they actually unpack the same way
# they actually unpack the same way
def
unpack_rfc850
():
def
unpack_rfc850
():
g
=
rfc850_reg
.
group
g
=
rfc850_reg
.
group
a
=
string
.
atoi
a
=
string
.
atoi
return
(
return
(
a
(
g
(
4
)),
# year
a
(
g
(
4
)),
# year
monmap
[
g
(
3
)],
# month
monmap
[
g
(
3
)],
# month
a
(
g
(
2
)),
# day
a
(
g
(
2
)),
# day
a
(
g
(
5
)),
# hour
a
(
g
(
5
)),
# hour
a
(
g
(
6
)),
# minute
a
(
g
(
6
)),
# minute
a
(
g
(
7
)),
# second
a
(
g
(
7
)),
# second
0
,
0
,
0
,
0
,
0
0
)
)
# parsdate.parsedate - ~700/sec.
# parsdate.parsedate - ~700/sec.
# parse_http_date - ~1333/sec.
# parse_http_date - ~1333/sec.
weekdayname
=
[
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
,
'Sun'
]
monthname
=
[
None
,
'Jan'
,
'Feb'
,
'Mar'
,
'Apr'
,
'May'
,
'Jun'
,
'Jul'
,
'Aug'
,
'Sep'
,
'Oct'
,
'Nov'
,
'Dec'
]
def
build_http_date
(
when
):
def
build_http_date
(
when
):
return
time
.
strftime
(
'%a, %d %b %Y %H:%M:%S GMT'
,
time
.
gmtime
(
when
))
year
,
month
,
day
,
hh
,
mm
,
ss
,
wd
,
y
,
z
=
time
.
gmtime
(
when
)
return
"%s, %02d %3s %4d %02d:%02d:%02d GMT"
%
(
weekdayname
[
wd
],
day
,
monthname
[
month
],
year
,
hh
,
mm
,
ss
)
def
parse_http_date
(
d
):
def
parse_http_date
(
d
):
d
=
string
.
lower
(
d
)
d
=
string
.
lower
(
d
)
tz
=
time
.
timezone
tz
=
time
.
timezone
if
rfc850_reg
.
match
(
d
)
==
len
(
d
):
if
rfc850_reg
.
match
(
d
)
==
len
(
d
):
retval
=
int
(
time
.
mktime
(
unpack_rfc850
())
-
tz
)
retval
=
int
(
time
.
mktime
(
unpack_rfc850
())
-
tz
)
elif
rfc822_reg
.
match
(
d
)
==
len
(
d
):
elif
rfc822_reg
.
match
(
d
)
==
len
(
d
):
retval
=
int
(
time
.
mktime
(
unpack_rfc822
())
-
tz
)
retval
=
int
(
time
.
mktime
(
unpack_rfc822
())
-
tz
)
else
:
else
:
return
0
return
0
# Thanks to Craig Silverstein <csilvers@google.com> for pointing
# Thanks to Craig Silverstein <csilvers@google.com> for pointing
# out the DST discrepancy
# out the DST discrepancy
if
time
.
daylight
and
time
.
localtime
(
retval
)[
-
1
]
==
1
:
# DST correction
if
time
.
daylight
and
time
.
localtime
(
retval
)[
-
1
]
==
1
:
# DST correction
retval
=
retval
+
(
tz
-
time
.
altzone
)
retval
=
retval
+
(
tz
-
time
.
altzone
)
return
retval
return
retval
lib/python/ZServer/medusa/http_date.py
View file @
6d63757e
...
@@ -5,13 +5,13 @@ import string
...
@@ -5,13 +5,13 @@ import string
import
time
import
time
def
concat
(
*
args
):
def
concat
(
*
args
):
return
string
.
joinfields
(
args
,
''
)
return
string
.
joinfields
(
args
,
''
)
def
join
(
seq
,
field
=
' '
):
def
join
(
seq
,
field
=
' '
):
return
string
.
joinfields
(
seq
,
field
)
return
string
.
joinfields
(
seq
,
field
)
def
group
(
s
):
def
group
(
s
):
return
'
\
\
('
+
s
+
'
\
\
)'
return
'
\
\
('
+
s
+
'
\
\
)'
short_days
=
[
'sun'
,
'mon'
,
'tue'
,
'wed'
,
'thu'
,
'fri'
,
'sat'
]
short_days
=
[
'sun'
,
'mon'
,
'tue'
,
'wed'
,
'thu'
,
'fri'
,
'sat'
]
long_days
=
[
'sunday'
,
'monday'
,
'tuesday'
,
'wednesday'
,
'thursday'
,
'friday'
,
'saturday'
]
long_days
=
[
'sunday'
,
'monday'
,
'tuesday'
,
'wednesday'
,
'thursday'
,
'friday'
,
'saturday'
]
...
@@ -21,8 +21,8 @@ long_day_reg = group (join (long_days, '\\|'))
...
@@ -21,8 +21,8 @@ long_day_reg = group (join (long_days, '\\|'))
daymap
=
{}
daymap
=
{}
for
i
in
range
(
7
):
for
i
in
range
(
7
):
daymap
[
short_days
[
i
]]
=
i
daymap
[
short_days
[
i
]]
=
i
daymap
[
long_days
[
i
]]
=
i
daymap
[
long_days
[
i
]]
=
i
hms_reg
=
join
(
3
*
[
group
(
'[0-9][0-9]'
)],
':'
)
hms_reg
=
join
(
3
*
[
group
(
'[0-9][0-9]'
)],
':'
)
...
@@ -30,7 +30,7 @@ months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec
...
@@ -30,7 +30,7 @@ months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec
monmap
=
{}
monmap
=
{}
for
i
in
range
(
12
):
for
i
in
range
(
12
):
monmap
[
months
[
i
]]
=
i
+
1
monmap
[
months
[
i
]]
=
i
+
1
months_reg
=
group
(
join
(
months
,
'
\
\
|'
))
months_reg
=
group
(
join
(
months
,
'
\
\
|'
))
...
@@ -41,83 +41,91 @@ months_reg = group (join (months, '\\|'))
...
@@ -41,83 +41,91 @@ months_reg = group (join (months, '\\|'))
# rfc822 format
# rfc822 format
rfc822_date
=
join
(
rfc822_date
=
join
(
[
concat
(
short_day_reg
,
','
),
# day
[
concat
(
short_day_reg
,
','
),
# day
group
(
'[0-9][0-9]?'
),
# date
group
(
'[0-9][0-9]?'
),
# date
months_reg
,
# month
months_reg
,
# month
group
(
'[0-9]+'
),
# year
group
(
'[0-9]+'
),
# year
hms_reg
,
# hour minute second
hms_reg
,
# hour minute second
'gmt'
'gmt'
],
],
' '
' '
)
)
rfc822_reg
=
regex
.
compile
(
rfc822_date
)
rfc822_reg
=
regex
.
compile
(
rfc822_date
)
def
unpack_rfc822
():
def
unpack_rfc822
():
g
=
rfc822_reg
.
group
g
=
rfc822_reg
.
group
a
=
string
.
atoi
a
=
string
.
atoi
return
(
return
(
a
(
g
(
4
)),
# year
a
(
g
(
4
)),
# year
monmap
[
g
(
3
)],
# month
monmap
[
g
(
3
)],
# month
a
(
g
(
2
)),
# day
a
(
g
(
2
)),
# day
a
(
g
(
5
)),
# hour
a
(
g
(
5
)),
# hour
a
(
g
(
6
)),
# minute
a
(
g
(
6
)),
# minute
a
(
g
(
7
)),
# second
a
(
g
(
7
)),
# second
0
,
0
,
0
,
0
,
0
0
)
)
# rfc850 format
# rfc850 format
rfc850_date
=
join
(
rfc850_date
=
join
(
[
concat
(
long_day_reg
,
','
),
[
concat
(
long_day_reg
,
','
),
join
(
join
(
[
group
(
'[0-9][0-9]?'
),
[
group
(
'[0-9][0-9]?'
),
months_reg
,
months_reg
,
group
(
'[0-9]+'
)
group
(
'[0-9]+'
)
],
],
'-'
'-'
),
),
hms_reg
,
hms_reg
,
'gmt'
'gmt'
],
],
' '
' '
)
)
rfc850_reg
=
regex
.
compile
(
rfc850_date
)
rfc850_reg
=
regex
.
compile
(
rfc850_date
)
# they actually unpack the same way
# they actually unpack the same way
def
unpack_rfc850
():
def
unpack_rfc850
():
g
=
rfc850_reg
.
group
g
=
rfc850_reg
.
group
a
=
string
.
atoi
a
=
string
.
atoi
return
(
return
(
a
(
g
(
4
)),
# year
a
(
g
(
4
)),
# year
monmap
[
g
(
3
)],
# month
monmap
[
g
(
3
)],
# month
a
(
g
(
2
)),
# day
a
(
g
(
2
)),
# day
a
(
g
(
5
)),
# hour
a
(
g
(
5
)),
# hour
a
(
g
(
6
)),
# minute
a
(
g
(
6
)),
# minute
a
(
g
(
7
)),
# second
a
(
g
(
7
)),
# second
0
,
0
,
0
,
0
,
0
0
)
)
# parsdate.parsedate - ~700/sec.
# parsdate.parsedate - ~700/sec.
# parse_http_date - ~1333/sec.
# parse_http_date - ~1333/sec.
weekdayname
=
[
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
,
'Sun'
]
monthname
=
[
None
,
'Jan'
,
'Feb'
,
'Mar'
,
'Apr'
,
'May'
,
'Jun'
,
'Jul'
,
'Aug'
,
'Sep'
,
'Oct'
,
'Nov'
,
'Dec'
]
def
build_http_date
(
when
):
def
build_http_date
(
when
):
return
time
.
strftime
(
'%a, %d %b %Y %H:%M:%S GMT'
,
time
.
gmtime
(
when
))
year
,
month
,
day
,
hh
,
mm
,
ss
,
wd
,
y
,
z
=
time
.
gmtime
(
when
)
return
"%s, %02d %3s %4d %02d:%02d:%02d GMT"
%
(
weekdayname
[
wd
],
day
,
monthname
[
month
],
year
,
hh
,
mm
,
ss
)
def
parse_http_date
(
d
):
def
parse_http_date
(
d
):
d
=
string
.
lower
(
d
)
d
=
string
.
lower
(
d
)
tz
=
time
.
timezone
tz
=
time
.
timezone
if
rfc850_reg
.
match
(
d
)
==
len
(
d
):
if
rfc850_reg
.
match
(
d
)
==
len
(
d
):
retval
=
int
(
time
.
mktime
(
unpack_rfc850
())
-
tz
)
retval
=
int
(
time
.
mktime
(
unpack_rfc850
())
-
tz
)
elif
rfc822_reg
.
match
(
d
)
==
len
(
d
):
elif
rfc822_reg
.
match
(
d
)
==
len
(
d
):
retval
=
int
(
time
.
mktime
(
unpack_rfc822
())
-
tz
)
retval
=
int
(
time
.
mktime
(
unpack_rfc822
())
-
tz
)
else
:
else
:
return
0
return
0
# Thanks to Craig Silverstein <csilvers@google.com> for pointing
# Thanks to Craig Silverstein <csilvers@google.com> for pointing
# out the DST discrepancy
# out the DST discrepancy
if
time
.
daylight
and
time
.
localtime
(
retval
)[
-
1
]
==
1
:
# DST correction
if
time
.
daylight
and
time
.
localtime
(
retval
)[
-
1
]
==
1
:
# DST correction
retval
=
retval
+
(
tz
-
time
.
altzone
)
retval
=
retval
+
(
tz
-
time
.
altzone
)
return
retval
return
retval
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment