Merge "Remove dependent module py3kcompat"
This commit is contained in:
commit
d59016901d
@ -4,7 +4,6 @@
|
||||
module=apiclient
|
||||
module=strutils
|
||||
module=install_venv_common
|
||||
module=py3kcompat
|
||||
|
||||
# The base module to hold the copy of openstack.common
|
||||
base=troveclient
|
||||
|
@ -24,12 +24,12 @@ import hashlib
|
||||
import os
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from troveclient.openstack.common.apiclient import base
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
from troveclient import utils
|
||||
from troveclient import common
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
# Python 2.4 compat
|
||||
try:
|
||||
@ -69,8 +69,8 @@ class Manager(utils.HookableMixin):
|
||||
next_marker = None
|
||||
for link in next_links:
|
||||
# Extract the marker from the url.
|
||||
parsed_url = urlutils.urlparse(link)
|
||||
query_dict = dict(urlutils.parse_qsl(parsed_url.query))
|
||||
parsed_url = parse.urlparse(link)
|
||||
query_dict = dict(parse.parse_qsl(parsed_url.query))
|
||||
next_marker = query_dict.get('marker')
|
||||
data = [self.resource_class(self, res) for res in body[response_key]]
|
||||
return common.Paginated(data, next_marker=next_marker, links=links)
|
||||
|
@ -13,11 +13,10 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
|
||||
def check_for_exceptions(resp, body, url):
|
||||
if resp.status_code in (400, 422, 500):
|
||||
@ -39,9 +38,9 @@ def limit_url(url, limit=None, marker=None):
|
||||
def quote_user_host(user, host):
|
||||
quoted = ''
|
||||
if host:
|
||||
quoted = urlutils.quote("%s@%s" % (user, host))
|
||||
quoted = parse.quote("%s@%s" % (user, host))
|
||||
else:
|
||||
quoted = urlutils.quote("%s" % user)
|
||||
quoted = parse.quote("%s" % user)
|
||||
return quoted.replace('.', '%2e')
|
||||
|
||||
|
||||
|
@ -18,13 +18,12 @@ import optparse
|
||||
import os
|
||||
import pickle
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
import sys
|
||||
|
||||
from troveclient.compat import client
|
||||
from troveclient.compat import exceptions
|
||||
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
|
||||
def methods_of(obj):
|
||||
"""Get all callable methods of an object that don't start with underscore
|
||||
@ -74,9 +73,9 @@ def limit_url(url, limit=None, marker=None):
|
||||
def quote_user_host(user, host):
|
||||
quoted = ''
|
||||
if host:
|
||||
quoted = urlutils.quote("%s@%s" % (user, host))
|
||||
quoted = parse.quote("%s@%s" % (user, host))
|
||||
else:
|
||||
quoted = urlutils.quote("%s" % user)
|
||||
quoted = parse.quote("%s" % user)
|
||||
return quoted.replace('.', '%2e')
|
||||
|
||||
|
||||
|
@ -1,14 +0,0 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
@ -19,7 +19,6 @@
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
import six
|
||||
@ -28,9 +27,6 @@ from stevedore import extension
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_discovered_plugins = {}
|
||||
|
||||
|
||||
@ -80,7 +76,7 @@ def load_plugin_from_args(args):
|
||||
alphabetical order.
|
||||
|
||||
:type args: argparse.Namespace
|
||||
:raises: AuthorizationFailure
|
||||
:raises: AuthPluginOptionsMissing
|
||||
"""
|
||||
auth_system = args.os_auth_system
|
||||
if auth_system:
|
||||
|
@ -24,11 +24,12 @@ Base utilities to build API operation managers and objects on top of.
|
||||
# pylint: disable=E1102
|
||||
|
||||
import abc
|
||||
import copy
|
||||
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from troveclient.openstack.common.apiclient import exceptions
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
from troveclient.openstack.common import strutils
|
||||
|
||||
|
||||
@ -327,7 +328,7 @@ class CrudManager(BaseManager):
|
||||
return self._list(
|
||||
'%(base_url)s%(query)s' % {
|
||||
'base_url': self.build_url(base_url=base_url, **kwargs),
|
||||
'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '',
|
||||
'query': '?%s' % parse.urlencode(kwargs) if kwargs else '',
|
||||
},
|
||||
self.collection_key)
|
||||
|
||||
@ -366,7 +367,7 @@ class CrudManager(BaseManager):
|
||||
rl = self._list(
|
||||
'%(base_url)s%(query)s' % {
|
||||
'base_url': self.build_url(base_url=base_url, **kwargs),
|
||||
'query': '?%s' % urlutils.urlencode(kwargs) if kwargs else '',
|
||||
'query': '?%s' % parse.urlencode(kwargs) if kwargs else '',
|
||||
},
|
||||
self.collection_key)
|
||||
num = len(rl)
|
||||
@ -456,17 +457,17 @@ class Resource(object):
|
||||
def __getattr__(self, k):
|
||||
if k not in self.__dict__:
|
||||
#NOTE(bcwaldon): disallow lazy-loading if already loaded once
|
||||
if not self.is_loaded():
|
||||
self.get()
|
||||
if not self.is_loaded:
|
||||
self._get()
|
||||
return self.__getattr__(k)
|
||||
|
||||
raise AttributeError(k)
|
||||
else:
|
||||
return self.__dict__[k]
|
||||
|
||||
def get(self):
|
||||
# set_loaded() first ... so if we have to bail, we know we tried.
|
||||
self.set_loaded(True)
|
||||
def _get(self):
|
||||
# set _loaded first ... so if we have to bail, we know we tried.
|
||||
self._loaded = True
|
||||
if not hasattr(self.manager, 'get'):
|
||||
return
|
||||
|
||||
@ -484,8 +485,9 @@ class Resource(object):
|
||||
return self.id == other.id
|
||||
return self._info == other._info
|
||||
|
||||
@property
|
||||
def is_loaded(self):
|
||||
return self._loaded
|
||||
|
||||
def set_loaded(self, val):
|
||||
self._loaded = val
|
||||
def to_dict(self):
|
||||
return copy.deepcopy(self._info)
|
||||
|
@ -425,8 +425,8 @@ def from_response(response, method, url):
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
if hasattr(body, "keys"):
|
||||
error = body[body.keys()[0]]
|
||||
if isinstance(body, dict):
|
||||
error = list(body.values())[0]
|
||||
kwargs["message"] = error.get("message", None)
|
||||
kwargs["details"] = error.get("details", None)
|
||||
elif content_type.startswith("text/"):
|
||||
|
@ -28,10 +28,9 @@ import json
|
||||
|
||||
import requests
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from troveclient.openstack.common.apiclient import client
|
||||
from troveclient.openstack.common.py3kcompat import urlutils
|
||||
from troveclient.openstack.common import strutils
|
||||
|
||||
|
||||
def assert_has_keys(dct, required=[], optional=[]):
|
||||
@ -64,7 +63,7 @@ class TestResponse(requests.Response):
|
||||
self._content = text
|
||||
default_headers = {}
|
||||
if six.PY3 and isinstance(self._content, six.string_types):
|
||||
self._content = strutils.safe_encode(self._content)
|
||||
self._content = self._content.encode('utf-8', 'strict')
|
||||
self.headers = data.get('headers') or default_headers
|
||||
else:
|
||||
self.status_code = data
|
||||
@ -148,7 +147,7 @@ class FakeHTTPClient(client.HTTPClient):
|
||||
"text": fixture[1]})
|
||||
|
||||
# Call the method
|
||||
args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
|
||||
args = parse.parse_qsl(parse.urlparse(url)[4])
|
||||
kwargs.update(args)
|
||||
munged_url = url.rsplit('?', 1)[0]
|
||||
munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')
|
||||
|
@ -1,16 +0,0 @@
|
||||
#
|
||||
# Copyright 2013 Canonical Ltd.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
@ -1,65 +0,0 @@
|
||||
#
|
||||
# Copyright 2013 Canonical Ltd.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""
|
||||
Python2/Python3 compatibility layer for OpenStack
|
||||
"""
|
||||
|
||||
import six
|
||||
|
||||
if six.PY3:
|
||||
# python3
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
urlencode = urllib.parse.urlencode
|
||||
urljoin = urllib.parse.urljoin
|
||||
quote = urllib.parse.quote
|
||||
parse_qsl = urllib.parse.parse_qsl
|
||||
unquote = urllib.parse.unquote
|
||||
unquote_plus = urllib.parse.unquote_plus
|
||||
urlparse = urllib.parse.urlparse
|
||||
urlsplit = urllib.parse.urlsplit
|
||||
urlunsplit = urllib.parse.urlunsplit
|
||||
SplitResult = urllib.parse.SplitResult
|
||||
|
||||
urlopen = urllib.request.urlopen
|
||||
URLError = urllib.error.URLError
|
||||
pathname2url = urllib.request.pathname2url
|
||||
else:
|
||||
# python2
|
||||
import urllib
|
||||
import urllib2
|
||||
import urlparse
|
||||
|
||||
urlencode = urllib.urlencode
|
||||
quote = urllib.quote
|
||||
unquote = urllib.unquote
|
||||
unquote_plus = urllib.unquote_plus
|
||||
|
||||
parse = urlparse
|
||||
parse_qsl = parse.parse_qsl
|
||||
urljoin = parse.urljoin
|
||||
urlparse = parse.urlparse
|
||||
urlsplit = parse.urlsplit
|
||||
urlunsplit = parse.urlunsplit
|
||||
SplitResult = parse.SplitResult
|
||||
|
||||
urlopen = urllib2.urlopen
|
||||
URLError = urllib2.URLError
|
||||
pathname2url = urllib.pathname2url
|
@ -472,7 +472,7 @@ class ResourceTest(testtools.TestCase):
|
||||
manager.get = None
|
||||
|
||||
robj.manager = object()
|
||||
robj.get()
|
||||
robj._get()
|
||||
|
||||
manager = mock.Mock()
|
||||
robj.manager = mock.Mock()
|
||||
@ -481,7 +481,7 @@ class ResourceTest(testtools.TestCase):
|
||||
new = mock.Mock()
|
||||
new._info = {"name": "test-human-id", "test_attr": 5}
|
||||
robj.manager.get = mock.Mock(return_value=new)
|
||||
robj.get()
|
||||
robj._get()
|
||||
self.assertEqual("test-human-id", robj.name)
|
||||
self.assertEqual(5, robj.test_attr)
|
||||
|
||||
@ -511,15 +511,7 @@ class ResourceTest(testtools.TestCase):
|
||||
def test_is_loaded(self):
|
||||
robj = self.get_mock_resource_obj()
|
||||
robj._loaded = True
|
||||
self.assertTrue(robj.is_loaded())
|
||||
self.assertTrue(robj.is_loaded)
|
||||
|
||||
robj._loaded = False
|
||||
self.assertFalse(robj.is_loaded())
|
||||
|
||||
def test_set_loaded(self):
|
||||
robj = self.get_mock_resource_obj()
|
||||
robj.set_loaded(True)
|
||||
self.assertTrue(robj._loaded)
|
||||
|
||||
robj.set_loaded(False)
|
||||
self.assertFalse(robj._loaded)
|
||||
self.assertFalse(robj.is_loaded)
|
||||
|
Loading…
x
Reference in New Issue
Block a user