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
=== modified file 'src/unity-scope-video-remote'
--- src/unity-scope-video-remote 2012-02-22 00:07:06 +0000
+++ src/unity-scope-video-remote 2012-02-22 14:38:26 +0000
@@ -21,7 +21,6 @@
21import json21import json
22import sys22import sys
23import urllib23import urllib
24import urllib2
25import time24import time
2625
27#pylint: disable=E061126#pylint: disable=E0611
@@ -38,6 +37,8 @@
38 GObject,37 GObject,
39 Gio,38 Gio,
40 Unity,39 Unity,
40 Soup,
41 SoupGNOME,
41)42)
42#pylint: enable=E061143#pylint: enable=E0611
4344
@@ -61,24 +62,21 @@
61 self.scope.props.sources.connect("notify::filtering",62 self.scope.props.sources.connect("notify::filtering",
62 self.on_filtering_changed)63 self.on_filtering_changed)
63 self.scope.connect ("activate-uri", self.on_activate_uri)64 self.scope.connect ("activate-uri", self.on_activate_uri)
65 self.session = Soup.SessionSync()
66 self.session.add_feature_by_type(SoupGNOME.ProxyResolverGNOME)
64 self.query_list_of_sources()67 self.query_list_of_sources()
65 self.scope.export()68 self.scope.export()
6669
67 def query_list_of_sources(self):70 def query_list_of_sources(self):
68 """Query the server for a list of sources that will be used71 """Query the server for a list of sources that will be used
69 to build sources filter options and search queries."""72 to build sources filter options and search queries."""
70 try:73 msg = Soup.Message.new("GET", SERVER + "/sources")
71 self.sources_list = json.load(urllib2.urlopen("%s/sources"74 if self.session.send_message(msg) != 200:
72 % (SERVER,)))
73 print "Got a list of sources from the server."
74 except (IOError,
75 KeyError,
76 urllib2.URLError,
77 urllib2.HTTPError,
78 ValueError):
79 self.sources_list = []75 self.sources_list = []
80 print "Error: Unable to query the server for a list of sources"76 print "Error: Unable to query the server for a list of sources"
77 print " %d: %s" % (msg.status_code, msg.reason_phrase)
81 else:78 else:
79 self.sources_list = json.loads(msg.response_body.data)
82 for n, source in enumerate(self.sources_list):80 for n, source in enumerate(self.sources_list):
83 self.scope.props.sources.add_option(str(n), source, None)81 self.scope.props.sources.add_option(str(n), source, None)
8482
@@ -140,21 +138,19 @@
140138
141 def get_results(self, search, sources):139 def get_results(self, search, sources):
142 """Query the server with the search string and the list of sources."""140 """Query the server with the search string and the list of sources."""
143 try:141 query = dict(q=search)
144 query = dict(q=search)142 if sources:
145 if sources:143 query['sources'] = sources
146 query['sources'] = sources144 query = urllib.urlencode(query)
147 query = urllib.urlencode(query)145 url = "%s/search?%s" % (SERVER, query)
148 url = "%s/search?%s" % (SERVER, query)146 print "Querying the server:", url
149 print "Querying the server:", url147 msg = Soup.Message.new("GET", url)
150 return json.load(urllib2.urlopen(url))148 if self.session.send_message(msg) != 200:
151 except (IOError,
152 KeyError,
153 urllib2.URLError,
154 urllib2.HTTPError,
155 ValueError):
156 print "Error: Unable to get results from the server"149 print "Error: Unable to get results from the server"
150 print " %d: %s" % (msg.status_code, msg.reason_phrase)
157 return []151 return []
152 else:
153 return json.loads(msg.response_body.data)
158154
159 def on_activate_uri (self, scope, rawuri):155 def on_activate_uri (self, scope, rawuri):
160 """On item clicked, parse the custom uri items"""156 """On item clicked, parse the custom uri items"""

Subscribers

People subscribed via source and target branches

to all changes: