def testTimeConversion(self): posix_time = 1354144241.0 http_time = 'Wed, 28 Nov 2012 23:10:41 GMT' self.assertEqual(http_time, common.posix_time_to_http(posix_time)) self.assertEqual(posix_time, common.http_time_to_posix(http_time)) posix = math.floor(time.time()) http_time = common.posix_time_to_http(posix) self.assertEqual('GMT', http_time[-3:]) new_posix = common.http_time_to_posix(http_time) self.assertEqual(posix, new_posix)
def stat(filename, retry_params=None, _account_id=None): """Get GCSFileStat of a Google Cloud storage file. Args: filename: A Google Cloud Storage filename of form '/bucket/filename'. retry_params: An api_utils.RetryParams for this call to GCS. If None, the default one is used. _account_id: Internal-use only. Returns: a GCSFileStat object containing info about this file. Raises: errors.AuthorizationError: if authorization failed. errors.NotFoundError: if an object that's expected to exist doesn't. """ common.validate_file_path(filename) api = storage_api._get_storage_api(retry_params=retry_params, account_id=_account_id) status, headers, content = api.head_object( api_utils._quote_filename(filename)) errors.check_status(status, [200], filename, resp_headers=headers, body=content) file_stat = common.GCSFileStat( filename=filename, st_size=common.get_stored_content_length(headers), st_ctime=common.http_time_to_posix(headers.get('last-modified')), etag=headers.get('etag'), content_type=headers.get('content-type'), metadata=common.get_metadata(headers)) return file_stat