Line 0
Link Here
|
|
|
1 |
Obtained-From: https://bitbucket.org/leafstorm/flask-xml-rpc/pull-requests/2/added-python3-support-alongside-python2/commits |
2 |
|
3 |
# HG changeset patch |
4 |
# User Maxime "Pepe_" Buquet <pep+code@bouah.net> |
5 |
# Date 1425540278 -32400 |
6 |
# Node ID 9da0e2bcfe5e32a1db95b639f41f67d3e1a43b80 |
7 |
# Parent 06a6c81e3a98ecb647e729e239f5de11814901d3 |
8 |
Added Python3 support alongside Python2 |
9 |
|
10 |
--- flaskext/xmlrpc.py.orig 2015-03-05 00:00:00 UTC |
11 |
+++ flaskext/xmlrpc.py |
12 |
@@ -10,9 +10,16 @@ |
13 |
""" |
14 |
|
15 |
from flask import request, current_app |
16 |
-from SimpleXMLRPCServer import SimpleXMLRPCDispatcher as Dispatcher |
17 |
import sys |
18 |
-import xmlrpclib |
19 |
+ |
20 |
+if sys.version_info[0] == 2: |
21 |
+ from SimpleXMLRPCServer import SimpleXMLRPCDispatcher as Dispatcher |
22 |
+ import xmlrpclib |
23 |
+ string_types = basestring |
24 |
+else: |
25 |
+ from xmlrpc.server import SimpleXMLRPCDispatcher as Dispatcher |
26 |
+ import xmlrpc.client as xmlrpclib |
27 |
+ string_types = str |
28 |
|
29 |
Fault = xmlrpclib.Fault |
30 |
|
31 |
@@ -97,7 +104,7 @@ |
32 |
If not given, the function's :obj:`__name__` attribute |
33 |
will be used. |
34 |
""" |
35 |
- if isinstance(function, basestring): |
36 |
+ if isinstance(function, string_types): |
37 |
return lambda fn: self.register_function(fn, function) |
38 |
return Dispatcher.register_function(self, function, name) |
39 |
|
40 |
@@ -198,7 +205,7 @@ |
41 |
If not given, the function's :obj:`__name__` attribute |
42 |
will be used. |
43 |
""" |
44 |
- if isinstance(function, basestring): |
45 |
+ if isinstance(function, string_types): |
46 |
return lambda fn: self.register_function(fn, function) |
47 |
if name is None: |
48 |
name = function.__name__ |
49 |
@@ -249,7 +256,8 @@ |
50 |
""" |
51 |
try: |
52 |
return xmlrpclib.loads(response)[0][0] |
53 |
- except Fault, fault: |
54 |
+ except Fault: |
55 |
+ _, fault = sys.exec_info()[:2] |
56 |
return fault |