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
22d8c250
Commit
22d8c250
authored
Jul 29, 2007
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the last failing test (w0000t): rip out most of our custom resource code and replace
it with light shims over the Zope 3 stuff.
parent
c8b94d0f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
92 deletions
+29
-92
lib/python/Products/Five/browser/resource.py
lib/python/Products/Five/browser/resource.py
+29
-92
No files found.
lib/python/Products/Five/browser/resource.py
View file @
22d8c250
...
...
@@ -18,44 +18,49 @@ $Id$
import
os
import
urllib
from
OFS.Traversable
import
Traversable
as
OFSTraversable
from
zope.app.publisher.browser.resources
import
empty
from
zope.app.publisher.fileresource
import
File
,
Image
from
zope.app.publisher.pagetemplateresource
import
PageTemplate
from
zope.interface
import
implements
from
zope.component
import
getMultiAdapter
from
zope.component.interfaces
import
IResource
from
zope.datetime
import
time
as
timeFromDateTimeString
from
zope.traversing.browser.interfaces
import
IAbsoluteURL
from
zope.traversing.browser
import
absoluteURL
from
zope.publisher.interfaces
import
NotFound
from
zope.publisher.interfaces.browser
import
IBrowserPublisher
from
zope.app.publisher.browser
import
fileresource
,
directoryresource
from
zope.app.publisher.fileresource
import
File
,
Image
from
zope.app.publisher.pagetemplateresource
import
PageTemplate
from
Products.Five.browser
import
BrowserView
_marker
=
[]
_marker
=
object
()
class
Resource
(
object
):
"""A publishable resource
"""
implements
(
IResource
)
"""A mixin that changes the URL-rendering of resources (__call__).
def
__init__
(
self
,
request
):
self
.
request
=
request
In Zope 3, resource URLs are of the form
nearest_site/@@/resource_name. Since Zope 2 didn't have support
for sites from the beginning of the Five integration, resource
URLs in Zope 2 are of the form context/++resource++resource_name.
TODO It would be good if that could be changed in the long term,
thus making this mixin (and probably the other classes in this
module) obsolete.
"""
def
__call__
(
self
):
name
=
self
.
__name__
container
=
self
.
__parent__
# TODO Zope 3 uses site = getSite() instead of container here
# and the @@ resource access view
url
=
str
(
getMultiAdapter
((
container
,
self
.
request
),
IAbsoluteURL
))
url
=
urllib
.
unquote
(
url
)
url
=
urllib
.
unquote
(
absoluteURL
(
container
,
self
.
request
))
if
not
isinstance
(
container
,
DirectoryResource
):
name
=
'++resource++%s'
%
name
return
"%s/%s"
%
(
url
,
name
)
class
PageTemplateResource
(
BrowserView
,
Resource
):
#implements(IBrowserPublisher)
class
PageTemplateResource
(
Resource
,
BrowserView
):
implements
(
IBrowserPublisher
)
def
browserDefault
(
self
,
request
):
return
self
.
render
,
()
def
__browser_default__
(
self
,
request
):
r
eturn
self
,
(
'render'
,
)
def
publishTraverse
(
self
,
request
,
name
):
r
aise
NotFound
(
self
,
name
,
request
)
def
render
(
self
):
"""Rendered content"""
...
...
@@ -65,62 +70,8 @@ class PageTemplateResource(BrowserView, Resource):
pt
=
self
.
context
return
pt
(
self
.
request
)
class
FileResource
(
BrowserView
,
Resource
):
"""A publishable file-based resource"""
#implements(IBrowserPublisher)
def
__browser_default__
(
self
,
request
):
return
self
,
(
request
.
REQUEST_METHOD
,)
def
GET
(
self
):
"""Default content"""
file
=
self
.
context
request
=
self
.
request
response
=
request
.
response
# HTTP If-Modified-Since header handling. This is duplicated
# from OFS.Image.Image - it really should be consolidated
# somewhere...
header
=
request
.
environ
.
get
(
'If-Modified-Since'
,
None
)
if
header
is
not
None
:
header
=
header
.
split
(
';'
)[
0
]
# Some proxies seem to send invalid date strings for this
# header. If the date string is not valid, we ignore it
# rather than raise an error to be generally consistent
# with common servers such as Apache (which can usually
# understand the screwy date string as a lucky side effect
# of the way they parse it).
try
:
mod_since
=
long
(
timeFromDateTimeString
(
header
))
except
:
mod_since
=
None
if
mod_since
is
not
None
:
if
getattr
(
file
,
'lmt'
,
None
):
last_mod
=
long
(
file
.
lmt
)
else
:
last_mod
=
long
(
0
)
if
last_mod
>
0
and
last_mod
<=
mod_since
:
response
.
setStatus
(
304
)
return
''
response
.
setHeader
(
'Content-Type'
,
file
.
content_type
)
response
.
setHeader
(
'Last-Modified'
,
file
.
lmh
)
# Cache for one day
response
.
setHeader
(
'Cache-Control'
,
'public,max-age=86400'
)
f
=
open
(
file
.
path
,
'rb'
)
data
=
f
.
read
()
f
.
close
()
return
data
def
HEAD
(
self
):
file
=
self
.
context
response
=
self
.
request
.
response
response
=
self
.
request
.
response
response
.
setHeader
(
'Content-Type'
,
file
.
content_type
)
response
.
setHeader
(
'Last-Modified'
,
file
.
lmh
)
# Cache for one day
response
.
setHeader
(
'Cache-Control'
,
'public,max-age=86400'
)
return
''
class
FileResource
(
Resource
,
fileresource
.
FileResource
):
pass
class
ResourceFactory
:
...
...
@@ -171,8 +122,7 @@ class Directory:
self
.
path
=
path
self
.
__name__
=
name
class
DirectoryResource
(
BrowserView
,
Resource
,
OFSTraversable
):
#implements(IBrowserPublisher)
class
DirectoryResource
(
Resource
,
directoryresource
.
DirectoryResource
):
resource_factories
=
{
'gif'
:
ImageResourceFactory
,
...
...
@@ -185,25 +135,12 @@ class DirectoryResource(BrowserView, Resource, OFSTraversable):
default_factory
=
FileResourceFactory
def
__init__
(
self
,
context
,
request
):
BrowserView
.
__init__
(
self
,
context
,
request
)
def
getId
(
self
):
name
=
self
.
__name__
if
not
name
.
startswith
(
'++resource++'
):
name
=
'++resource++%s'
%
self
.
__name__
return
name
def
__browser_default__
(
self
,
request
):
'''See interface IBrowserPublisher'''
return
empty
,
()
def
__getitem__
(
self
,
name
):
res
=
self
.
get
(
name
,
None
)
if
res
is
None
:
raise
KeyError
,
name
return
res
def
get
(
self
,
name
,
default
=
_marker
):
path
=
self
.
context
.
path
filename
=
os
.
path
.
join
(
path
,
name
)
...
...
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