Merge lp:~guydmann/anonplus/guydmann_dev into lp:anonplus

Proposed by Guy Mann
Status: Merged
Approved by: aj00200
Approved revision: 204
Merged at revision: 204
Proposed branch: lp:~guydmann/anonplus/guydmann_dev
Merge into: lp:anonplus
Diff against target: 181 lines (+80/-41)
2 files modified
src/setup.py (+1/-1)
src/uis/web/handler.py (+79/-40)
To merge this branch: bzr merge lp:~guydmann/anonplus/guydmann_dev
Reviewer Review Type Date Requested Status
aj00200 Approve
Review via email: mp+94911@code.launchpad.net

Description of the change

bug fix for #938221 Old versions of PyCrypto do not have Crypto.version_info

refactoring of the uis/web/handler.py to use an array to store the list of requests available and moving the code for those requests into separate functions.

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

The code looks acceptable. The fix for bug #938221 is perfect. However, the additional web-ui code in r204 is not needed as the web-ui is being rewritten anyways.

I will try to include this new structure in the web-ui as I rewrite it.

Thanks for your help.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/setup.py'
2--- src/setup.py 2012-02-22 00:45:53 +0000
3+++ src/setup.py 2012-02-28 05:50:23 +0000
4@@ -30,7 +30,7 @@
5
6 # Check PyCrypto version basics - require v2.4.x or higher
7 # The version in PyCrypto is incorrect. See bug #892944
8-if Crypto.version_info[0] < 2 or Crypto.version_info[1] < 1:
9+if not hasattr(Crypto,'version_info') or Crypto.version_info[0] < 2 or Crypto.version_info[1] < 1:
10 raise Exception(_(
11 'Please update PyCrypto: https://www.dlitz.net/software/pycrypto/'))
12
13
14=== modified file 'src/uis/web/handler.py'
15--- src/uis/web/handler.py 2012-02-09 01:53:56 +0000
16+++ src/uis/web/handler.py 2012-02-28 05:50:23 +0000
17@@ -29,41 +29,19 @@
18 self.posts.insert(0, Post(name, sha256, post))
19
20 def web_ui_request(self, path, connection):
21- if path == '/':
22- connection.send_response(200)
23- connection.send_header('Content-type', 'text/html')
24- connection.end_headers()
25- connection.wfile.write(uis.web.content.template.format(
26- title = 'Anon+ News Feed',
27- pagetitle = 'Anon+ News Feed',
28- main = uis.web.content.post_box + self.__generate_news_feed(),
29- sidecontent = self.__friends2html()
30- ))
31- elif path == '/global.css':
32- connection.send_response(200)
33- connection.send_header('Content-type', 'text/css')
34- connection.end_headers()
35- connection.wfile.write(uis.web.content.globalcss)
36- elif path == '/settings.html':
37- connection.send_response(200)
38- connection.send_header('Content-type', 'text/html')
39- connection.end_headers()
40- connection.wfile.write('Connections page')
41- elif path == '/shutdown.html':
42- connection.send_response(200)
43- connection.send_header('Content-type', 'text/html')
44- connection.end_headers()
45- print('Got shutdown request from web server')
46- connection.wfile.write(uis.web.content.template.format(
47- title = 'Shutting down',
48- pagetitle = 'Shutdown',
49- main = 'We are quitting now. Threads are being killed.',
50- sidecontent = 'Goodbye :)'
51- ))
52- libs.globals['running'] = False
53- libs.threadmanager.killall()
54- libs.threadmanager.close_sockets()
55- elif path.startswith('/make_post.cgi?'):
56+ request_array = [['/','==','root'],['/global.css','==','global_css'], ['/friends.html', '==', 'friends_html'], ['/settings.html', '==', 'settings_html'], ['/shutdown.html','==','shutdown_html'], ['/make_post.cgi?',"<-",'make_post_cgi'], ['/forward.cgi?',"<-",'forward_cgi'], ['/reply.cgi?',"<-",'reply_cgi'], ['/add_friend.cgi?',"<-",'add_friend_cgi'], ['/keys.html', '==','keys_html']]
57+ for request in request_array:
58+ if request[1] == "==":
59+ if path ==request[0]:
60+ getattr(self, request[2],self.__defaultFailure)(path, connection)
61+ elif request[1] == "<-":
62+ if path.startswith(request[0]):
63+ getattr(self, request[2],self.__defaultFailure)(path, connection)
64+
65+ def __defaultFailure(self, path, connection):
66+ connection.wfile.write('unrecognized request')
67+
68+ def make_post_cgi(self, path, connection):
69 parameters = unquote_plus(path.split('?')[-1]).split('&')
70 for parameter in parameters:
71 item = parameter.split('=')
72@@ -83,7 +61,45 @@
73 connection.send_header('Location', 'http://localhost:7777/')
74 connection.end_headers()
75 connection.wfile.write('Redirecting')
76- elif path.startswith('/forward.cgi?'):
77+
78+ def shutdown_html(self, path, connection):
79+ connection.send_response(200)
80+ connection.send_header('Content-type', 'text/html')
81+ connection.end_headers()
82+ print('Got shutdown request from web server')
83+ connection.wfile.write(uis.web.content.template.format(
84+ title = 'Shutting down',
85+ pagetitle = 'Shutdown',
86+ main = 'We are quitting now. Threads are being killed.',
87+ sidecontent = 'Goodbye :)'
88+ ))
89+ libs.globals['running'] = False
90+ libs.threadmanager.killall()
91+ libs.threadmanager.close_sockets()
92+
93+ def settings_html(self, path, connection):
94+ connection.send_response(200)
95+ connection.send_header('Content-type', 'text/html')
96+ connection.end_headers()
97+ connection.wfile.write('Connections page')
98+
99+
100+ def forward_cgi(self, path, connection):
101+ connection.send_response(200)
102+ connection.send_header('Content-type', 'text/html')
103+ connection.end_headers()
104+ print('Got shutdown request from web server')
105+ connection.wfile.write(uis.web.content.template.format(
106+ title = 'Shutting down',
107+ pagetitle = 'Shutdown',
108+ main = 'We are quitting now. Threads are being killed.',
109+ sidecontent = 'Goodbye :)'
110+ ))
111+ libs.globals['running'] = False
112+ libs.threadmanager.killall()
113+ libs.threadmanager.close_sockets()
114+
115+ def forward_cgi(self, path, connection):
116 parameters = unquote_plus(path.split('?')[-1])
117 post_hash = parameters.split('=')[-1]
118
119@@ -103,12 +119,14 @@
120 connection.send_header('Location', 'http://localhost:7777/')
121 connection.end_headers()
122 connection.wfile.write('Redirecting')
123- elif path.startswith('/reply.cgi?'):
124+
125+ def reply_cgi(self, path, connection):
126 connection.send_response(301)
127 connection.send_header('Location', 'http://localhost:7777/')
128 connection.end_headers()
129 connection.wfile.write('Redirecting')
130- elif path == '/friends.html':
131+
132+ def friends_html(self, path, connection):
133 connection.send_response(200)
134 connection.send_header('Content-type', 'text/html')
135 connection.end_headers()
136@@ -122,7 +140,9 @@
137 ),
138 sidecontent = self.__friends2html()
139 ))
140- elif path.startswith('/add_friend.cgi?'):
141+
142+
143+ def add_friend_cgi(self, path, connection):
144 parameters = unquote_plus(path.split('?')[-1]).split('&')
145 keydata = ''
146 tunnel = ''
147@@ -156,7 +176,9 @@
148 '<br />Key: %s' % result,
149 sidecontent = self.__friends2html()
150 ))
151- elif path == '/keys.html':
152+
153+
154+ def keys_html(self, path, connection):
155 connection.send_response(200)
156 connection.send_header('Content-type', 'text/html')
157 connection.end_headers()
158@@ -167,6 +189,23 @@
159 sidecontent = self.__friends2html()
160 ))
161
162+ def root(self,path,connection):
163+ connection.send_response(200)
164+ connection.send_header('Content-type', 'text/html')
165+ connection.end_headers()
166+ connection.wfile.write(uis.web.content.template.format(
167+ title = 'Anon+ News Feed',
168+ pagetitle = 'Anon+ News Feed',
169+ main = uis.web.content.post_box + self.__generate_news_feed(),
170+ sidecontent = self.__friends2html()
171+ ))
172+
173+ def global_css(self,path,connection):
174+ connection.send_response(200)
175+ connection.send_header('Content-type', 'text/css')
176+ connection.end_headers()
177+ connection.wfile.write(uis.web.content.globalcss)
178+
179 def __friends2html(self):
180 '''Convert our friends list into some nice HTML'''
181 return uis.web.content.friends_box.format(

Subscribers

People subscribed via source and target branches

to all changes: