Skip to content

Commit

Permalink
Merge from Oslo-Incubator
Browse files Browse the repository at this point in the history
This brings in the latest Python 3.x related
fixes from Oslo.

Change-Id: If0207d3b29038483098632586613bba9aeb803f7
  • Loading branch information
dirkmueller authored and Jamie Lennox committed Aug 6, 2013
1 parent 734ef6e commit de72de3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions keystoneclient/openstack/common/jsonutils.py
Expand Up @@ -41,6 +41,7 @@
import types
import xmlrpclib

import netaddr
import six

from keystoneclient.openstack.common import timeutils
Expand Down Expand Up @@ -137,6 +138,8 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
# Likely an instance of something. Watch for cycles.
# Ignore class member vars.
return recursive(value.__dict__, level=level + 1)
elif isinstance(value, netaddr.IPAddress):
return six.text_type(value)
else:
if any(test(value) for test in _nasty_type_tests):
return six.text_type(value)
Expand Down
19 changes: 10 additions & 9 deletions keystoneclient/openstack/common/timeutils.py
Expand Up @@ -23,6 +23,7 @@
import datetime

import iso8601
import six


# ISO 8601 extended time format with microseconds
Expand Down Expand Up @@ -75,14 +76,14 @@ def normalize_time(timestamp):

def is_older_than(before, seconds):
"""Return True if before is older than seconds."""
if isinstance(before, basestring):
if isinstance(before, six.string_types):
before = parse_strtime(before).replace(tzinfo=None)
return utcnow() - before > datetime.timedelta(seconds=seconds)


def is_newer_than(after, seconds):
"""Return True if after is newer than seconds."""
if isinstance(after, basestring):
if isinstance(after, six.string_types):
after = parse_strtime(after).replace(tzinfo=None)
return after - utcnow() > datetime.timedelta(seconds=seconds)

Expand Down Expand Up @@ -111,9 +112,9 @@ def iso8601_from_timestamp(timestamp):


def set_time_override(override_time=datetime.datetime.utcnow()):
"""
Override utils.utcnow to return a constant time or a list thereof,
one at a time.
"""Overrides utils.utcnow.
Make it return a constant time or a list thereof, one at a time.
"""
utcnow.override_time = override_time

Expand Down Expand Up @@ -141,7 +142,7 @@ def clear_time_override():
def marshall_now(now=None):
"""Make an rpc-safe datetime with microseconds.
Note: tzinfo is stripped, but not required for relative times.
Note: tzinfo is stripped, but not required for relative times.
"""
if not now:
now = utcnow()
Expand All @@ -162,7 +163,8 @@ def unmarshall_time(tyme):


def delta_seconds(before, after):
"""
"""Return the difference between two timing objects.
Compute the difference in seconds between two date, time, or
datetime objects (as a float, to microsecond resolution).
"""
Expand All @@ -175,8 +177,7 @@ def delta_seconds(before, after):


def is_soon(dt, window):
"""
Determines if time is going to happen in the next window seconds.
"""Determines if time is going to happen in the next window seconds.
:params dt: the time
:params window: minimum seconds to remain to consider the time not soon
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -7,3 +7,4 @@ requests>=0.8.8
simplejson
six
oslo.config>=1.1.0
netaddr
1 change: 0 additions & 1 deletion test-requirements.txt
Expand Up @@ -3,7 +3,6 @@ pep8==1.4.5
pyflakes==0.7.2
flake8==2.0
hacking>=0.5.3,<0.6

coverage
discover
fixtures
Expand Down

0 comments on commit de72de3

Please sign in to comment.