Exemplo n.º 1
0
 def _parse_value_resource(resource):
     """Helper for _parse_fields_resource"""
     if 'stringValue' in resource:
         string_format = resource.get('stringFormat')
         language = resource.get('lang')
         value = resource['stringValue']
         return StringValue(value, string_format, language)
     if 'numberValue' in resource:
         value = resource['numberValue']
         if isinstance(value, six.string_types):
             if '.' in value:
                 value = float(value)
             else:
                 value = int(value)
         return NumberValue(value)
     if 'timestampValue' in resource:
         stamp = resource['timestampValue']
         value = _rfc3339_to_datetime(stamp)
         return TimestampValue(value)
     if 'geoValue' in resource:
         lat_long = resource['geoValue']
         latitude, longitude = [
             float(coord.strip()) for coord in lat_long.split(',')
         ]
         return GeoValue((latitude, longitude))
     raise ValueError("Unknown value type")
Exemplo n.º 2
0
    def _verifyResourceProperties(self, changes, resource, zone):
        from gcloud._helpers import _rfc3339_to_datetime
        from gcloud._helpers import UTC
        self.assertEqual(changes.name, resource['id'])
        started = _rfc3339_to_datetime(resource['startTime'])
        self.assertEqual(changes.started, started)
        self.assertEqual(changes.status, resource['status'])

        r_additions = resource.get('additions', ())
        self.assertEqual(len(changes.additions), len(r_additions))
        for found, expected in zip(changes.additions, r_additions):
            self.assertEqual(found.name, expected['name'])
            self.assertEqual(found.record_type, expected['type'])
            self.assertEqual(found.ttl, int(expected['ttl']))
            self.assertEqual(found.rrdatas, expected['rrdatas'])
            self.assertTrue(found.zone is zone)

        r_deletions = resource.get('deletions', ())
        self.assertEqual(len(changes.deletions), len(r_deletions))
        for found, expected in zip(changes.deletions, r_deletions):
            self.assertEqual(found.name, expected['name'])
            self.assertEqual(found.record_type, expected['type'])
            self.assertEqual(found.ttl, int(expected['ttl']))
            self.assertEqual(found.rrdatas, expected['rrdatas'])
            self.assertTrue(found.zone is zone)
Exemplo n.º 3
0
    def _verifyResourceProperties(self, changes, resource, zone):
        from gcloud._helpers import _rfc3339_to_datetime
        from gcloud._helpers import UTC
        self.assertEqual(changes.name, resource['id'])
        started = _rfc3339_to_datetime(resource['startTime'])
        self.assertEqual(changes.started, started)
        self.assertEqual(changes.status, resource['status'])

        r_additions = resource.get('additions', ())
        self.assertEqual(len(changes.additions), len(r_additions))
        for found, expected in zip(changes.additions, r_additions):
            self.assertEqual(found.name, expected['name'])
            self.assertEqual(found.record_type, expected['type'])
            self.assertEqual(found.ttl, int(expected['ttl']))
            self.assertEqual(found.rrdatas, expected['rrdatas'])
            self.assertTrue(found.zone is zone)

        r_deletions = resource.get('deletions', ())
        self.assertEqual(len(changes.deletions), len(r_deletions))
        for found, expected in zip(changes.deletions, r_deletions):
            self.assertEqual(found.name, expected['name'])
            self.assertEqual(found.record_type, expected['type'])
            self.assertEqual(found.ttl, int(expected['ttl']))
            self.assertEqual(found.rrdatas, expected['rrdatas'])
            self.assertTrue(found.zone is zone)
Exemplo n.º 4
0
    def started(self):
        """Time when the change set was started.

        :rtype: ``datetime.datetime`` or ``NoneType``
        :returns: Time, as set by the back-end, or None.
        """
        stamp = self._properties.get('startTime')
        if stamp is not None:
            return _rfc3339_to_datetime(stamp)
Exemplo n.º 5
0
    def started(self):
        """Time when the change set was started.

        :rtype: ``datetime.datetime`` or ``NoneType``
        :returns: Time, as set by the back-end, or None.
        """
        stamp = self._properties.get('startTime')
        if stamp is not None:
            return _rfc3339_to_datetime(stamp)
