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
=== modified file 'client/weblive.py'
--- client/weblive.py 2011-05-04 01:33:40 +0000
+++ client/weblive.py 2012-03-19 13:15:25 +0000
@@ -1,5 +1,8 @@
1#!/usr/bin/python1#!/usr/bin/python
2import urllib, urllib2, json2import json
3import urllib
4import urllib2
5
36
4class WebLiveJsonError(Exception):7class WebLiveJsonError(Exception):
5 def __init__(self, value):8 def __init__(self, value):
@@ -8,6 +11,7 @@
8 def __str__(self):11 def __str__(self):
9 return repr(self.value)12 return repr(self.value)
1013
14
11class WebLiveError(Exception):15class WebLiveError(Exception):
12 def __init__(self, value):16 def __init__(self, value):
13 self.value = value17 self.value = value
@@ -15,19 +19,23 @@
15 def __str__(self):19 def __str__(self):
16 return repr(self.value)20 return repr(self.value)
1721
22
18class WebLiveLocale(object):23class WebLiveLocale(object):
19 def __init__(self, locale, description):24 def __init__(self, locale, description):
20 self.locale = locale25 self.locale = locale
21 self.description = description26 self.description = description
2227
28
23class WebLivePackage(object):29class WebLivePackage(object):
24 def __init__(self, pkgname, version, autoinstall):30 def __init__(self, pkgname, version, autoinstall):
25 self.pkgname = pkgname31 self.pkgname = pkgname
26 self.version = version32 self.version = version
27 self.autoinstall = autoinstall33 self.autoinstall = autoinstall
2834
35
29class WebLiveServer(object):36class WebLiveServer(object):
30 def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall):37 def __init__(self, name, title, description, timelimit, userlimit,
38 users, autoinstall):
31 self.name = name39 self.name = name
32 self.title = title40 self.title = title
33 self.description = description41 self.description = description
@@ -37,77 +45,94 @@
37 self.autoinstall = autoinstall45 self.autoinstall = autoinstall
3846
39 def __repr__(self):47 def __repr__(self):
40 return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s" % (48 return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, "
41 self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall)49 "current_users=%s, autoinstall=%s") % (
50 self.name, self.title, self.description, self.timelimit,
51 self.userlimit, self.current_users, self.autoinstall)
52
4253
43class WebLiveEverythingServer(WebLiveServer):54class WebLiveEverythingServer(WebLiveServer):
44 def __init__(self, name, title, description, timelimit, userlimit, users, autoinstall, locales, packages):55 def __init__(self, name, title, description, timelimit, userlimit,
56 users, autoinstall, locales, packages):
45 self.locales = [WebLiveLocale(x[0], x[1]) for x in locales]57 self.locales = [WebLiveLocale(x[0], x[1]) for x in locales]
46 self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages]58 self.packages = [WebLivePackage(x[0], x[1], x[2]) for x in packages]
4759
48 WebLiveServer.__init__(self, name, title, description, timelimit, userlimit, users, autoinstall)60 WebLiveServer.__init__(self, name, title, description, timelimit,
61 userlimit, users, autoinstall)
4962
50 def __repr__(self):63 def __repr__(self):
51 return "[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s" % (64 return ("[WebLiveServer: %s (%s - %s), timelimit=%s, userlimit=%s, "
52 self.name, self.title, self.description, self.timelimit, self.userlimit, self.current_users, self.autoinstall, len(self.locales), len(self.packages))65 "current_users=%s, autoinstall=%s, nr_locales=%s, nr_pkgs=%s") % (
66 self.name, self.title, self.description, self.timelimit,
67 self.userlimit, self.current_users, self.autoinstall,
68 len(self.locales), len(self.packages))
69
5370
54class WebLive:71class WebLive:
55 def __init__(self,url,as_object=False):72 def __init__(self, url, as_object=False):
56 self.url=url73 self.url = url
57 self.as_object=as_object74 self.as_object = as_object
5875
59 def do_query(self,query):76 def do_query(self, query):
60 page=urllib2.Request(self.url,urllib.urlencode({'query':json.dumps(query)}))77 page = urllib2.Request(self.url, urllib.urlencode(
78 {'query': json.dumps(query)}))
6179
62 try:80 try:
63 response=urllib2.urlopen(page)81 response = urllib2.urlopen(page)
64 except urllib2.HTTPError, e:82 except urllib2.HTTPError, e:
65 raise WebLiveJsonError("HTTP return code: %s" % e.code)83 raise WebLiveJsonError("HTTP return code: %s" % e.code)
66 except urllib2.URLError, e:84 except urllib2.URLError, e:
67 raise WebLiveJsonError("Failed to reach server: %s" % e.reason)85 raise WebLiveJsonError("Failed to reach server: %s" % e.reason)
6886
69 try:87 try:
70 reply=json.loads(response.read())88 reply = json.loads(response.read())
71 except ValueError:89 except ValueError:
72 raise WebLiveJsonError("Returned json object is invalid.")90 raise WebLiveJsonError("Returned json object is invalid.")
7391
74 if reply['status'] != 'ok':92 if reply['status'] != 'ok':
75 if reply['message'] == -1:93 if reply['message'] == -1:
76 raise WebliveJsonError("Missing 'action' field in query.")94 raise WebLiveJsonError("Missing 'action' field in query.")
77 elif reply['message'] == -2:95 elif reply['message'] == -2:
78 raise WebLiveJsonError("Missing parameter")96 raise WebLiveJsonError("Missing parameter")
79 elif reply['message'] == -3:97 elif reply['message'] == -3:
80 raise WebliveJsonError("Function '%s' isn't exported over JSON." % query['action'])98 raise WebLiveJsonError("Function '%s' isn't exported "
99 "over JSON." % query['action'])
81 else:100 else:
82 raise WebLiveJsonError("Unknown error code: %s" % reply['message'])101 raise WebLiveJsonError("Unknown error code: %s" %
102 reply['message'])
83103
84 if 'message' not in reply:104 if 'message' not in reply:
85 raise WebLiveJsonError("Invalid json reply")105 raise WebLiveJsonError("Invalid json reply")
86106
87 return reply107 return reply
88108
89 def create_user(self,serverid,username,fullname,password,session,locale):109 def create_user(self, serverid, username, fullname, password,
90 query={}110 session, locale):
91 query['action']='create_user'111 query = {}
92 query['serverid']=serverid112 query['action'] = 'create_user'
93 query['username']=username113 query['serverid'] = serverid
94 query['fullname']=fullname114 query['username'] = username
95 query['password']=password115 query['fullname'] = fullname
96 query['session']=session116 query['password'] = password
97 query['locale']=locale117 query['session'] = session
98 reply=self.do_query(query)118 query['locale'] = locale
119 reply = self.do_query(query)
99120
100 if type(reply['message']) != type([]):121 if type(reply['message']) != type([]):
101 if reply['message'] == 1:122 if reply['message'] == 1:
102 raise WebLiveError("Reached user limit, return false.")123 raise WebLiveError("Reached user limit, return false.")
103 elif reply['message'] == 2:124 elif reply['message'] == 2:
104 raise WebLiveError("Different user with same username already exists.")125 raise WebLiveError("Different user with same username "
126 "already exists.")
105 elif reply['message'] == 3:127 elif reply['message'] == 3:
106 raise WebLiveError("Invalid fullname, must only contain alphanumeric characters and spaces.")128 raise WebLiveError("Invalid fullname, must only contain "
129 "alphanumeric characters and spaces.")
107 elif reply['message'] == 4:130 elif reply['message'] == 4:
108 raise WebLiveError("Invalid login, must only contain lowercase letters.")131 raise WebLiveError("Invalid login, must only contain "
132 "lowercase letters.")
109 elif reply['message'] == 5:133 elif reply['message'] == 5:
110 raise WebLiveError("Invalid password, must contain only alphanumeric characters.")134 raise WebLiveError("Invalid password, must contain only "
135 "alphanumeric characters.")
111 elif reply['message'] == 7:136 elif reply['message'] == 7:
112 raise WebLiveError("Invalid server: %s" % serverid)137 raise WebLiveError("Invalid server: %s" % serverid)
113 else:138 else:
@@ -116,20 +141,20 @@
116 return reply['message']141 return reply['message']
117142
118 def list_everything(self):143 def list_everything(self):
119 query={}144 query = {}
120 query['action']='list_everything'145 query['action'] = 'list_everything'
121 reply=self.do_query(query)146 reply = self.do_query(query)
122147
123 if type(reply['message']) != type({}):148 if type(reply['message']) != type({}):
124 raise WebLiveError("Invalid value, expected '%s' and got '%s'."149 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
125 % (type({}),type(reply['message'])))150 % (type({}), type(reply['message'])))
126151
127 if not self.as_object:152 if not self.as_object:
128 return reply['message']153 return reply['message']
129 else:154 else:
130 servers=[]155 servers = []
131 for server in reply['message']:156 for server in reply['message']:
132 attr=reply['message'][server]157 attr = reply['message'][server]
133 servers.append(WebLiveEverythingServer(158 servers.append(WebLiveEverythingServer(
134 server,159 server,
135 attr['title'],160 attr['title'],
@@ -142,15 +167,15 @@
142 attr['packages']))167 attr['packages']))
143 return servers168 return servers
144169
145 def list_locales(self,serverid):170 def list_locales(self, serverid):
146 query={}171 query = {}
147 query['action']='list_locales'172 query['action'] = 'list_locales'
148 query['serverid']=serverid173 query['serverid'] = serverid
149 reply=self.do_query(query)174 reply = self.do_query(query)
150175
151 if type(reply['message']) != type([]):176 if type(reply['message']) != type([]):
152 raise WebLiveError("Invalid value, expected '%s' and got '%s'."177 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
153 % (type({}),type(reply['message'])))178 % (type({}), type(reply['message'])))
154179
155 if not self.as_object:180 if not self.as_object:
156 return reply['message']181 return reply['message']
@@ -158,28 +183,28 @@
158 return [WebLiveLocale(x[0], x[1]) for x in reply['message']]183 return [WebLiveLocale(x[0], x[1]) for x in reply['message']]
159184
160 def list_package_blacklist(self):185 def list_package_blacklist(self):
161 query={}186 query = {}
162 query['action']='list_package_blacklist'187 query['action'] = 'list_package_blacklist'
163 reply=self.do_query(query)188 reply = self.do_query(query)
164189
165 if type(reply['message']) != type([]):190 if type(reply['message']) != type([]):
166 raise WebLiveError("Invalid value, expected '%s' and got '%s'."191 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
167 % (type({}),type(reply['message'])))192 % (type({}), type(reply['message'])))
168193
169 if not self.as_object:194 if not self.as_object:
170 return reply['message']195 return reply['message']
171 else:196 else:
172 return [WebLivePackage(x, None, None) for x in reply['message']]197 return [WebLivePackage(x, None, None) for x in reply['message']]
173198
174 def list_packages(self,serverid):199 def list_packages(self, serverid):
175 query={}200 query = {}
176 query['action']='list_packages'201 query['action'] = 'list_packages'
177 query['serverid']=serverid202 query['serverid'] = serverid
178 reply=self.do_query(query)203 reply = self.do_query(query)
179204
180 if type(reply['message']) != type([]):205 if type(reply['message']) != type([]):
181 raise WebLiveError("Invalid value, expected '%s' and got '%s'."206 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
182 % (type({}),type(reply['message'])))207 % (type({}), type(reply['message'])))
183208
184 if not self.as_object:209 if not self.as_object:
185 return reply['message']210 return reply['message']
@@ -187,20 +212,20 @@
187 return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']]212 return [WebLivePackage(x[0], x[1], x[2]) for x in reply['message']]
188213
189 def list_servers(self):214 def list_servers(self):
190 query={}215 query = {}
191 query['action']='list_servers'216 query['action'] = 'list_servers'
192 reply=self.do_query(query)217 reply = self.do_query(query)
193218
194 if type(reply['message']) != type({}):219 if type(reply['message']) != type({}):
195 raise WebLiveError("Invalid value, expected '%s' and got '%s'."220 raise WebLiveError("Invalid value, expected '%s' and got '%s'."
196 % (type({}),type(reply['message'])))221 % (type({}), type(reply['message'])))
197222
198 if not self.as_object:223 if not self.as_object:
199 return reply['message']224 return reply['message']
200 else:225 else:
201 servers=[]226 servers = []
202 for server in reply['message']:227 for server in reply['message']:
203 attr=reply['message'][server]228 attr = reply['message'][server]
204 servers.append(WebLiveServer(229 servers.append(WebLiveServer(
205 server,230 server,
206 attr['title'],231 attr['title'],

Subscribers

People subscribed via source and target branches