Skip to content

Commit

Permalink
Bringing local column_family.py closer to upstream.
Browse files Browse the repository at this point in the history
This is so that a simple diff is possible.
  • Loading branch information
dhermes committed Dec 23, 2015
1 parent 4f0ee5e commit 4f3132e
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 384 deletions.
31 changes: 31 additions & 0 deletions gcloud_bigtable/_non_upstream_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import datetime
import os
import socket
import sys

import pytz
import six
Expand Down Expand Up @@ -291,3 +292,33 @@ def _to_bytes(value, encoding='ascii'):
return result
else:
raise TypeError('%r could not be converted to bytes' % (value,))


def _total_seconds_backport(offset):
"""Backport of timedelta.total_seconds() from python 2.7+.
:type offset: :class:`datetime.timedelta`
:param offset: A timedelta object.
:rtype: int
:returns: The total seconds (including microseconds) in the
duration.
"""
seconds = offset.days * 24 * 60 * 60 + offset.seconds
return seconds + offset.microseconds * 1e-6


def _total_seconds(offset):
"""Version independent total seconds for a time delta.
:type offset: :class:`datetime.timedelta`
:param offset: A timedelta object.
:rtype: int
:returns: The total seconds (including microseconds) in the
duration.
"""
if sys.version_info[:2] < (2, 7): # pragma: NO COVER
return _total_seconds_backport(offset)
else:
return offset.total_seconds()

0 comments on commit 4f3132e

Please sign in to comment.