/usr/lib/python2.7/dist-packages/kombu/utils/compat.py is in python-kombu 3.0.33-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | """
kombu.utils.compat
==================
Helps compatibility with older Python versions.
"""
from __future__ import absolute_import
# ############# timedelta_seconds() -> delta.total_seconds ###################
from datetime import timedelta
HAVE_TIMEDELTA_TOTAL_SECONDS = hasattr(timedelta, 'total_seconds')
if HAVE_TIMEDELTA_TOTAL_SECONDS: # pragma: no cover
def timedelta_seconds(delta):
"""Convert :class:`datetime.timedelta` to seconds.
Doesn't account for negative values.
"""
return max(delta.total_seconds(), 0)
else: # pragma: no cover
def timedelta_seconds(delta): # noqa
"""Convert :class:`datetime.timedelta` to seconds.
Doesn't account for negative values.
"""
if delta.days < 0:
return 0
return delta.days * 86400 + delta.seconds + (delta.microseconds / 10e5)
# ############# socket.error.errno ###########################################
def get_errno(exc):
""":exc:`socket.error` and :exc:`IOError` first got
the ``.errno`` attribute in Py2.7"""
try:
return exc.errno
except AttributeError:
try:
# e.args = (errno, reason)
if isinstance(exc.args, tuple) and len(exc.args) == 2:
return exc.args[0]
except AttributeError:
pass
return 0
# ############# collections.OrderedDict ######################################
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict # noqa
|