Merge lp:~chipaca/unity-lens-video/soupify into lp:unity-lens-video/remote-videos-scope-trunk

Proposed by John Lenton
Status: Merged
Approved by: David Callé
Approved revision: 23
Merged at revision: 23
Proposed branch: lp:~chipaca/unity-lens-video/soupify
Merge into: lp:unity-lens-video/remote-videos-scope-trunk
Diff against target: 84 lines (+19/-23)
1 file modified
src/unity-scope-video-remote (+19/-23)
To merge this branch: bzr merge lp:~chipaca/unity-lens-video/soupify
Reviewer Review Type Date Requested Status
David Callé Approve
Review via email: mp+94179@code.launchpad.net

Commit message

Change from urllib2 to libsoup for the HTTP work.

Description of the change

Change from urllib2 to libsoup for the HTTP work.

To post a comment you must log in.
Revision history for this message
David Callé (davidc3) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity-scope-video-remote'
2--- src/unity-scope-video-remote 2012-02-22 00:07:06 +0000
3+++ src/unity-scope-video-remote 2012-02-22 14:38:26 +0000
4@@ -21,7 +21,6 @@
5 import json
6 import sys
7 import urllib
8-import urllib2
9 import time
10
11 #pylint: disable=E0611
12@@ -38,6 +37,8 @@
13 GObject,
14 Gio,
15 Unity,
16+ Soup,
17+ SoupGNOME,
18 )
19 #pylint: enable=E0611
20
21@@ -61,24 +62,21 @@
22 self.scope.props.sources.connect("notify::filtering",
23 self.on_filtering_changed)
24 self.scope.connect ("activate-uri", self.on_activate_uri)
25+ self.session = Soup.SessionSync()
26+ self.session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
27 self.query_list_of_sources()
28 self.scope.export()
29
30 def query_list_of_sources(self):
31 """Query the server for a list of sources that will be used
32 to build sources filter options and search queries."""
33- try:
34- self.sources_list = json.load(urllib2.urlopen("%s/sources"
35- % (SERVER,)))
36- print "Got a list of sources from the server."
37- except (IOError,
38- KeyError,
39- urllib2.URLError,
40- urllib2.HTTPError,
41- ValueError):
42+ msg = Soup.Message.new("GET", SERVER + "/sources")
43+ if self.session.send_message(msg) != 200:
44 self.sources_list = []
45 print "Error: Unable to query the server for a list of sources"
46+ print " %d: %s" % (msg.status_code, msg.reason_phrase)
47 else:
48+ self.sources_list = json.loads(msg.response_body.data)
49 for n, source in enumerate(self.sources_list):
50 self.scope.props.sources.add_option(str(n), source, None)
51
52@@ -140,21 +138,19 @@
53
54 def get_results(self, search, sources):
55 """Query the server with the search string and the list of sources."""
56- try:
57- query = dict(q=search)
58- if sources:
59- query['sources'] = sources
60- query = urllib.urlencode(query)
61- url = "%s/search?%s" % (SERVER, query)
62- print "Querying the server:", url
63- return json.load(urllib2.urlopen(url))
64- except (IOError,
65- KeyError,
66- urllib2.URLError,
67- urllib2.HTTPError,
68- ValueError):
69+ query = dict(q=search)
70+ if sources:
71+ query['sources'] = sources
72+ query = urllib.urlencode(query)
73+ url = "%s/search?%s" % (SERVER, query)
74+ print "Querying the server:", url
75+ msg = Soup.Message.new("GET", url)
76+ if self.session.send_message(msg) != 200:
77 print "Error: Unable to get results from the server"
78+ print " %d: %s" % (msg.status_code, msg.reason_phrase)
79 return []
80+ else:
81+ return json.loads(msg.response_body.data)
82
83 def on_activate_uri (self, scope, rawuri):
84 """On item clicked, parse the custom uri items"""

Subscribers

People subscribed via source and target branches

to all changes: