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
2b8b699e
Commit
2b8b699e
authored
Apr 06, 1999
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added caching headers and handling of If-Modified-Since headers to ImageFile objects.
parent
5a36954a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
16 deletions
+30
-16
lib/python/ImageFile.py
lib/python/ImageFile.py
+30
-16
No files found.
lib/python/ImageFile.py
View file @
2b8b699e
...
...
@@ -84,29 +84,49 @@
##############################################################################
"""Image object that is stored in a file"""
__version__
=
'$Revision: 1.8 $'
[
11
:
-
2
]
__version__
=
'$Revision: 1.9 $'
[
11
:
-
2
]
from
string
import
rfind
from
Globals
import
package_home
from
Common
import
rfc1123_date
from
DateTime
import
DateTime
from
string
import
rfind
from
time
import
time
from
os
import
stat
import
Acquisition
class
ImageFile
(
Acquisition
.
Explicit
):
"""Image object
stored in an external file
"""
"""Image object
s stored in external files.
"""
def
__init__
(
self
,
path
,
_prefix
=
None
):
if
_prefix
is
None
:
_prefix
=
SOFTWARE_HOME
elif
type
(
_prefix
)
is
not
type
(
''
):
_prefix
=
package_home
(
_prefix
)
elif
type
(
_prefix
)
is
not
type
(
''
):
_prefix
=
package_home
(
_prefix
)
path
=
'%s/%s'
%
(
_prefix
,
path
)
self
.
path
=
path
self
.
content_type
=
'image/%s'
%
path
[
rfind
(
path
,
'.'
)
+
1
:]
self
.
__name__
=
path
[
rfind
(
path
,
'/'
)
+
1
:]
def
index_html
(
self
,
RESPONSE
):
# Determine a reasonable last-modification time
# to support aggressive image caching.
self
.
lmt
=
float
(
stat
(
path
)[
8
])
or
time
()
self
.
lmh
=
rfc1123_date
(
self
.
lmt
)
def
_init_headers
(
self
,
request
,
response
):
# attempt aggressive caching!
ms
=
request
.
get_header
(
'If-Modified-Since'
,
None
)
if
ms
is
not
None
:
mst
=
DateTime
(
ms
).
timeTime
()
if
mst
>=
self
.
lmt
:
response
.
setStatus
(
304
)
return
response
response
.
setHeader
(
'Content-Type'
,
self
.
content_type
)
response
.
setHeader
(
'Last-Modified'
,
self
.
lmh
)
response
.
setHeader
(
'Expires'
,
rfc1123_date
(
time
()
+
86400.0
))
def
index_html
(
self
,
REQUEST
,
RESPONSE
):
"""Default document"""
RESPONSE
[
'content-type'
]
=
self
.
content_type
self
.
_init_headers
(
REQUEST
,
RESPONSE
)
f
=
open
(
self
.
path
,
'rb'
)
data
=
f
.
read
()
f
.
close
()
...
...
@@ -115,7 +135,7 @@ class ImageFile(Acquisition.Explicit):
HEAD__roles__
=
None
def
HEAD
(
self
,
REQUEST
,
RESPONSE
):
""" """
RESPONSE
[
'content-type'
]
=
self
.
content_type
self
.
_init_headers
(
self
,
REQUEST
,
RESPONSE
)
return
''
def
__len__
(
self
):
...
...
@@ -125,9 +145,3 @@ class ImageFile(Acquisition.Explicit):
def
__str__
(
self
):
return
'<IMG SRC="%s" ALT="%s">'
%
(
self
.
__name__
,
self
.
title_or_id
())
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