Python3: replace urllib by six.moves.urllib
This makes the code compatible with both Python 2 and 3. Change-Id: I721a5567842f2df6ce2a8af501787204daba3082
This commit is contained in:
@@ -23,9 +23,9 @@ Base utilities to build API operation managers and objects on top of.
|
|||||||
|
|
||||||
import abc
|
import abc
|
||||||
import functools
|
import functools
|
||||||
import urllib
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common import strutils
|
from keystoneclient.openstack.common import strutils
|
||||||
@@ -331,10 +331,14 @@ class CrudManager(Manager):
|
|||||||
def list(self, **kwargs):
|
def list(self, **kwargs):
|
||||||
url = self.build_url(dict_args_in_out=kwargs)
|
url = self.build_url(dict_args_in_out=kwargs)
|
||||||
|
|
||||||
|
if kwargs:
|
||||||
|
query = '?%s' % urllib.parse.urlencode(kwargs)
|
||||||
|
else:
|
||||||
|
query = ''
|
||||||
return self._list(
|
return self._list(
|
||||||
'%(url)s%(query)s' % {
|
'%(url)s%(query)s' % {
|
||||||
'url': url,
|
'url': url,
|
||||||
'query': '?%s' % urllib.urlencode(kwargs) if kwargs else '',
|
'query': query,
|
||||||
},
|
},
|
||||||
self.collection_key)
|
self.collection_key)
|
||||||
|
|
||||||
@@ -364,10 +368,14 @@ class CrudManager(Manager):
|
|||||||
"""Find a single item with attributes matching ``**kwargs``."""
|
"""Find a single item with attributes matching ``**kwargs``."""
|
||||||
url = self.build_url(dict_args_in_out=kwargs)
|
url = self.build_url(dict_args_in_out=kwargs)
|
||||||
|
|
||||||
|
if kwargs:
|
||||||
|
query = '?%s' % urllib.parse.urlencode(kwargs)
|
||||||
|
else:
|
||||||
|
query = ''
|
||||||
rl = self._list(
|
rl = self._list(
|
||||||
'%(url)s%(query)s' % {
|
'%(url)s%(query)s' % {
|
||||||
'url': url,
|
'url': url,
|
||||||
'query': '?%s' % urllib.urlencode(kwargs) if kwargs else '',
|
'query': query,
|
||||||
},
|
},
|
||||||
self.collection_key)
|
self.collection_key)
|
||||||
num = len(rl)
|
num = len(rl)
|
||||||
|
@@ -22,9 +22,9 @@ import base64
|
|||||||
import hashlib
|
import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
|
|
||||||
class Ec2Signer(object):
|
class Ec2Signer(object):
|
||||||
@@ -134,8 +134,8 @@ class Ec2Signer(object):
|
|||||||
pairs = []
|
pairs = []
|
||||||
for key in keys:
|
for key in keys:
|
||||||
val = Ec2Signer._get_utf8_value(params[key])
|
val = Ec2Signer._get_utf8_value(params[key])
|
||||||
val = urllib.quote(val, safe='-_~')
|
val = urllib.parse.quote(val, safe='-_~')
|
||||||
pairs.append(urllib.quote(key, safe='') + '=' + val)
|
pairs.append(urllib.parse.quote(key, safe='') + '=' + val)
|
||||||
qs = '&'.join(pairs)
|
qs = '&'.join(pairs)
|
||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
@@ -151,10 +151,10 @@ import requests
|
|||||||
import stat
|
import stat
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import urllib
|
|
||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
import six
|
import six
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
from keystoneclient.common import cms
|
from keystoneclient.common import cms
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
@@ -343,7 +343,7 @@ def confirm_token_not_expired(data):
|
|||||||
|
|
||||||
def safe_quote(s):
|
def safe_quote(s):
|
||||||
"""URL-encode strings that are not already URL-encoded."""
|
"""URL-encode strings that are not already URL-encoded."""
|
||||||
return urllib.quote(s) if s == urllib.unquote(s) else s
|
return urllib.parse.quote(s) if s == urllib.parse.unquote(s) else s
|
||||||
|
|
||||||
|
|
||||||
class InvalidUserToken(Exception):
|
class InvalidUserToken(Exception):
|
||||||
|
@@ -14,9 +14,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import urllib
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
from six.moves import urllib
|
||||||
|
|
||||||
from keystoneclient import base
|
from keystoneclient import base
|
||||||
|
|
||||||
@@ -108,7 +107,7 @@ class TenantManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
query = ""
|
query = ""
|
||||||
if params:
|
if params:
|
||||||
query = "?" + urllib.urlencode(params)
|
query = "?" + urllib.parse.urlencode(params)
|
||||||
|
|
||||||
reset = 0
|
reset = 0
|
||||||
if self.api.management_url is None:
|
if self.api.management_url is None:
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import urllib
|
from six.moves import urllib
|
||||||
|
|
||||||
from keystoneclient import base
|
from keystoneclient import base
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class UserManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
query = ""
|
query = ""
|
||||||
if params:
|
if params:
|
||||||
query = "?" + urllib.urlencode(params)
|
query = "?" + urllib.parse.urlencode(params)
|
||||||
|
|
||||||
if not tenant_id:
|
if not tenant_id:
|
||||||
return self._list("/users%s" % query, "users")
|
return self._list("/users%s" % query, "users")
|
||||||
|
Reference in New Issue
Block a user