Merge lp:~elachuni/weblive/pep8-client into lp:weblive

Proposed by Anthony Lenton
Status: Merged
Merged at revision: 161
Proposed branch: lp:~elachuni/weblive/pep8-client
Merge into: lp:weblive
Diff against target: 286 lines (+85/-60)
1 file modified
client/weblive.py (+85/-60)
To merge this branch: bzr merge lp:~elachuni/weblive/pep8-client
Reviewer Review Type Date Requested Status
Registry Administrators Pending
Review via email: mp+98195@code.launchpad.net

Description of the change

A branch with whitespace fixes so that client/weblive.py passes the pep8 test.

In software-center we're adding a test that checks code statically using http://pypi.python.org/pypi/pep8
Currently client/weblive.py is copied in as weblive_pristine.py, but will need to have whitespace fixes applied after importing so that it passes this test. It would be nice if weblive's version were already pep8-compliant.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Could somone please have a look at this? Stephane :) ?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client/weblive.py'
2--- client/weblive.py 2011-05-04 01:33:40 +0000
3+++ client/weblive.py 2012-03-19 13:15:25 +0000
4@@ -1,5 +1,8 @@
5 #!/usr/bin/python
6-import urllib, urllib2, json
7+import json
8+import urllib
9+import urllib2
10+
11
12 class WebLiveJsonError(Exception):
13 def __init__(self, value):
14@@ -8,6 +11,7 @@
15 def __str__(self):
16 return repr(self.value)
17
18+
19 class WebLiveError(Exception):
20 def __init__(self, value):
21 self.value = value
22@@ -15,19 +19,23 @@
23 def __str__(self):
24 return repr(self.value)
25
26+
27 class WebLiveLocale(object):
28 def __init__(self, locale, description):
29 self.locale = locale
30 self.description = description
31
32+
33 class WebLivePackage(object):
34 def __init__(self, pkgname, version, autoinstall):
35 self.pkgname = pkgname
36 self.version = version
37 self.autoinstall = autoinstall
38
39+
40 class WebLiveServer(object):
41- def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall):
42+ def __init__(self, name, title, description, timelimit, userlimit,
43+ users, autoinstall):
44 self.name = name
45 self.title = title
46 self.description = description
47@@ -37,77 +45,94 @@
48 self.autoinstall = autoinstall
49
50 def __repr__(self):
51- return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s" % (
52- self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall)
53+ return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, "
54+ "current_users=%s, autoinstall=%s") % (
55+ self.name, self.title, self.description, self.timelimit,
56+ self.userlimit, self.current_users, self.autoinstall)
57+
58
59 class WebLiveEverythingServer(WebLiveServer):
60- def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall, locales, packages):
61+ def __init__(self, name, title, description, timelimit, userlimit,
62+ users, autoinstall, locales, packages):
63 self.locales = [WebLiveLocale(x[0], x[1]) for x in locales]
64 self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages]
65
66- WebLiveServer.__init__(self, name, title, description, timelimit, userlimit, users, autoinstall)
67+ WebLiveServer.__init__(self, name, title, description, timelimit,
68+ userlimit, users, autoinstall)
69
70 def __repr__(self):
71- return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s" % (
72- self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall, len(self.locales), len(self.packages))
73+ return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, "
74+ "current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s") % (
75+ self.name, self.title, self.description, self.timelimit,
76+ self.userlimit, self.current_users, self.autoinstall,
77+ len(self.locales), len(self.packages))
78+
79
80 class WebLive:
81- def __init__(self,url,as_object=False):
82- self.url=url
83- self.as_object=as_object
84+ def __init__(self, url, as_object=False):
85+ self.url = url
86+ self.as_object = as_object
87
88- def do_query(self,query):
89- page=urllib2.Request(self.url,urllib.urlencode({'query':json.dumps(query)}))
90+ def do_query(self, query):
91+ page = urllib2.Request(self.url, urllib.urlencode(
92+ {'query': json.dumps(query)}))
93
94 try:
95- response=urllib2.urlopen(page)
96+ response = urllib2.urlopen(page)
97 except urllib2.HTTPError, e:
98 raise WebLiveJsonError("HTTP return code: %s" % e.code)
99 except urllib2.URLError, e:
100 raise WebLiveJsonError("Failed to reach server: %s" % e.reason)
101
102 try:
103- reply=json.loads(response.read())
104+ reply = json.loads(response.read())
105 except ValueError:
106 raise WebLiveJsonError("Returned json object is invalid.")
107
108 if reply['status'] != 'ok':
109 if reply['message'] == -1:
110- raise WebliveJsonError("Missing 'action' field in query.")
111+ raise WebLiveJsonError("Missing 'action' field in query.")
112 elif reply['message'] == -2:
113 raise WebLiveJsonError("Missing parameter")
114 elif reply['message'] == -3:
115- raise WebliveJsonError("Function '%s' isn't exported over JSON." % query['action'])
116+ raise WebLiveJsonError("Function '%s' isn't exported "
117+ "over JSON." % query['action'])
118 else:
119- raise WebLiveJsonError("Unknown error code: %s" % reply['message'])
120+ raise WebLiveJsonError("Unknown error code: %s" %
121+ reply['message'])
122
123 if 'message' not in reply:
124 raise WebLiveJsonError("Invalid json reply")
125
126 return reply
127
128- def create_user(self,serverid,username,fullname,password,session,locale):
129- query={}
130- query['action']='create_user'
131- query['serverid']=serverid
132- query['username']=username
133- query['fullname']=fullname
134- query['password']=password
135- query['session']=session
136- query['locale']=locale
137- reply=self.do_query(query)
138+ def create_user(self, serverid, username, fullname, password,
139+ session, locale):
140+ query = {}
141+ query['action'] = 'create_user'
142+ query['serverid'] = serverid
143+ query['username'] = username
144+ query['fullname'] = fullname
145+ query['password'] = password
146+ query['session'] = session
147+ query['locale'] = locale
148+ reply = self.do_query(query)
149
150 if type(reply['message']) != type([]):
151 if reply['message'] == 1:
152 raise WebLiveError("Reached user limit, return false.")
153 elif reply['message'] == 2:
154- raise WebLiveError("Different user with same username already exists.")
155+ raise WebLiveError("Different user with same username "
156+ "already exists.")
157 elif reply['message'] == 3:
158- raise WebLiveError("Invalid fullname, must only contain alphanumeric characters and spaces.")
159+ raise WebLiveError("Invalid fullname, must only contain "
160+ "alphanumeric characters and spaces.")
161 elif reply['message'] == 4:
162- raise WebLiveError("Invalid login, must only contain lowercase letters.")
163+ raise WebLiveError("Invalid login, must only contain "
164+ "lowercase letters.")
165 elif reply['message'] == 5:
166- raise WebLiveError("Invalid password, must contain only alphanumeric characters.")
167+ raise WebLiveError("Invalid password, must contain only "
168+ "alphanumeric characters.")
169 elif reply['message'] == 7:
170 raise WebLiveError("Invalid server: %s" % serverid)
171 else:
172@@ -116,20 +141,20 @@
173 return reply['message']
174
175 def list_everything(self):
176- query={}
177- query['action']='list_everything'
178- reply=self.do_query(query)
179+ query = {}
180+ query['action'] = 'list_everything'
181+ reply = self.do_query(query)
182
183 if type(reply['message']) != type({}):
184 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
185- % (type({}),type(reply['message'])))
186+ % (type({}), type(reply['message'])))
187
188 if not self.as_object:
189 return reply['message']
190 else:
191- servers=[]
192+ servers = []
193 for server in reply['message']:
194- attr=reply['message'][server]
195+ attr = reply['message'][server]
196 servers.append(WebLiveEverythingServer(
197 server,
198 attr['title'],
199@@ -142,15 +167,15 @@
200 attr['packages']))
201 return servers
202
203- def list_locales(self,serverid):
204- query={}
205- query['action']='list_locales'
206- query['serverid']=serverid
207- reply=self.do_query(query)
208+ def list_locales(self, serverid):
209+ query = {}
210+ query['action'] = 'list_locales'
211+ query['serverid'] = serverid
212+ reply = self.do_query(query)
213
214 if type(reply['message']) != type([]):
215 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
216- % (type({}),type(reply['message'])))
217+ % (type({}), type(reply['message'])))
218
219 if not self.as_object:
220 return reply['message']
221@@ -158,28 +183,28 @@
222 return [WebLiveLocale(x[0], x[1]) for x in reply['message']]
223
224 def list_package_blacklist(self):
225- query={}
226- query['action']='list_package_blacklist'
227- reply=self.do_query(query)
228+ query = {}
229+ query['action'] = 'list_package_blacklist'
230+ reply = self.do_query(query)
231
232 if type(reply['message']) != type([]):
233 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
234- % (type({}),type(reply['message'])))
235+ % (type({}), type(reply['message'])))
236
237 if not self.as_object:
238 return reply['message']
239 else:
240 return [WebLivePackage(x, None, None) for x in reply['message']]
241
242- def list_packages(self,serverid):
243- query={}
244- query['action']='list_packages'
245- query['serverid']=serverid
246- reply=self.do_query(query)
247+ def list_packages(self, serverid):
248+ query = {}
249+ query['action'] = 'list_packages'
250+ query['serverid'] = serverid
251+ reply = self.do_query(query)
252
253 if type(reply['message']) != type([]):
254 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
255- % (type({}),type(reply['message'])))
256+ % (type({}), type(reply['message'])))
257
258 if not self.as_object:
259 return reply['message']
260@@ -187,20 +212,20 @@
261 return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']]
262
263 def list_servers(self):
264- query={}
265- query['action']='list_servers'
266- reply=self.do_query(query)
267+ query = {}
268+ query['action'] = 'list_servers'
269+ reply = self.do_query(query)
270
271 if type(reply['message']) != type({}):
272 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
273- % (type({}),type(reply['message'])))
274+ % (type({}), type(reply['message'])))
275
276 if not self.as_object:
277 return reply['message']
278 else:
279- servers=[]
280+ servers = []
281 for server in reply['message']:
282- attr=reply['message'][server]
283+ attr = reply['message'][server]
284 servers.append(WebLiveServer(
285 server,
286 attr['title'],

Subscribers

People subscribed via source and target branches