Sync with oslo-incubator fd90c34a9
This syncs python-keystoneclient with oslo-incubator commit hash fd90c34a914ef98e0c7ccdbf823d9b6d04aa436b First, remove the existing code to cleanup: $ rm -r keystoneclient/openstack/* Then, sync from oslo-incubator: $ python update.py ../python-keystoneclient Commits since last sync (caed79d): ---------------------------------- de4adbc pep8: fixed multiple violations e42e77f Restore UUID and human-ID bash completion 250cd88 Fixed a new pep8 error and a small typo 9e88af1 fixed typos found by RETF rules 0d7296f Add kwargs to jsonutils.load(s) functions 822e09b Don't slugify names that don't exist Change-Id: I33378512593a0cdbc0db0def171b66911aba8708
This commit is contained in:
@@ -32,6 +32,7 @@ from six.moves.urllib import parse
|
||||
from keystoneclient.openstack.common.apiclient import exceptions
|
||||
from keystoneclient.openstack.common.gettextutils import _
|
||||
from keystoneclient.openstack.common import strutils
|
||||
from keystoneclient.openstack.common import uuidutils
|
||||
|
||||
|
||||
def getid(obj):
|
||||
@@ -436,6 +437,21 @@ class Resource(object):
|
||||
self._info = info
|
||||
self._add_details(info)
|
||||
self._loaded = loaded
|
||||
self._init_completion_cache()
|
||||
|
||||
def _init_completion_cache(self):
|
||||
cache_write = getattr(self.manager, 'write_to_completion_cache', None)
|
||||
if not cache_write:
|
||||
return
|
||||
|
||||
# NOTE(sirp): ensure `id` is already present because if it isn't we'll
|
||||
# enter an infinite loop of __getattr__ -> get -> __init__ ->
|
||||
# __getattr__ -> ...
|
||||
if 'id' in self.__dict__ and uuidutils.is_uuid_like(self.id):
|
||||
cache_write('uuid', self.id)
|
||||
|
||||
if self.human_id:
|
||||
cache_write('human_id', self.human_id)
|
||||
|
||||
def __repr__(self):
|
||||
reprkeys = sorted(k
|
||||
@@ -448,8 +464,10 @@ class Resource(object):
|
||||
def human_id(self):
|
||||
"""Human-readable ID which can be used for bash completion.
|
||||
"""
|
||||
if self.NAME_ATTR in self.__dict__ and self.HUMAN_ID:
|
||||
return strutils.to_slug(getattr(self, self.NAME_ATTR))
|
||||
if self.HUMAN_ID:
|
||||
name = getattr(self, self.NAME_ATTR, None)
|
||||
if name is not None:
|
||||
return strutils.to_slug(name)
|
||||
return None
|
||||
|
||||
def _add_details(self, info):
|
||||
|
@@ -77,7 +77,7 @@ class AuthPluginOptionsMissing(AuthorizationFailure):
|
||||
|
||||
|
||||
class AuthSystemNotFound(AuthorizationFailure):
|
||||
"""User has specified a AuthSystem that is not installed."""
|
||||
"""User has specified an AuthSystem that is not installed."""
|
||||
def __init__(self, auth_system):
|
||||
super(AuthSystemNotFound, self).__init__(
|
||||
_("AuthSystemNotFound: %s") % repr(auth_system))
|
||||
|
@@ -79,7 +79,7 @@ class FakeHTTPClient(client.HTTPClient):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.callstack = []
|
||||
self.fixtures = kwargs.pop("fixtures", None) or {}
|
||||
if not args and not "auth_plugin" in kwargs:
|
||||
if not args and "auth_plugin" not in kwargs:
|
||||
args = (None, )
|
||||
super(FakeHTTPClient, self).__init__(*args, **kwargs)
|
||||
|
||||
|
@@ -373,8 +373,8 @@ def get_available_languages(domain):
|
||||
'zh_Hant_HK': 'zh_HK',
|
||||
'zh_Hant': 'zh_TW',
|
||||
'fil': 'tl_PH'}
|
||||
for (locale, alias) in six.iteritems(aliases):
|
||||
if locale in language_list and alias not in language_list:
|
||||
for (locale_, alias) in six.iteritems(aliases):
|
||||
if locale_ in language_list and alias not in language_list:
|
||||
language_list.append(alias)
|
||||
|
||||
_AVAILABLE_LANGUAGES[domain] = language_list
|
||||
|
@@ -168,12 +168,12 @@ def dumps(value, default=to_primitive, **kwargs):
|
||||
return json.dumps(value, default=default, **kwargs)
|
||||
|
||||
|
||||
def loads(s, encoding='utf-8'):
|
||||
return json.loads(strutils.safe_decode(s, encoding))
|
||||
def loads(s, encoding='utf-8', **kwargs):
|
||||
return json.loads(strutils.safe_decode(s, encoding), **kwargs)
|
||||
|
||||
|
||||
def load(fp, encoding='utf-8'):
|
||||
return json.load(codecs.getreader(encoding)(fp))
|
||||
def load(fp, encoding='utf-8', **kwargs):
|
||||
return json.load(codecs.getreader(encoding)(fp), **kwargs)
|
||||
|
||||
|
||||
try:
|
||||
|
@@ -114,7 +114,7 @@ def utcnow():
|
||||
|
||||
|
||||
def iso8601_from_timestamp(timestamp):
|
||||
"""Returns a iso8601 formatted date from timestamp."""
|
||||
"""Returns an iso8601 formatted date from timestamp."""
|
||||
return isotime(datetime.datetime.utcfromtimestamp(timestamp))
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ def set_time_override(override_time=None):
|
||||
|
||||
def advance_time_delta(timedelta):
|
||||
"""Advance overridden time using a datetime.timedelta."""
|
||||
assert(not utcnow.override_time is None)
|
||||
assert utcnow.override_time is not None
|
||||
try:
|
||||
for dt in utcnow.override_time:
|
||||
dt += timedelta
|
||||
|
37
keystoneclient/openstack/common/uuidutils.py
Normal file
37
keystoneclient/openstack/common/uuidutils.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2012 Intel Corporation.
|
||||
# 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.
|
||||
|
||||
"""
|
||||
UUID related utilities and helper functions.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
|
||||
def generate_uuid():
|
||||
return str(uuid.uuid4())
|
||||
|
||||
|
||||
def is_uuid_like(val):
|
||||
"""Returns validation of a value as a UUID.
|
||||
|
||||
For our purposes, a UUID is a canonical form string:
|
||||
aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
|
||||
|
||||
"""
|
||||
try:
|
||||
return str(uuid.UUID(val)) == val
|
||||
except (TypeError, ValueError, AttributeError):
|
||||
return False
|
Reference in New Issue
Block a user