Skip to content

Commit ecdc9a6

Browse files
committed
Update advanced script to python3; other doc updates
1 parent 0e2fbc8 commit ecdc9a6

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

doc/xmlrpc.txt

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ server (such as Apache or lighttpd) that provide SSL.
7979

8080
Client API
8181
----------
82-
The server currently implements four methods. Each method requires
83-
that the user provide a username and password in the HTTP
82+
The server currently implements seven methods/commands. Each method
83+
requires that the user provide a username and password in the HTTP
8484
authorization header in order to authenticate the request against the
8585
tracker.
8686

@@ -128,7 +128,8 @@ filter arguments: *classname, list or None, attributes*
128128
``list`` is a list of ids to filter. It can be set to None to run
129129
filter over all values (requires ``allow_none=True`` when
130130
instantiating the ServerProxy). The ``attributes`` are given as a
131-
dictionary of name value pairs to search for. See also :ref:`query-tracker`.
131+
dictionary of name value pairs to search for. See also
132+
:ref:`query-tracker`.
132133
======= ====================================================================
133134

134135
sample python client
@@ -173,35 +174,45 @@ stronger CSRF detection methods. It also generates a fault message
173174
from the server and reports it. Note if you are using http rather than
174175
https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport::
175176

176-
import xmlrpclib
177+
try:
178+
from xmlrpc import client as xmlrpclib # python 3
179+
except ImportError:
180+
import xmlrpclib # python 2
181+
182+
hostname="localhost"
183+
path="/demo"
184+
user_pw="admin:admin"
177185

178186
class SpecialTransport(xmlrpclib.SafeTransport):
179187

180-
def send_content(self, connection, request_body):
188+
def send_content(self, connection, request_body):
181189

182-
connection.putheader("Referer", "https://localhost/demo/")
183-
connection.putheader("Origin", "https://localhost")
184-
connection.putheader("X-Requested-With", "XMLHttpRequest")
190+
connection.putheader("Referer", "https://%s%s/"%(hostname, path))
191+
connection.putheader("Origin", "https://%s"%hostname)
192+
connection.putheader("X-Requested-With", "XMLHttpRequest")
185193

186-
connection.putheader("Content-Type", "text/xml")
187-
connection.putheader("Content-Length", str(len(request_body)))
188-
connection.endheaders()
189-
if request_body:
190-
connection.send(request_body)
194+
connection.putheader("Content-Type", "text/xml")
195+
connection.putheader("Content-Length", str(len(request_body)))
196+
connection.endheaders()
197+
if request_body:
198+
connection.send(request_body)
191199

192200
roundup_server = xmlrpclib.ServerProxy(
193-
'https://admin:admin@localhost/demo/xmlrpc',
194-
transport=SpecialTransport(),
195-
verbose=False,
196-
allow_none=True)
201+
'https://%s@%s%s/xmlrpc'%(user_pw,hostname,path),
202+
transport=SpecialTransport(),
203+
verbose=False,
204+
allow_none=True)
197205

198206
print(roundup_server.schema())
199207
print(roundup_server.display('user2', 'username'))
200208
print(roundup_server.display('issue1', 'status'))
201209
print(roundup_server.filter('user',['1','2','3'],{'username':'demo'}))
202210

203-
# this will fail with a fault
204-
try:
205-
print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'}))
206-
except Exception as msg:
207-
print(msg)
211+
# this will fail with a fault
212+
try:
213+
print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'}))
214+
except Exception as msg:
215+
print(msg)
216+
217+
modify this script replacing the hostname, path and user_pw with those
218+
for your tracker.

0 commit comments

Comments
 (0)