|
|
|
@ -43,7 +43,6 @@ __author__ = 'jieluo@google.com (Jie Luo)' |
|
|
|
|
import calendar |
|
|
|
|
from datetime import datetime |
|
|
|
|
from datetime import timedelta |
|
|
|
|
import six |
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
# Since python 3 |
|
|
|
@ -143,7 +142,7 @@ class Timestamp(object): |
|
|
|
|
Raises: |
|
|
|
|
ValueError: On parsing problems. |
|
|
|
|
""" |
|
|
|
|
if not isinstance(value, six.string_types): |
|
|
|
|
if not isinstance(value, str): |
|
|
|
|
raise ValueError('Timestamp JSON value not a string: {!r}'.format(value)) |
|
|
|
|
timezone_offset = value.find('Z') |
|
|
|
|
if timezone_offset == -1: |
|
|
|
@ -305,7 +304,7 @@ class Duration(object): |
|
|
|
|
Raises: |
|
|
|
|
ValueError: On parsing problems. |
|
|
|
|
""" |
|
|
|
|
if not isinstance(value, six.string_types): |
|
|
|
|
if not isinstance(value, str): |
|
|
|
|
raise ValueError('Duration JSON value not a string: {!r}'.format(value)) |
|
|
|
|
if len(value) < 1 or value[-1] != 's': |
|
|
|
|
raise ValueError( |
|
|
|
@ -432,7 +431,7 @@ class FieldMask(object): |
|
|
|
|
|
|
|
|
|
def FromJsonString(self, value): |
|
|
|
|
"""Converts string to FieldMask according to proto3 JSON spec.""" |
|
|
|
|
if not isinstance(value, six.string_types): |
|
|
|
|
if not isinstance(value, str): |
|
|
|
|
raise ValueError('FieldMask JSON value not a string: {!r}'.format(value)) |
|
|
|
|
self.Clear() |
|
|
|
|
if value: |
|
|
|
@ -718,9 +717,6 @@ def _AddFieldPaths(node, prefix, field_mask): |
|
|
|
|
_AddFieldPaths(node[name], child_path, field_mask) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_INT_OR_FLOAT = six.integer_types + (float,) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _SetStructValue(struct_value, value): |
|
|
|
|
if value is None: |
|
|
|
|
struct_value.null_value = 0 |
|
|
|
@ -728,9 +724,9 @@ def _SetStructValue(struct_value, value): |
|
|
|
|
# Note: this check must come before the number check because in Python |
|
|
|
|
# True and False are also considered numbers. |
|
|
|
|
struct_value.bool_value = value |
|
|
|
|
elif isinstance(value, six.string_types): |
|
|
|
|
elif isinstance(value, str): |
|
|
|
|
struct_value.string_value = value |
|
|
|
|
elif isinstance(value, _INT_OR_FLOAT): |
|
|
|
|
elif isinstance(value, (int, float)): |
|
|
|
|
struct_value.number_value = value |
|
|
|
|
elif isinstance(value, (dict, Struct)): |
|
|
|
|
struct_value.struct_value.Clear() |
|
|
|
|