1
1
import collections
2
2
import sys
3
+ import urllib .parse
3
4
4
5
from wordpress_xmlrpc .compat import xmlrpc_client , dict_type
5
6
from wordpress_xmlrpc .exceptions import ServerConnectionError , UnsupportedXmlrpcMethodError , InvalidCredentialsError , XmlrpcDisabledError
6
7
7
8
8
9
class Client (object ):
10
+
9
11
"""
10
12
Connection to a WordPress XML-RPC API endpoint.
11
13
12
14
To execute XML-RPC methods, pass an instance of an
13
15
`XmlrpcMethod`-derived class to `Client`'s `call` method.
14
16
"""
15
17
16
- def __init__ (self , url , username , password , blog_id = 0 , transport = None , verbose = False ):
18
+ def __init__ (self , url , username , password , blog_id = 0 , transport = None , verbose = False , safe_transport = None ):
17
19
self .url = url
18
20
self .username = username
19
21
self .password = password
20
22
self .blog_id = blog_id
21
23
22
- self .setup (transport , verbose )
23
-
24
+ self .setup (transport , verbose , safe_transport )
24
25
25
- def setup (self , transport , verbose ):
26
+ def setup (self , transport , verbose , safe_transport ):
26
27
try :
27
28
self .server = xmlrpc_client .ServerProxy (self .url , allow_none = True , transport = transport ,
28
- verbose = verbose )
29
+ verbose = verbose )
29
30
self .supported_methods = self .server .mt .supportedMethods ()
30
31
except xmlrpc_client .ProtocolError :
31
32
e = sys .exc_info ()[1 ]
@@ -34,7 +35,12 @@ def setup(self, transport, verbose):
34
35
self .url = e .headers ['location' ]
35
36
except KeyError :
36
37
self .url = e .headers ['Location' ]
37
- self .setup (transport , verbose )
38
+
39
+ protocol , _ = urllib .parse .splittype (self .url )
40
+ if protocol == 'https' :
41
+ transport = safe_transport
42
+
43
+ self .setup (transport , verbose , None )
38
44
else :
39
45
raise ServerConnectionError (repr (e ))
40
46
@@ -59,6 +65,7 @@ def call(self, method):
59
65
60
66
61
67
class XmlrpcMethod (object ):
68
+
62
69
"""
63
70
Base class for XML-RPC methods.
64
71
@@ -80,10 +87,12 @@ def __init__(self, *args, **kwargs):
80
87
if self .optional_args :
81
88
max_num_args = len (self .method_args ) + len (self .optional_args )
82
89
if not (len (self .method_args ) <= len (args ) <= max_num_args ):
83
- raise ValueError ("Invalid number of parameters to %s" % self .method_name )
90
+ raise ValueError (
91
+ "Invalid number of parameters to %s" % self .method_name )
84
92
else :
85
93
if len (args ) != len (self .method_args ):
86
- raise ValueError ("Invalid number of parameters to %s" % self .method_name )
94
+ raise ValueError (
95
+ "Invalid number of parameters to %s" % self .method_name )
87
96
88
97
for i , arg_name in enumerate (self .method_args ):
89
98
setattr (self , arg_name , args [i ])
@@ -144,13 +153,15 @@ def process_result(self, raw_result):
144
153
145
154
146
155
class AnonymousMethod (XmlrpcMethod ):
156
+
147
157
"""
148
158
An XML-RPC method for which no authentication is required.
149
159
"""
150
160
pass
151
161
152
162
153
163
class AuthenticatedMethod (XmlrpcMethod ):
164
+
154
165
"""
155
166
An XML-RPC method for which user authentication is required.
156
167
0 commit comments