Exemplo n.º 6
0
    def time_created(self):
        """Retrieve the timestamp at which the bucket was created.

        See: https://cloud.google.com/storage/docs/json_api/v1/buckets

        :rtype: :class:`datetime.datetime` or ``NoneType``
        :returns: Datetime object parsed from RFC3339 valid timestamp, or
                  ``None`` if the property is not set locally.
        """
        value = self._properties.get('timeCreated')
        if value is not None:
            return _rfc3339_to_datetime(value)
Exemplo n.º 7
0
    def time_created(self):
        """Retrieve the timestamp at which the bucket was created.

        See: https://cloud.google.com/storage/docs/json_api/v1/buckets

        :rtype: :class:`datetime.datetime` or ``NoneType``
        :returns: Datetime object parsed from RFC3339 valid timestamp, or
                  ``None`` if the property is not set locally.
        """
        value = self._properties.get('timeCreated')
        if value is not None:
            return _rfc3339_to_datetime(value)
Exemplo n.º 8
0
    def _set_properties(self, api_response):
        """Update properties from resource in body of ``api_response``

        :type api_response: httplib2.Response
        :param api_response: response returned from an API call
        """
        self._properties.clear()
        cleaned = api_response.copy()
        if 'creationTime' in cleaned:
            cleaned['creationTime'] = _rfc3339_to_datetime(
                cleaned['creationTime'])
        self._properties.update(cleaned)
Exemplo n.º 9
0
    def time_deleted(self):
        """Retrieve the timestamp at which the object was deleted.

        See: https://cloud.google.com/storage/docs/json_api/v1/objects

        :rtype: :class:`datetime.datetime` or ``NoneType``
        :returns: Datetime object parsed from RFC3339 valid timestamp, or
                  ``None`` if the property is not set locally. If the blob has
                  not been deleted, this will never be set.
        """
        value = self._properties.get('timeDeleted')
        if value is not None:
            return _rfc3339_to_datetime(value)
Exemplo n.º 10
0
    def time_deleted(self):
        """Retrieve the timestamp at which the object was deleted.

        See: https://cloud.google.com/storage/docs/json_api/v1/objects

        :rtype: :class:`datetime.datetime` or ``NoneType``
        :returns: Datetime object parsed from RFC3339 valid timestamp, or
                  ``None`` if the property is not set locally. If the blob has
                  not been deleted, this will never be set.
        """
        value = self._properties.get('timeDeleted')
        if value is not None:
            return _rfc3339_to_datetime(value)
Exemplo n.º 11
0
    def timestamp(self):
        """Return sortable timestamp from attributes, if passed.

        Allows sorting messages in publication order (assuming consistent
        clocks across all publishers).

        :rtype: :class:`datetime.datetime`
        :returns: timestamp (in UTC timezone) parsed from RFC 3339 timestamp
        :raises: ValueError if timestamp not in ``attributes``, or if it does
                 not match the RFC 3339 format.
        """
        stamp = self.attributes.get('timestamp')
        if stamp is None:
            raise ValueError('No timestamp')
        return _rfc3339_to_datetime(stamp)
Exemplo n.º 12
0
    def timestamp(self):
        """Return sortable timestamp from attributes, if passed.

        Allows sorting messages in publication order (assuming consistent
        clocks across all publishers).

        :rtype: :class:`datetime.datetime`
        :returns: timestamp (in UTC timezone) parsed from RFC 3339 timestamp
        :raises: ValueError if timestamp not in ``attributes``, or if it does
                 not match the RFC 3339 format.
        """
        stamp = self.attributes.get("timestamp")
        if stamp is None:
            raise ValueError("No timestamp")
        return _rfc3339_to_datetime(stamp)
Exemplo n.º 13
0
 def _callFUT(self, dt_str):
     from gcloud._helpers import _rfc3339_to_datetime
     return _rfc3339_to_datetime(dt_str)
Exemplo n.º 14
0
 def _callFUT(self, dt_str):
     from gcloud._helpers import _rfc3339_to_datetime
     return _rfc3339_to_datetime(dt_str)