Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: third_party/cherrypy/lib/xmlrpcutil.py

Issue 9368042: Add CherryPy to third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build/
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/cherrypy/lib/static.py ('k') | third_party/cherrypy/process/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 import sys
2
3 import cherrypy
4 from cherrypy._cpcompat import ntob
5
6 def get_xmlrpclib():
7 try:
8 import xmlrpc.client as x
9 except ImportError:
10 import xmlrpclib as x
11 return x
12
13 def process_body():
14 """Return (params, method) from request body."""
15 try:
16 return get_xmlrpclib().loads(cherrypy.request.body.read())
17 except Exception:
18 return ('ERROR PARAMS', ), 'ERRORMETHOD'
19
20
21 def patched_path(path):
22 """Return 'path', doctored for RPC."""
23 if not path.endswith('/'):
24 path += '/'
25 if path.startswith('/RPC2/'):
26 # strip the first /rpc2
27 path = path[5:]
28 return path
29
30
31 def _set_response(body):
32 # The XML-RPC spec (http://www.xmlrpc.com/spec) says:
33 # "Unless there's a lower-level error, always return 200 OK."
34 # Since Python's xmlrpclib interprets a non-200 response
35 # as a "Protocol Error", we'll just return 200 every time.
36 response = cherrypy.response
37 response.status = '200 OK'
38 response.body = ntob(body, 'utf-8')
39 response.headers['Content-Type'] = 'text/xml'
40 response.headers['Content-Length'] = len(body)
41
42
43 def respond(body, encoding='utf-8', allow_none=0):
44 xmlrpclib = get_xmlrpclib()
45 if not isinstance(body, xmlrpclib.Fault):
46 body = (body,)
47 _set_response(xmlrpclib.dumps(body, methodresponse=1,
48 encoding=encoding,
49 allow_none=allow_none))
50
51 def on_error(*args, **kwargs):
52 body = str(sys.exc_info()[1])
53 xmlrpclib = get_xmlrpclib()
54 _set_response(xmlrpclib.dumps(xmlrpclib.Fault(1, body)))
55
OLDNEW
« no previous file with comments | « third_party/cherrypy/lib/static.py ('k') | third_party/cherrypy/process/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698