Merge lp:~cjwatson/lazr.restfulclient/cgi-parse-qs-deprecated into lp:lazr.restfulclient

Proposed by Colin Watson
Status: Merged
Merged at revision: 130
Proposed branch: lp:~cjwatson/lazr.restfulclient/cgi-parse-qs-deprecated
Merge into: lp:lazr.restfulclient
Diff against target: 31 lines (+5/-2)
1 file modified
src/lazr/restfulclient/resource.py (+5/-2)
To merge this branch: bzr merge lp:~cjwatson/lazr.restfulclient/cgi-parse-qs-deprecated
Reviewer Review Type Date Requested Status
Richard Harding Approve
Review via email: mp+111001@code.launchpad.net

Commit message

Use parse_qs from urlparse (Python >= 2.6) rather than cgi if available.

Description of the change

Uses of launchpadlib in quantal have a habit of emitting this message (I have PYTHONWARNINGS=default set in my environment to catch more of this kind of thing):

/usr/lib/python2.7/dist-packages/lazr/restfulclient/resource.py:921: PendingDeprecationWarning: cgi.parse_qs is deprecated, use urlparse.parse_qs instead
  params = cgi.parse_qs(uri.query)

This branch uses urlparse.parse_qs instead if it's available. It shouldn't break compatibility with pre-2.6.

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

Thanks for the update.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restfulclient/resource.py'
2--- src/lazr/restfulclient/resource.py 2012-04-16 03:16:46 +0000
3+++ src/lazr/restfulclient/resource.py 2012-06-19 12:04:44 +0000
4@@ -29,7 +29,6 @@
5 ]
6
7
8-import cgi
9 try:
10 from email.message import Message
11 except ImportError:
12@@ -38,6 +37,10 @@
13 from StringIO import StringIO
14 import types
15 import urllib
16+try:
17+ from urlparse import parse_qs
18+except ImportError:
19+ from cgi import parse_qs
20 from urlparse import urlparse, urljoin
21
22 from lazr.uri import URI
23@@ -927,7 +930,7 @@
24 if uri.query is None:
25 params = {}
26 else:
27- params = cgi.parse_qs(uri.query)
28+ params = parse_qs(uri.query)
29 params[variable] = str(new_value)
30 uri.query = urllib.urlencode(params, True)
31 return str(uri)

Subscribers

People subscribed via source and target branches