0.4.4
by Martin Pool
Start forming xmlrpc requests |
1 |
# Copyright (C) 2006 by Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
||
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
18 |
from urlparse import urlsplit, urlunsplit |
19 |
from urllib import unquote, quote |
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
20 |
import xmlrpclib |
21 |
## from twisted.web import xmlrpc
|
|
22 |
||
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
23 |
|
24 |
# TODO: use last component of path as default id?
|
|
25 |
||
0.4.4
by Martin Pool
Start forming xmlrpc requests |
26 |
class BranchRegistrationRequest(object): |
27 |
"""Request to tell Launchpad about a bzr branch."""
|
|
28 |
||
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
29 |
_methodname = 'register_branch' |
30 |
||
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
31 |
# NB this should always end in a slash to avoid xmlrpclib appending
|
32 |
# '/RPC2'
|
|
33 |
DEFAULT_SERVICE_URL = 'http://xmlrpc.launchpad.net/branch/' |
|
34 |
||
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
35 |
def __init__(self, branch_url, branch_id): |
0.4.4
by Martin Pool
Start forming xmlrpc requests |
36 |
self.branch_url = branch_url |
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
37 |
self.branch_id = branch_id |
0.4.9
by Martin Pool
Don't transmit non-standard xmlrpc <nil> value. |
38 |
self.branch_description = '' |
39 |
self.owner_email = '' |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
40 |
self.service_url = self.DEFAULT_SERVICE_URL |
41 |
self.registrant = 'testuser@launchpad.net' |
|
42 |
self.password = 'testpassword' |
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
43 |
|
44 |
def _request_params(self): |
|
45 |
"""Return xmlrpc request parameters"""
|
|
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
46 |
# This must match the parameter tuple expected by Launchpad for this
|
47 |
# method
|
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
48 |
return (self.branch_url, |
0.4.6
by Martin Pool
Put the rest of the parameters into the registration request. |
49 |
self.branch_id, |
50 |
self.branch_description, |
|
51 |
self.owner_email, |
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
52 |
)
|
53 |
||
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
54 |
def submit(self, transport=None): |
55 |
"""Submit registration request to the server.
|
|
56 |
|
|
57 |
The particular server to use is set in self.service_url; this
|
|
58 |
should only need to be changed for testing.
|
|
0.4.4
by Martin Pool
Start forming xmlrpc requests |
59 |
|
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
60 |
:param transport: If non-null, use a special xmlrpclib.Transport
|
61 |
to send the request. This has no connection to bzrlib
|
|
62 |
Transports.
|
|
63 |
"""
|
|
64 |
# auth info must be in url
|
|
65 |
scheme, hostinfo, path = urlsplit(self.service_url)[:3] |
|
66 |
assert '@' not in hostinfo |
|
67 |
hostinfo = '%s:%s@%s' % (quote(self.registrant), |
|
68 |
quote(self.password), |
|
69 |
hostinfo) |
|
70 |
url = urlunsplit((scheme, hostinfo, path, '', '')) |
|
0.4.9
by Martin Pool
Don't transmit non-standard xmlrpc <nil> value. |
71 |
proxy = xmlrpclib.ServerProxy(url, transport=transport) |
0.4.7
by Martin Pool
Start making provision to test using a mock xmlrpc transport. |
72 |
proxy.register_branch(*self._request_params()) |
0.4.4
by Martin Pool
Start forming xmlrpc requests |
73 |