aboutsummaryrefslogtreecommitdiff
path: root/google
diff options
context:
space:
mode:
Diffstat (limited to 'google')
-rw-r--r--google/api_core/bidi.py10
-rw-r--r--google/api_core/datetime_helpers.py37
-rw-r--r--google/api_core/iam.py3
-rw-r--r--google/api_core/protobuf_helpers.py10
-rw-r--r--google/api_core/retry.py2
5 files changed, 29 insertions, 33 deletions
diff --git a/google/api_core/bidi.py b/google/api_core/bidi.py
index b171a41..be52d97 100644
--- a/google/api_core/bidi.py
+++ b/google/api_core/bidi.py
@@ -172,7 +172,9 @@ class _Throttle(object):
self._time_window = time_window
self._access_limit = access_limit
- self._past_entries = collections.deque(maxlen=access_limit) # least recent first
+ self._past_entries = collections.deque(
+ maxlen=access_limit
+ ) # least recent first
self._entry_lock = threading.Lock()
def __enter__(self):
@@ -198,9 +200,7 @@ class _Throttle(object):
def __repr__(self):
return "{}(access_limit={}, time_window={})".format(
- self.__class__.__name__,
- self._access_limit,
- repr(self._time_window),
+ self.__class__.__name__, self._access_limit, repr(self._time_window)
)
@@ -423,7 +423,7 @@ class ResumableBidiRpc(BidiRpc):
if throttle_reopen:
self._reopen_throttle = _Throttle(
- access_limit=5, time_window=datetime.timedelta(seconds=10),
+ access_limit=5, time_window=datetime.timedelta(seconds=10)
)
else:
self._reopen_throttle = None
diff --git a/google/api_core/datetime_helpers.py b/google/api_core/datetime_helpers.py
index 84c1bb7..e52fb1d 100644
--- a/google/api_core/datetime_helpers.py
+++ b/google/api_core/datetime_helpers.py
@@ -115,20 +115,10 @@ def from_iso8601_time(value):
def from_rfc3339(value):
- """Convert a microsecond-precision timestamp to datetime.
+ """Convert an RFC3339-format timestamp to a native datetime.
- Args:
- value (str): The RFC3339 string to convert.
-
- Returns:
- datetime.datetime: The datetime object equivalent to the timestamp in
- UTC.
- """
- return datetime.datetime.strptime(value, _RFC3339_MICROS).replace(tzinfo=pytz.utc)
-
-
-def from_rfc3339_nanos(value):
- """Convert a nanosecond-precision timestamp to a native datetime.
+ Supported formats include those without fractional seconds, or with
+ any fraction up to nanosecond precision.
.. note::
Python datetimes do not support nanosecond precision; this function
@@ -138,11 +128,11 @@ def from_rfc3339_nanos(value):
value (str): The RFC3339 string to convert.
Returns:
- datetime.datetime: The datetime object equivalent to the timestamp in
- UTC.
+ datetime.datetime: The datetime object equivalent to the timestamp
+ in UTC.
Raises:
- ValueError: If the timestamp does not match the RFC 3339
+ ValueError: If the timestamp does not match the RFC3339
regular expression.
"""
with_nanos = _RFC3339_NANOS.match(value)
@@ -169,6 +159,9 @@ def from_rfc3339_nanos(value):
return bare_seconds.replace(microsecond=micros, tzinfo=pytz.utc)
+from_rfc3339_nanos = from_rfc3339 # from_rfc3339_nanos method was deprecated.
+
+
def to_rfc3339(value, ignore_zone=True):
"""Convert a datetime to an RFC3339 timestamp string.
@@ -215,22 +208,22 @@ class DatetimeWithNanoseconds(datetime.datetime):
return self._nanosecond
def rfc3339(self):
- """Return an RFC 3339-compliant timestamp.
+ """Return an RFC3339-compliant timestamp.
Returns:
- (str): Timestamp string according to RFC 3339 spec.
+ (str): Timestamp string according to RFC3339 spec.
"""
if self._nanosecond == 0:
return to_rfc3339(self)
- nanos = str(self._nanosecond).rjust(9, '0').rstrip("0")
+ nanos = str(self._nanosecond).rjust(9, "0").rstrip("0")
return "{}.{}Z".format(self.strftime(_RFC3339_NO_FRACTION), nanos)
@classmethod
def from_rfc3339(cls, stamp):
- """Parse RFC 3339-compliant timestamp, preserving nanoseconds.
+ """Parse RFC3339-compliant timestamp, preserving nanoseconds.
Args:
- stamp (str): RFC 3339 stamp, with up to nanosecond precision
+ stamp (str): RFC3339 stamp, with up to nanosecond precision
Returns:
:class:`DatetimeWithNanoseconds`:
@@ -280,7 +273,7 @@ class DatetimeWithNanoseconds(datetime.datetime):
@classmethod
def from_timestamp_pb(cls, stamp):
- """Parse RFC 3339-compliant timestamp, preserving nanoseconds.
+ """Parse RFC3339-compliant timestamp, preserving nanoseconds.
Args:
stamp (:class:`~google.protobuf.timestamp_pb2.Timestamp`): timestamp message
diff --git a/google/api_core/iam.py b/google/api_core/iam.py
index 0e108a3..04680eb 100644
--- a/google/api_core/iam.py
+++ b/google/api_core/iam.py
@@ -34,11 +34,12 @@ Example usage:
"""
import collections
+import warnings
+
try:
from collections import abc as collections_abc
except ImportError: # Python 2.7
import collections as collections_abc
-import warnings
# Generic IAM roles
diff --git a/google/api_core/protobuf_helpers.py b/google/api_core/protobuf_helpers.py
index aec6b36..365ef25 100644
--- a/google/api_core/protobuf_helpers.py
+++ b/google/api_core/protobuf_helpers.py
@@ -15,10 +15,6 @@
"""Helpers for :mod:`protobuf`."""
import collections
-try:
- from collections import abc as collections_abc
-except ImportError: # Python 2.7
- import collections as collections_abc
import copy
import inspect
@@ -26,6 +22,12 @@ from google.protobuf import field_mask_pb2
from google.protobuf import message
from google.protobuf import wrappers_pb2
+try:
+ from collections import abc as collections_abc
+except ImportError: # Python 2.7
+ import collections as collections_abc
+
+
_SENTINEL = object()
_WRAPPER_TYPES = (
wrappers_pb2.BoolValue,
diff --git a/google/api_core/retry.py b/google/api_core/retry.py
index 79343ba..5962a68 100644
--- a/google/api_core/retry.py
+++ b/google/api_core/retry.py
@@ -237,7 +237,7 @@ class Retry(object):
maximum=_DEFAULT_MAXIMUM_DELAY,
multiplier=_DEFAULT_DELAY_MULTIPLIER,
deadline=_DEFAULT_DEADLINE,
- on_error=None
+ on_error=None,
):
self._predicate = predicate
self._initial = initial