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
ea0cdd5a
Commit
ea0cdd5a
authored
Jan 29, 1999
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Many changes to fix PUT handling.
parent
d5519d7e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
156 deletions
+108
-156
lib/python/OFS/DTMLDocument.py
lib/python/OFS/DTMLDocument.py
+12
-14
lib/python/OFS/DTMLMethod.py
lib/python/OFS/DTMLMethod.py
+11
-59
lib/python/OFS/Folder.py
lib/python/OFS/Folder.py
+35
-40
lib/python/OFS/Image.py
lib/python/OFS/Image.py
+24
-14
lib/python/OFS/ObjectManager.py
lib/python/OFS/ObjectManager.py
+8
-11
lib/python/OFS/PropertyManager.py
lib/python/OFS/PropertyManager.py
+18
-18
No files found.
lib/python/OFS/DTMLDocument.py
View file @
ea0cdd5a
...
...
@@ -102,7 +102,7 @@
##############################################################################
"""DTML Document objects."""
__version__
=
'$Revision: 1.
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
from
ZPublisher.Converters
import
type_converters
from
Globals
import
HTML
,
HTMLFile
,
MessageDialog
from
DTMLMethod
import
DTMLMethod
,
decapitate
...
...
@@ -153,13 +153,10 @@ class DTMLDocument(DTMLMethod, PropertyManager):
state
[
k
]
=
v
return
state
do_post_processing
=
1
def
post_process
(
self
,
data
):
if
not
self
.
do_post_processing
:
return
# Set properties based on html meta tags.
try
:
meta
=
hp
(
data
)
def
on_update
(
self
):
# This is just experimental!
if
1
:
return
try
:
meta
=
hp
(
self
.
raw
)
except
:
return
for
key
,
val
in
meta
.
metavars
.
items
():
if
not
self
.
hasProperty
(
key
):
...
...
@@ -190,7 +187,7 @@ class DTMLDocument(DTMLMethod, PropertyManager):
return
self
.
_er
(
data
,
title
,
SUBMIT
,
dtpref_cols
,
dtpref_rows
,
REQUEST
)
self
.
title
=
title
self
.
munge
(
data
)
self
.
post_process
(
data
)
self
.
on_update
(
)
if
REQUEST
:
return
MessageDialog
(
title
=
'Success!'
,
message
=
'Your changes have been saved'
,
...
...
@@ -201,18 +198,19 @@ class DTMLDocument(DTMLMethod, PropertyManager):
self
.
_validateProxy
(
REQUEST
)
data
=
file
.
read
()
self
.
munge
(
data
)
self
.
post_process
(
data
)
self
.
on_update
(
)
if
REQUEST
:
return
MessageDialog
(
title
=
'Success!'
,
message
=
'Your changes have been saved'
,
action
=
'manage_main'
)
def
PUT
(
self
,
BODY
,
REQUEST
):
def
PUT
(
self
,
BODY
,
REQUEST
,
RESPONSE
):
"""Handle HTTP PUT requests."""
self
.
_validateProxy
(
REQUEST
)
self
.
munge
(
BODY
)
self
.
post_process
(
BODY
)
return
'OK'
self
.
on_update
()
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
def
__call__
(
self
,
client
=
None
,
REQUEST
=
{},
RESPONSE
=
None
,
**
kw
):
"""Render the document given a client object, REQUEST mapping,
...
...
@@ -305,7 +303,7 @@ def add(self, id, title='', file='', REQUEST=None, submit=None):
if
not
file
:
file
=
default_dd_html
ob
=
DTMLDocument
(
file
,
__name__
=
id
)
ob
.
title
=
title
ob
.
post_process
(
file
)
ob
.
on_update
(
)
self
.
_setObject
(
id
,
ob
)
if
REQUEST
is
not
None
:
u
=
REQUEST
[
'URL1'
]
...
...
lib/python/OFS/DTMLMethod.py
View file @
ea0cdd5a
...
...
@@ -102,7 +102,7 @@
##############################################################################
"""DTML Method objects."""
__version__
=
'$Revision: 1.
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
from
Globals
import
HTML
,
HTMLFile
,
MessageDialog
from
string
import
join
,
split
,
strip
,
rfind
,
atoi
,
lower
...
...
@@ -216,7 +216,6 @@ class DTMLMethod(cDocument, HTML, Explicit, RoleManager, Item_w__name__):
manage
=
manage_main
=
manage_editDocument
=
manage_editForm
manage_proxyForm
=
HTMLFile
(
'documentProxy'
,
globals
())
_size_changes
=
{
'Bigger'
:
(
5
,
5
),
'Smaller'
:
(
-
5
,
-
5
),
...
...
@@ -270,11 +269,7 @@ class DTMLMethod(cDocument, HTML, Explicit, RoleManager, Item_w__name__):
message
=
'Your changes have been saved'
,
action
=
'manage_main'
)
def
PUT
(
self
,
BODY
,
REQUEST
):
"""Handle HTTP PUT requests."""
self
.
_validateProxy
(
REQUEST
)
self
.
munge
(
BODY
)
return
'OK'
def
manage_haveProxy
(
self
,
r
):
return
r
in
self
.
_proxy_roles
...
...
@@ -311,64 +306,21 @@ class DTMLMethod(cDocument, HTML, Explicit, RoleManager, Item_w__name__):
return
self
.
read
()
## Protocol handlers
def
PUT
(
self
,
BODY
,
REQUEST
,
RESPONSE
):
"""Handle HTTP PUT requests."""
self
.
_validateProxy
(
REQUEST
)
self
.
munge
(
BODY
)
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
def
manage_FTPget
(
self
):
"Get source for FTP download"
return
self
.
read
()
from
sgmllib
import
SGMLParser
done
=
'done'
class
hp
(
SGMLParser
):
from
htmlentitydefs
import
entitydefs
def
__init__
(
self
,
data
):
SGMLParser
.
__init__
(
self
,
verbose
=
0
)
self
.
metavars
=
{}
self
.
headers
=
{}
self
.
data
=
None
self
.
title
=
''
try
:
self
.
feed
(
data
)
except
done
:
pass
def
handle_data
(
self
,
data
):
if
self
.
data
is
not
None
:
self
.
data
=
self
.
data
+
data
else
:
pass
def
save_bgn
(
self
):
self
.
data
=
''
def
save_end
(
self
):
data
=
self
.
data
self
.
data
=
None
return
data
def
start_head
(
self
,
attrs
):
pass
def
end_head
(
self
):
# avoid parsing whole file!
raise
done
,
done
def
start_title
(
self
,
attrs
):
self
.
save_bgn
()
def
end_title
(
self
):
self
.
title
=
self
.
save_end
()
def
do_meta
(
self
,
attrs
):
dict
=
{}
for
key
,
val
in
attrs
:
dict
[
key
]
=
val
if
dict
.
has_key
(
'http-equiv'
):
self
.
headers
[
dict
[
'http-equiv'
]]
=
dict
[
'content'
]
elif
dict
.
has_key
(
'name'
):
self
.
metavars
[
dict
[
'name'
]]
=
dict
[
'content'
]
...
...
lib/python/OFS/Folder.py
View file @
ea0cdd5a
...
...
@@ -105,23 +105,20 @@
Folders are the basic container objects and are analogous to directories.
$Id: Folder.py,v 1.58 1999/01/27 20:30:28 brian Exp $"""
__version__
=
'$Revision: 1.58 $'
[
11
:
-
2
]
$Id: Folder.py,v 1.59 1999/01/29 15:41:39 brian Exp $"""
__version__
=
'$Revision: 1.59 $'
[
11
:
-
2
]
import
Globals
,
SimpleItem
,
Acquisition
,
mimetypes
,
content_types
from
Globals
import
HTMLFile
from
ObjectManager
import
ObjectManager
from
PropertyManager
import
PropertyManager
from
AccessControl.Role
import
RoleManager
from
CopySupport
import
CopyContainer
from
FindSupport
import
FindSupport
from
Image
import
Image
,
File
from
AccessControl.Role
import
RoleManager
import
SimpleItem
from
string
import
rfind
,
lower
from
content_types
import
content_type
,
find_binary
,
text_type
import
Globals
import
Acquisition
manage_addFolderForm
=
HTMLFile
(
'folderAdd'
,
globals
())
...
...
@@ -258,45 +255,43 @@ class Folder(ObjectManager, PropertyManager, RoleManager, SimpleItem.Item,
self
.
_setObject
(
id
,
o
)
return
'OK, I imported %s'
%
id
class
PUTer
(
Acquisition
.
Explicit
):
"""Class to support the HTTP PUT protocol."""
def
__init__
(
self
,
parent
,
key
):
self
.
_parent
=
parent
self
.
_
key
=
key
self
.
__roles__
=
parent
.
PUT__roles__
def
__init__
(
self
,
parent
,
id
):
self
.
id
=
id
self
.
_
_parent__
=
parent
self
.
__roles__
=
parent
.
PUT__roles__
def
PUT
(
self
,
REQUEST
,
BODY
):
def
PUT
(
self
,
REQUEST
,
RESPONSE
):
"""Adds a document, image or file to the folder when a PUT
request is received."""
name
=
self
.
_key
try
:
type
=
REQUEST
[
'CONTENT_TYPE'
]
except
KeyError
:
type
=
''
if
not
type
:
dot
=
rfind
(
name
,
'.'
)
suf
=
dot
>
0
and
lower
(
name
[
dot
+
1
:])
or
''
if
suf
:
try
:
type
=
content_type
[
suf
]
except
KeyError
:
if
find_binary
(
BODY
)
>=
0
:
type
=
'application/x-%s'
%
suf
else
:
type
=
text_type
(
BODY
)
else
:
if
find_binary
(
BODY
)
>=
0
:
raise
'Bad Request'
,
'Could not determine file type'
else
:
type
=
text_type
(
BODY
)
__traceback_info__
=
suf
,
dot
,
name
,
type
if
lower
(
type
)[:
5
]
==
'text/'
:
return
self
.
_parent
.
manage_addDTMLDocument
(
name
,
''
,
BODY
,
REQUEST
=
REQUEST
)
if
lower
(
type
)[:
6
]
==
'image/'
:
self
.
_parent
.
_setObject
(
name
,
Image
(
name
,
''
,
BODY
,
content_type
=
type
))
name
=
self
.
id
type
=
REQUEST
.
get_header
(
'content-type'
,
None
)
body
=
REQUEST
.
get
(
'BODY'
,
''
)
if
type
is
None
:
type
,
enc
=
mimetypes
.
guess_type
(
name
)
if
type
is
None
:
if
content_types
.
find_binary
(
body
)
>=
0
:
raise
'Bad Request'
,
'Unknown content type'
else
:
type
=
content_types
.
text_type
(
body
)
type
=
lower
(
type
)
if
type
in
(
'text/html'
,
'text/xml'
,
'text/plain'
):
self
.
__parent__
.
manage_addDTMLDocument
(
name
,
''
,
body
)
elif
type
[:
6
]
==
'image/'
:
ob
=
Image
(
name
,
''
,
body
,
content_type
=
type
)
self
.
__parent__
.
_setObject
(
name
,
ob
)
else
:
self
.
_parent
.
_setObject
(
name
,
File
(
name
,
''
,
BODY
,
content_type
=
type
))
return
'OK'
def
__str__
(
self
):
return
self
.
_key
ob
=
File
(
name
,
''
,
body
,
content_type
=
type
)
self
.
__parent__
.
_setObject
(
name
,
ob
)
RESPONSE
.
setStatus
(
201
)
RESPONSE
.
setBody
(
''
)
return
RESPONSE
def
__str__
(
self
):
return
self
.
id
...
...
lib/python/OFS/Image.py
View file @
ea0cdd5a
...
...
@@ -102,9 +102,9 @@
##############################################################################
"""Image object"""
__version__
=
'$Revision: 1.5
1
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.5
2
$'
[
11
:
-
2
]
import
Globals
import
Globals
,
string
,
struct
,
mimetypes
,
content_types
from
Globals
import
HTMLFile
,
MessageDialog
from
PropertyManager
import
PropertyManager
from
AccessControl.Role
import
RoleManager
...
...
@@ -112,7 +112,7 @@ from SimpleItem import Item_w__name__
from
Globals
import
Persistent
from
Acquisition
import
Implicit
from
DateTime
import
DateTime
import
string
,
struct
manage_addFileForm
=
HTMLFile
(
'imageAdd'
,
globals
(),
Kind
=
'File'
,
kind
=
'file'
)
def
manage_addFile
(
self
,
id
,
file
,
title
=
''
,
precondition
=
''
,
REQUEST
=
None
):
...
...
@@ -168,13 +168,13 @@ class File(Persistent,Implicit,PropertyManager,
self
.
precondition
=
precondition
headers
=
hasattr
(
file
,
'headers'
)
and
file
.
headers
or
None
if
(
headers
is
None
)
and
(
not
content_type
):
raise
'Bad
Value
'
,
'No content type specified.'
if
headers
.
has_key
(
'content-type'
):
raise
'Bad
Request
'
,
'No content type specified.'
if
headers
and
headers
.
has_key
(
'content-type'
):
content_type
=
headers
[
'content-type'
]
if
not
content_type
:
raise
'Bad
Value
'
,
'No content type specified.'
raise
'Bad
Request
'
,
'No content type specified.'
data
=
(
headers
is
None
)
and
file
or
file
.
read
()
self
.
post_process
(
data
,
content_type
)
self
.
update_data
(
data
,
content_type
)
def
id
(
self
):
return
self
.
__name__
...
...
@@ -205,7 +205,7 @@ class File(Persistent,Implicit,PropertyManager,
"""
raise
'Redirect'
,
URL1
def
post_process
(
self
,
data
,
content_type
=
None
):
def
update_data
(
self
,
data
,
content_type
=
None
):
if
content_type
is
not
None
:
self
.
content_type
=
content_type
self
.
data
=
Pdata
(
data
)
...
...
@@ -233,7 +233,7 @@ class File(Persistent,Implicit,PropertyManager,
if
file
.
headers
.
has_key
(
'content-type'
):
content_type
=
file
.
headers
[
'content-type'
]
else
:
content_type
=
None
self
.
post_process
(
file
.
read
(),
content_type
)
self
.
update_data
(
file
.
read
(),
content_type
)
if
REQUEST
:
return
MessageDialog
(
title
=
'Success!'
,
message
=
'Your changes have been saved'
,
...
...
@@ -246,11 +246,21 @@ class File(Persistent,Implicit,PropertyManager,
RESPONSE
[
'content-length'
]
=
self
.
getSize
()
return
''
def
PUT
(
self
,
BODY
,
REQUEST
):
def
PUT
(
self
,
REQUEST
,
RESPONSE
):
"""Handle HTTP PUT requests"""
content_type
=
REQUEST
.
get
(
'CONTENT_TYPE'
,
None
)
self
.
post_process
(
BODY
,
content_type
)
type
=
REQUEST
.
get_header
(
'content-type'
,
None
)
body
=
REQUEST
.
get
(
'BODY'
,
''
)
if
type
is
None
:
type
,
enc
=
mimetypes
.
guess_type
(
self
.
id
())
if
type
is
None
:
if
content_types
.
find_binary
(
body
)
>=
0
:
type
=
'application/octet-stream'
else
:
type
=
content_types
.
text_type
(
body
)
type
=
string
.
lower
(
type
)
self
.
update_data
(
body
,
type
)
RESPONSE
.
setStatus
(
204
)
return
RESPONSE
def
getSize
(
self
):
"""Get the size of a file or image.
...
...
@@ -309,7 +319,7 @@ class Image(File):
kind
=
'image'
)
manage
=
manage_main
=
manage_editForm
def
post_process
(
self
,
data
,
content_type
=
None
):
def
update_data
(
self
,
data
,
content_type
=
None
):
if
content_type
is
not
None
:
self
.
content_type
=
content_type
self
.
data
=
Pdata
(
data
)
...
...
lib/python/OFS/ObjectManager.py
View file @
ea0cdd5a
...
...
@@ -84,9 +84,9 @@
##############################################################################
__doc__
=
"""Object Manager
$Id: ObjectManager.py,v 1.
49 1999/01/06 23:20:06
brian Exp $"""
$Id: ObjectManager.py,v 1.
50 1999/01/29 15:41:39
brian Exp $"""
__version__
=
'$Revision: 1.
49
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
50
$'
[
11
:
-
2
]
import
App.Management
,
Acquisition
,
App
.
Undo
,
Globals
import
App.FactoryDispatcher
...
...
@@ -153,21 +153,18 @@ class ObjectManager(
return
self
.
meta_types
+
self
.
dynamic_meta_types
+
pmt
def
_checkId
(
self
,
id
):
if
not
id
:
raise
'Bad Request'
,
'No <em>id</em> was specified'
if
not
id
:
raise
'Bad Request'
,
'No <em>id</em> was specified'
if
quote
(
id
)
!=
id
:
raise
'Bad Request'
,
(
"""The id <em>%s<em> is invalid - it
contains characters illegal in URLs."""
%
id
)
if
id
[:
1
]
==
'_'
:
raise
'Bad Request'
,
(
"""The id <em>%s<em> is invalid - it
begins with an underscore character, _."""
%
id
)
try
:
self
=
self
.
aq_base
except
:
return
if
hasattr
(
self
,
id
):
raise
'Bad Request'
,
(
if
hasattr
(
self
,
'aq_base'
):
self
=
self
.
aq_base
if
hasattr
(
self
,
id
):
raise
'Bad Request'
,
(
"""The id <em>%s<em> is invalid - it
is already in use."""
%
id
)
...
...
lib/python/OFS/PropertyManager.py
View file @
ea0cdd5a
...
...
@@ -84,7 +84,7 @@
##############################################################################
"""Property management"""
__version__
=
'$Revision: 1.
4
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
5
$'
[
11
:
-
2
]
from
ZPublisher.Converters
import
type_converters
...
...
@@ -219,7 +219,7 @@ class PropertyManager:
def
manage_addProperty
(
self
,
id
,
value
,
type
,
REQUEST
=
None
):
"""Add a new property via the web. Sets a new property with
the given id, type, and value."""
the given id, type, and value."""
if
type_converters
.
has_key
(
type
):
value
=
type_converters
[
type
](
value
)
self
.
_setProperty
(
id
,
value
,
type
)
...
...
@@ -338,26 +338,26 @@ class PropertyManager:
'lines'
:
_linesInput
,
'text'
:
_textInput
,
'date'
:
_defaultInput
,
'tokens'
:
_tokensInput
,
'tokens'
:
_tokensInput
}
propertyTypes
=
map
(
lambda
key
:
(
lower
(
key
),
key
),
_inputMap
.
keys
())
propertyTypes
.
sort
()
propertyTypes
=
map
(
lambda
key
:
{
'id'
:
key
[
1
],
'selected'
:
key
[
1
]
==
'string'
and
'SELECTED'
or
''
},
propertyTypes
)
propertyTypes
=
map
(
lambda
key
:
(
lower
(
key
),
key
),
_inputMap
.
keys
())
propertyTypes
.
sort
()
propertyTypes
=
map
(
lambda
key
:
{
'id'
:
key
[
1
],
'selected'
:
key
[
1
]
==
'string'
and
'SELECTED'
or
''
},
propertyTypes
)
def
propertyInputs
(
self
):
imap
=
self
.
_inputMap
r
=
[]
for
p
in
self
.
_properties
:
n
=
p
[
'id'
]
t
=
p
[
'type'
]
v
=
getattr
(
self
,
n
)
r
.
append
({
'id'
:
n
,
'input'
:
imap
[
t
](
None
,
n
,
t
,
v
)})
return
r
def
propertyInputs
(
self
):
imap
=
self
.
_inputMap
r
=
[]
for
p
in
self
.
_properties
:
n
=
p
[
'id'
]
t
=
p
[
'type'
]
v
=
getattr
(
self
,
n
)
r
.
append
({
'id'
:
n
,
'input'
:
imap
[
t
](
None
,
n
,
t
,
v
)})
return
r
def
aq_base
(
ob
):
...
...
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