当前位置: 首页>>代码示例>>Python>>正文


Python Response.headers["X-Timestamp"]方法代码示例

本文整理汇总了Python中swift.common.swob.Response.headers["X-Timestamp"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["X-Timestamp"]方法的具体用法?Python Response.headers["X-Timestamp"]怎么用?Python Response.headers["X-Timestamp"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在swift.common.swob.Response的用法示例。


在下文中一共展示了Response.headers["X-Timestamp"]方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HEAD

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def HEAD(self, request):
     """Handle HTTP HEAD requests for the Swift Object Server."""
     device, partition, account, container, obj, policy_idx = get_name_and_placement(request, 5, 5, True)
     try:
         disk_file = self.get_diskfile(device, partition, account, container, obj, policy_idx=policy_idx)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         metadata = disk_file.read_metadata()
     except DiskFileXattrNotSupported:
         return HTTPInsufficientStorage(drive=device, request=request)
     except (DiskFileNotExist, DiskFileQuarantined) as e:
         headers = {}
         if hasattr(e, "timestamp"):
             headers["X-Backend-Timestamp"] = e.timestamp.internal
         return HTTPNotFound(request=request, headers=headers, conditional_response=True)
     response = Response(request=request, conditional_response=True)
     response.headers["Content-Type"] = metadata.get("Content-Type", "application/octet-stream")
     for key, value in metadata.iteritems():
         if is_sys_or_user_meta("object", key) or key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = metadata["ETag"]
     ts = Timestamp(metadata["X-Timestamp"])
     response.last_modified = math.ceil(float(ts))
     # Needed for container sync feature
     response.headers["X-Timestamp"] = ts.normal
     response.headers["X-Backend-Timestamp"] = ts.internal
     response.content_length = int(metadata["Content-Length"])
     try:
         response.content_encoding = metadata["Content-Encoding"]
     except KeyError:
         pass
     return response
开发者ID:steveruckdashel,项目名称:swift,代码行数:35,代码来源:server.py

示例2: HEAD

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def HEAD(self, request):
     """Handle HTTP HEAD requests for the Swift Object Server."""
     device, partition, account, container, obj = split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self.get_diskfile(device, partition, account, container, obj)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         metadata = disk_file.read_metadata()
     except (DiskFileNotExist, DiskFileQuarantined):
         return HTTPNotFound(request=request)
     response = Response(request=request, conditional_response=True)
     response.headers["Content-Type"] = metadata.get("Content-Type", "application/octet-stream")
     for key, value in metadata.iteritems():
         if is_user_meta("object", key) or key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = metadata["ETag"]
     ts = metadata["X-Timestamp"]
     response.last_modified = math.ceil(float(ts))
     # Needed for container sync feature
     response.headers["X-Timestamp"] = ts
     response.content_length = int(metadata["Content-Length"])
     try:
         response.content_encoding = metadata["Content-Encoding"]
     except KeyError:
         pass
     return response
开发者ID:vbaret,项目名称:swift,代码行数:29,代码来源:server.py

示例3: HEAD

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def HEAD(self, request):
     """Handle HTTP HEAD requests for the Swift Object Server."""
     device, partition, account, container, obj = split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self._diskfile(device, partition, account, container, obj)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     if disk_file.is_deleted() or disk_file.is_expired():
         return HTTPNotFound(request=request)
     try:
         file_size = disk_file.get_data_file_size()
     except (DiskFileError, DiskFileNotExist):
         disk_file.quarantine()
         return HTTPNotFound(request=request)
     response = Response(request=request, conditional_response=True)
     response.headers["Content-Type"] = disk_file.metadata.get("Content-Type", "application/octet-stream")
     for key, value in disk_file.metadata.iteritems():
         if key.lower().startswith("x-object-meta-") or key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = disk_file.metadata["ETag"]
     response.last_modified = float(disk_file.metadata["X-Timestamp"])
     # Needed for container sync feature
     response.headers["X-Timestamp"] = disk_file.metadata["X-Timestamp"]
     response.content_length = file_size
     if "Content-Encoding" in disk_file.metadata:
         response.content_encoding = disk_file.metadata["Content-Encoding"]
     return response
开发者ID:vishalkanaujia,项目名称:swift,代码行数:29,代码来源:server.py

示例4: GET

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj, policy_idx = get_name_and_placement(request, 5, 5, True)
     keep_cache = self.keep_cache_private or (
         "X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers
     )
     try:
         disk_file = self.get_diskfile(device, partition, account, container, obj, policy_idx=policy_idx)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         with disk_file.open():
             metadata = disk_file.get_metadata()
             obj_size = int(metadata["Content-Length"])
             file_x_ts = Timestamp(metadata["X-Timestamp"])
             keep_cache = self.keep_cache_private or (
                 "X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers
             )
             response = Response(
                 app_iter=disk_file.reader(keep_cache=keep_cache), request=request, conditional_response=True
             )
             response.headers["Content-Type"] = metadata.get("Content-Type", "application/octet-stream")
             for key, value in metadata.iteritems():
                 if is_sys_or_user_meta("object", key) or key.lower() in self.allowed_headers:
                     response.headers[key] = value
             response.etag = metadata["ETag"]
             response.last_modified = math.ceil(float(file_x_ts))
             response.content_length = obj_size
             try:
                 response.content_encoding = metadata["Content-Encoding"]
             except KeyError:
                 pass
             response.headers["X-Timestamp"] = file_x_ts.normal
             response.headers["X-Backend-Timestamp"] = file_x_ts.internal
             resp = request.get_response(response)
     except DiskFileXattrNotSupported:
         return HTTPInsufficientStorage(drive=device, request=request)
     except (DiskFileNotExist, DiskFileQuarantined) as e:
         headers = {}
         if hasattr(e, "timestamp"):
             headers["X-Backend-Timestamp"] = e.timestamp.internal
         resp = HTTPNotFound(request=request, headers=headers, conditional_response=True)
     return resp
开发者ID:steveruckdashel,项目名称:swift,代码行数:45,代码来源:server.py

示例5: Response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
        response = Response(app_iter=disk_file, request=request, conditional_response=True)
        response.headers["Content-Type"] = disk_file.metadata.get("Content-Type", "application/octet-stream")
        for key, value in disk_file.metadata.iteritems():
            if key.lower().startswith("x-object-meta-") or key.lower() in self.allowed_headers:
                response.headers[key] = value
        response.etag = disk_file.metadata["ETag"]
        response.last_modified = float(disk_file.metadata["X-Timestamp"])
        response.content_length = file_size
        if response.content_length < self.keep_cache_size and (
            self.keep_cache_private
            or ("X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers)
        ):
            disk_file.keep_cache = True
        if "Content-Encoding" in disk_file.metadata:
            response.content_encoding = disk_file.metadata["Content-Encoding"]
        response.headers["X-Timestamp"] = disk_file.metadata["X-Timestamp"]
        return request.get_response(response)

    @public
    @timing_stats(sample_rate=0.8)
    def HEAD(self, request):
        """Handle HTTP HEAD requests for the Swift Object Server."""
        try:
            device, partition, account, container, obj = split_path(unquote(request.path), 5, 5, True)
            validate_device_partition(device, partition)
        except ValueError, err:
            resp = HTTPBadRequest(request=request)
            resp.content_type = "text/plain"
            resp.body = str(err)
            return resp
        if self.mount_check and not check_mount(self.devices, device):
开发者ID:schatt,项目名称:swift,代码行数:33,代码来源:server.py

示例6: GET

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = split_and_validate_path(request, 5, 5, True)
     keep_cache = self.keep_cache_private or (
         "X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers
     )
     try:
         disk_file = self.get_diskfile(device, partition, account, container, obj)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         with disk_file.open():
             metadata = disk_file.get_metadata()
             obj_size = int(metadata["Content-Length"])
             if request.headers.get("if-match") not in (None, "*") and metadata["ETag"] not in request.if_match:
                 return HTTPPreconditionFailed(request=request)
             if request.headers.get("if-none-match") is not None:
                 if metadata["ETag"] in request.if_none_match:
                     resp = HTTPNotModified(request=request)
                     resp.etag = metadata["ETag"]
                     return resp
             file_x_ts = metadata["X-Timestamp"]
             file_x_ts_flt = float(file_x_ts)
             try:
                 if_unmodified_since = request.if_unmodified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             file_x_ts_utc = datetime.fromtimestamp(file_x_ts_flt, UTC)
             if if_unmodified_since and file_x_ts_utc > if_unmodified_since:
                 return HTTPPreconditionFailed(request=request)
             try:
                 if_modified_since = request.if_modified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             if if_modified_since and file_x_ts_utc <= if_modified_since:
                 return HTTPNotModified(request=request)
             keep_cache = self.keep_cache_private or (
                 "X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers
             )
             response = Response(
                 app_iter=disk_file.reader(keep_cache=keep_cache), request=request, conditional_response=True
             )
             response.headers["Content-Type"] = metadata.get("Content-Type", "application/octet-stream")
             for key, value in metadata.iteritems():
                 if is_user_meta("object", key) or key.lower() in self.allowed_headers:
                     response.headers[key] = value
             response.etag = metadata["ETag"]
             response.last_modified = math.ceil(file_x_ts_flt)
             response.content_length = obj_size
             try:
                 response.content_encoding = metadata["Content-Encoding"]
             except KeyError:
                 pass
             response.headers["X-Timestamp"] = file_x_ts
             resp = request.get_response(response)
     except DiskFileNotExist:
         if request.headers.get("if-match") == "*":
             resp = HTTPPreconditionFailed(request=request)
         else:
             resp = HTTPNotFound(request=request)
     except DiskFileQuarantined:
         resp = HTTPNotFound(request=request)
     return resp
开发者ID:vbaret,项目名称:swift,代码行数:67,代码来源:server.py

示例7: GET

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import headers["X-Timestamp"] [as 别名]
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self._diskfile(device, partition, account, container, obj, keep_data_fp=True, iter_hook=sleep)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     if disk_file.is_deleted() or disk_file.is_expired():
         if request.headers.get("if-match") == "*":
             return HTTPPreconditionFailed(request=request)
         else:
             return HTTPNotFound(request=request)
     try:
         file_size = disk_file.get_data_file_size()
     except (DiskFileError, DiskFileNotExist):
         disk_file.quarantine()
         return HTTPNotFound(request=request)
     if request.headers.get("if-match") not in (None, "*") and disk_file.metadata["ETag"] not in request.if_match:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     if request.headers.get("if-none-match") is not None:
         if disk_file.metadata["ETag"] in request.if_none_match:
             resp = HTTPNotModified(request=request)
             resp.etag = disk_file.metadata["ETag"]
             disk_file.close()
             return resp
     try:
         if_unmodified_since = request.if_unmodified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if (
         if_unmodified_since
         and datetime.fromtimestamp(float(disk_file.metadata["X-Timestamp"]), UTC) > if_unmodified_since
     ):
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     try:
         if_modified_since = request.if_modified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if (
         if_modified_since
         and datetime.fromtimestamp(float(disk_file.metadata["X-Timestamp"]), UTC) < if_modified_since
     ):
         disk_file.close()
         return HTTPNotModified(request=request)
     response = Response(app_iter=disk_file, request=request, conditional_response=True)
     response.headers["Content-Type"] = disk_file.metadata.get("Content-Type", "application/octet-stream")
     for key, value in disk_file.metadata.iteritems():
         if key.lower().startswith("x-object-meta-") or key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = disk_file.metadata["ETag"]
     response.last_modified = float(disk_file.metadata["X-Timestamp"])
     response.content_length = file_size
     if response.content_length < self.keep_cache_size and (
         self.keep_cache_private
         or ("X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers)
     ):
         disk_file.keep_cache = True
     if "Content-Encoding" in disk_file.metadata:
         response.content_encoding = disk_file.metadata["Content-Encoding"]
     response.headers["X-Timestamp"] = disk_file.metadata["X-Timestamp"]
     return request.get_response(response)
开发者ID:vishalkanaujia,项目名称:swift,代码行数:67,代码来源:server.py


注:本文中的swift.common.swob.Response.headers["X-Timestamp"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。