[oe-commits] [bitbake] 23/24: toaster: fix urllib imports

git at git.openembedded.org git at git.openembedded.org
Wed Jun 1 14:29:29 UTC 2016


rpurdie pushed a commit to branch python3
in repository bitbake.

commit b91aa29fa20befd9841678a727bb91100363518f
Author: Ed Bartosh <ed.bartosh at linux.intel.com>
AuthorDate: Mon May 30 16:10:59 2016 +0300

    toaster: fix urllib imports
    
    Some functions have been moved from urllib to urllib.parse
    in python 3. Modifying the code to import unquote, urlencode and
    unquote_plus from urllib.parse if import from urllib fails should
    make it working on both python 2 and python 3.
    
    Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 lib/toaster/toastergui/views.py   | 9 ++++++---
 lib/toaster/toastergui/widgets.py | 6 +++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 8e920f0..0510897 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -200,16 +200,19 @@ def _verify_parameters(g, mandatory_parameters):
     return None
 
 def _redirect_parameters(view, g, mandatory_parameters, *args, **kwargs):
-    import urllib
+    try:
+        from urllib import unquote, urlencode
+    except ImportError:
+        from urllib.parse import unquote, urlencode
     url = reverse(view, kwargs=kwargs)
     params = {}
     for i in g:
         params[i] = g[i]
     for i in mandatory_parameters:
         if not i in params:
-            params[i] = urllib.unquote(str(mandatory_parameters[i]))
+            params[i] = unquote(str(mandatory_parameters[i]))
 
-    return redirect(url + "?%s" % urllib.urlencode(params), permanent = False, **kwargs)
+    return redirect(url + "?%s" % urlencode(params), permanent = False, **kwargs)
 
 class RedirectException(Exception):
     def __init__(self, view, g, mandatory_parameters, *args, **kwargs):
diff --git a/lib/toaster/toastergui/widgets.py b/lib/toaster/toastergui/widgets.py
index 19850fb..551c33c 100644
--- a/lib/toaster/toastergui/widgets.py
+++ b/lib/toaster/toastergui/widgets.py
@@ -38,7 +38,11 @@ import json
 import collections
 import operator
 import re
-import urllib
+
+try:
+    from urllib import unquote_plus
+except ImportError:
+    from urllib.parse import unquote_plus
 
 import logging
 logger = logging.getLogger("toaster")

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list