Update oslo to latest and greatest

This was done mainly to pull in the fixt to timeutils.set_time_override() so
we don't have to keep passing in utcnow() into it.

Change-Id: I9918d03c57b8fbdc3750c7cb072a1aff2b2c653d
This commit is contained in:
kgriffs 2013-09-25 22:18:40 -04:00
parent e8e3baef4e
commit 4b39ab06ed
4 changed files with 62 additions and 19 deletions

View File

@ -79,7 +79,7 @@ def forever_retry_uncaught_exceptions(infunc):
try: try:
return infunc(*args, **kwargs) return infunc(*args, **kwargs)
except Exception as exc: except Exception as exc:
this_exc_message = unicode(exc) this_exc_message = six.u(str(exc))
if this_exc_message == last_exc_message: if this_exc_message == last_exc_message:
exc_count += 1 exc_count += 1
else: else:

View File

@ -60,6 +60,8 @@ def _(msg):
if USE_LAZY: if USE_LAZY:
return Message(msg, 'marconi') return Message(msg, 'marconi')
else: else:
if six.PY3:
return _t.gettext(msg)
return _t.ugettext(msg) return _t.ugettext(msg)
@ -105,13 +107,17 @@ def install(domain, lazy=False):
""" """
return Message(msg, domain) return Message(msg, domain)
import __builtin__ from six import moves
__builtin__.__dict__['_'] = _lazy_gettext moves.builtins.__dict__['_'] = _lazy_gettext
else: else:
localedir = '%s_LOCALEDIR' % domain.upper() localedir = '%s_LOCALEDIR' % domain.upper()
gettext.install(domain, if six.PY3:
localedir=os.environ.get(localedir), gettext.install(domain,
unicode=True) localedir=os.environ.get(localedir))
else:
gettext.install(domain,
localedir=os.environ.get(localedir),
unicode=True)
class Message(_userString.UserString, object): class Message(_userString.UserString, object):
@ -121,8 +127,8 @@ class Message(_userString.UserString, object):
self._msg = msg self._msg = msg
self._left_extra_msg = '' self._left_extra_msg = ''
self._right_extra_msg = '' self._right_extra_msg = ''
self._locale = None
self.params = None self.params = None
self.locale = None
self.domain = domain self.domain = domain
@property @property
@ -142,8 +148,13 @@ class Message(_userString.UserString, object):
localedir=localedir, localedir=localedir,
fallback=True) fallback=True)
if six.PY3:
ugettext = lang.gettext
else:
ugettext = lang.ugettext
full_msg = (self._left_extra_msg + full_msg = (self._left_extra_msg +
lang.ugettext(self._msg) + ugettext(self._msg) +
self._right_extra_msg) self._right_extra_msg)
if self.params is not None: if self.params is not None:
@ -151,6 +162,33 @@ class Message(_userString.UserString, object):
return six.text_type(full_msg) return six.text_type(full_msg)
@property
def locale(self):
return self._locale
@locale.setter
def locale(self, value):
self._locale = value
if not self.params:
return
# This Message object may have been constructed with one or more
# Message objects as substitution parameters, given as a single
# Message, or a tuple or Map containing some, so when setting the
# locale for this Message we need to set it for those Messages too.
if isinstance(self.params, Message):
self.params.locale = value
return
if isinstance(self.params, tuple):
for param in self.params:
if isinstance(param, Message):
param.locale = value
return
if isinstance(self.params, dict):
for param in self.params.values():
if isinstance(param, Message):
param.locale = value
def _save_dictionary_parameter(self, dict_param): def _save_dictionary_parameter(self, dict_param):
full_msg = self.data full_msg = self.data
# look for %(blah) fields in string; # look for %(blah) fields in string;
@ -169,7 +207,7 @@ class Message(_userString.UserString, object):
params[key] = copy.deepcopy(dict_param[key]) params[key] = copy.deepcopy(dict_param[key])
except TypeError: except TypeError:
# cast uncopyable thing to unicode string # cast uncopyable thing to unicode string
params[key] = unicode(dict_param[key]) params[key] = six.text_type(dict_param[key])
return params return params
@ -188,7 +226,7 @@ class Message(_userString.UserString, object):
try: try:
self.params = copy.deepcopy(other) self.params = copy.deepcopy(other)
except TypeError: except TypeError:
self.params = unicode(other) self.params = six.text_type(other)
return self return self
@ -197,11 +235,13 @@ class Message(_userString.UserString, object):
return self.data return self.data
def __str__(self): def __str__(self):
if six.PY3:
return self.__unicode__()
return self.data.encode('utf-8') return self.data.encode('utf-8')
def __getstate__(self): def __getstate__(self):
to_copy = ['_msg', '_right_extra_msg', '_left_extra_msg', to_copy = ['_msg', '_right_extra_msg', '_left_extra_msg',
'domain', 'params', 'locale'] 'domain', 'params', '_locale']
new_dict = self.__dict__.fromkeys(to_copy) new_dict = self.__dict__.fromkeys(to_copy)
for attr in to_copy: for attr in to_copy:
new_dict[attr] = copy.deepcopy(self.__dict__[attr]) new_dict[attr] = copy.deepcopy(self.__dict__[attr])
@ -293,7 +333,7 @@ def get_localized_message(message, user_locale):
if isinstance(message, Message): if isinstance(message, Message):
if user_locale: if user_locale:
message.locale = user_locale message.locale = user_locale
return unicode(message) return six.text_type(message)
else: else:
return message return message

View File

@ -260,14 +260,14 @@ class ContextAdapter(BaseLoggerAdapter):
extra.update(_dictify_context(context)) extra.update(_dictify_context(context))
instance = kwargs.pop('instance', None) instance = kwargs.pop('instance', None)
instance_uuid = (extra.get('instance_uuid', None) or
kwargs.pop('instance_uuid', None))
instance_extra = '' instance_extra = ''
if instance: if instance:
instance_extra = CONF.instance_format % instance instance_extra = CONF.instance_format % instance
else: elif instance_uuid:
instance_uuid = kwargs.pop('instance_uuid', None) instance_extra = (CONF.instance_uuid_format
if instance_uuid: % {'uuid': instance_uuid})
instance_extra = (CONF.instance_uuid_format
% {'uuid': instance_uuid})
extra.update({'instance': instance_extra}) extra.update({'instance': instance_extra})
extra.update({"project": self.project}) extra.update({"project": self.project})

View File

@ -117,12 +117,15 @@ def iso8601_from_timestamp(timestamp):
utcnow.override_time = None utcnow.override_time = None
def set_time_override(override_time=datetime.datetime.utcnow()): def set_time_override(override_time=None):
"""Overrides utils.utcnow. """Overrides utils.utcnow.
Make it return a constant time or a list thereof, one at a time. Make it return a constant time or a list thereof, one at a time.
:param override_time: datetime instance or list thereof. If not
given, defaults to the current UTC time.
""" """
utcnow.override_time = override_time utcnow.override_time = override_time or datetime.datetime.utcnow()
def advance_time_delta(timedelta): def advance_time_delta(timedelta):