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
3f407d3d
Commit
3f407d3d
authored
Jun 21, 1999
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed to use delegation rather than inheritence to customize responses
for XML-RPC.
parent
eb56a836
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
18 deletions
+30
-18
lib/python/ZPublisher/xmlrpc.py
lib/python/ZPublisher/xmlrpc.py
+30
-18
No files found.
lib/python/ZPublisher/xmlrpc.py
View file @
3f407d3d
...
@@ -39,25 +39,27 @@ def parse_input(data):
...
@@ -39,25 +39,27 @@ def parse_input(data):
method
=
replace
(
method
,
'.'
,
'/'
)
method
=
replace
(
method
,
'.'
,
'/'
)
return
method
,
params
return
method
,
params
def
response
(
anHTTPResponse
):
# See below
"""Return a valid ZPublisher response object
#
# def response(anHTTPResponse):
Use data already gathered by the existing response.
# """Return a valid ZPublisher response object
The new response will replace the existing response.
#
"""
# Use data already gathered by the existing response.
# As a first cut, lets just clone the response and
# The new response will replace the existing response.
# put all of the logic in our refined response class below.
# """
r
=
Response
()
# # As a first cut, lets just clone the response and
r
.
__dict__
.
update
(
anHTTPResponse
.
__dict__
)
# # put all of the logic in our refined response class below.
return
r
# r=Response()
# r.__dict__.update(anHTTPResponse.__dict__)
# return r
########################################################################
########################################################################
# Possible implementation helpers:
# Possible implementation helpers:
class
Response
(
HTTPResponse
)
:
class
Response
:
"""Customized
HTTP
Response that handles XML-RPC-specific details.
"""Customized Response that handles XML-RPC-specific details.
We override setBody to marhsall Python objects into XML-RPC. We
We override setBody to marhsall Python objects into XML-RPC. We
also override exception to convert errors to XML-RPC faults.
also override exception to convert errors to XML-RPC faults.
...
@@ -70,6 +72,16 @@ class Response(HTTPResponse):
...
@@ -70,6 +72,16 @@ class Response(HTTPResponse):
The current implementation, however, should suffice for now.
The current implementation, however, should suffice for now.
"""
"""
# Because we can't predict what kind of thing we're customizing,
# we have to use delegation, rather than inheritence to do the
# customization.
def
__init__
(
self
,
real
):
self
.
__dict__
[
'_real'
]
=
real
def
__getattr__
(
self
,
name
):
return
getattr
(
self
.
_real
,
name
)
def
__setattr__
(
self
,
name
,
v
):
return
setattr
(
self
.
_real
,
name
,
v
)
def
__delattr__
(
self
,
name
):
return
delattr
(
self
.
_real
,
name
)
def
setBody
(
self
,
body
,
title
=
''
,
is_error
=
0
,
bogus_str_search
=
None
):
def
setBody
(
self
,
body
,
title
=
''
,
is_error
=
0
,
bogus_str_search
=
None
):
if
isinstance
(
body
,
xmlrpclib
.
Fault
):
if
isinstance
(
body
,
xmlrpclib
.
Fault
):
# Convert Fault object to XML-RPC response.
# Convert Fault object to XML-RPC response.
...
@@ -80,9 +92,8 @@ class Response(HTTPResponse):
...
@@ -80,9 +92,8 @@ class Response(HTTPResponse):
# everything to a string first.
# everything to a string first.
body
=
xmlrpclib
.
dumps
((
body
,),
methodresponse
=
1
)
body
=
xmlrpclib
.
dumps
((
body
,),
methodresponse
=
1
)
# Set our body to the XML-RPC message, and fix our MIME type.
# Set our body to the XML-RPC message, and fix our MIME type.
HTTPResponse
.
setBody
(
self
,
body
)
self
.
_real
.
setBody
(
body
)
self
.
setHeader
(
'content-type'
,
'text/xml'
)
self
.
_real
.
setHeader
(
'content-type'
,
'text/xml'
)
print
'setBody'
,
body
return
self
return
self
def
exception
(
self
,
fatal
=
0
,
info
=
None
,
def
exception
(
self
,
fatal
=
0
,
info
=
None
,
...
@@ -113,7 +124,8 @@ class Response(HTTPResponse):
...
@@ -113,7 +124,8 @@ class Response(HTTPResponse):
# Do the damage.
# Do the damage.
self
.
setBody
(
f
)
self
.
setBody
(
f
)
print
'Exception'
,
f
self
.
_real
.
setStatus
(
200
)
self
.
setStatus
(
200
)
return
tb
return
tb
response
=
Response
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