|
Revision 1102
(checked in by fumanchu, 3 years ago)
|
Dispatch and config lookup now happens as early as possible, once per request (unless InternalRedirect? is raised). Also moved the logging code out of _cputil and into __init__. xmlrpc still needs fixed so it doesn't re-write path_info.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
import sys |
|---|
| 2 |
import xmlrpclib |
|---|
| 3 |
|
|---|
| 4 |
import cherrypy |
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
def process_body(): |
|---|
| 8 |
"""Return (params, method) from request body.""" |
|---|
| 9 |
try: |
|---|
| 10 |
return xmlrpclib.loads(cherrypy.request.body.read()) |
|---|
| 11 |
except Exception: |
|---|
| 12 |
return ('ERROR PARAMS', ), 'ERRORMETHOD' |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
def patched_path(path): |
|---|
| 16 |
"""Return 'path', doctored for RPC.""" |
|---|
| 17 |
if not path.endswith('/'): |
|---|
| 18 |
path += '/' |
|---|
| 19 |
if path.startswith('/RPC2/'): |
|---|
| 20 |
|
|---|
| 21 |
path = path[5:] |
|---|
| 22 |
return path |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
def _set_response(body): |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
response = cherrypy.response |
|---|
| 31 |
response.status = '200 OK' |
|---|
| 32 |
response.body = body |
|---|
| 33 |
response.headers['Content-Type'] = 'text/xml' |
|---|
| 34 |
response.headers['Content-Length'] = len(body) |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
def respond(body, encoding='utf-8', allow_none=0): |
|---|
| 38 |
_set_response(xmlrpclib.dumps((body,), methodresponse=1, |
|---|
| 39 |
encoding=encoding, |
|---|
| 40 |
allow_none=allow_none)) |
|---|
| 41 |
|
|---|
| 42 |
def on_error(): |
|---|
| 43 |
body = str(sys.exc_info()[1]) |
|---|
| 44 |
_set_response(xmlrpclib.dumps(xmlrpclib.Fault(1, body))) |
|---|
| 45 |
|
|---|