• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python constraints.FORMAT2CONTENT_TYPE类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中swift.common.constraints.FORMAT2CONTENT_TYPE的典型用法代码示例。如果您正苦于以下问题:Python FORMAT2CONTENT_TYPE类的具体用法?Python FORMAT2CONTENT_TYPE怎么用?Python FORMAT2CONTENT_TYPE使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FORMAT2CONTENT_TYPE类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: account_listing_content_type

def account_listing_content_type(req):
    """
    Figure out the content type of an account-listing response.

    Returns a 2-tuple: (content_type, error). Only one of them will be set;
    the other will be None.
    """
    query_format = get_param(req, 'format')
    if query_format:
        req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
                                             FORMAT2CONTENT_TYPE['plain'])
    content_type = req.accept.best_match(
        ['text/plain', 'application/json', 'application/xml', 'text/xml'])
    if not content_type:
        return (None, HTTPNotAcceptable(request=req))
    else:
        return (content_type, None)
开发者ID:Awingu,项目名称:swift,代码行数:17,代码来源:utils.py


示例2: get_listing_content_type

def get_listing_content_type(req):
    """
    Determine the content type to use for an account or container listing
    response.

    :param req: request object
    :returns: content type as a string (e.g. text/plain, application/json)
    :raises: HTTPNotAcceptable if the requested content type is not acceptable
    :raises: HTTPBadRequest if the 'format' query param is provided and
             not valid UTF-8
    """
    query_format = get_param(req, "format")
    if query_format:
        req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(), FORMAT2CONTENT_TYPE["plain"])
    out_content_type = req.accept.best_match(["text/plain", "application/json", "application/xml", "text/xml"])
    if not out_content_type:
        raise HTTPNotAcceptable(request=req)
    return out_content_type
开发者ID:bigdig,项目名称:swift,代码行数:18,代码来源:request_helpers.py


示例3: int

     if given_limit and given_limit.isdigit():
         limit = int(given_limit)
         if limit > ACCOUNT_LISTING_LIMIT:
             self.logger.increment('GET.errors')
             return HTTPPreconditionFailed(request=req,
                                           body='Maximum limit is %d' %
                                           ACCOUNT_LISTING_LIMIT)
     marker = get_param(req, 'marker', '')
     end_marker = get_param(req, 'end_marker')
     query_format = get_param(req, 'format')
 except UnicodeDecodeError, err:
     self.logger.increment('GET.errors')
     return HTTPBadRequest(body='parameters not utf8',
                           content_type='text/plain', request=req)
 if query_format:
     req.accept = FORMAT2CONTENT_TYPE.get(query_format.lower(),
                                          FORMAT2CONTENT_TYPE['plain'])
 try:
     out_content_type = req.accept.best_match(
         ['text/plain', 'application/json', 'application/xml',
          'text/xml'],
         default_match='text/plain')
 except AssertionError, err:
     self.logger.increment('GET.errors')
     return HTTPBadRequest(body='bad accept header: %s' % req.accept,
                           content_type='text/plain', request=req)
 account_list = broker.list_containers_iter(limit, marker, end_marker,
                                            prefix, delimiter)
 if out_content_type == 'application/json':
     data = []
     for (name, object_count, bytes_used, is_subdir) in account_list:
         if is_subdir:
开发者ID:VictorLowther,项目名称:swift,代码行数:32,代码来源:server.py


示例4: HTTPNotFound

        if broker.is_deleted():
            return HTTPNotFound(request=req)
        info = broker.get_info()
        headers = {
            "X-Container-Object-Count": info["object_count"],
            "X-Container-Bytes-Used": info["bytes_used"],
            "X-Timestamp": info["created_at"],
            "X-PUT-Timestamp": info["put_timestamp"],
        }
        headers.update(
            (key, value)
            for key, (value, timestamp) in broker.metadata.iteritems()
            if value != "" and (key.lower() in self.save_headers or key.lower().startswith("x-container-meta-"))
        )
        if get_param(req, "format"):
            req.accept = FORMAT2CONTENT_TYPE.get(get_param(req, "format").lower(), FORMAT2CONTENT_TYPE["plain"])
        try:
            headers["Content-Type"] = req.accept.best_match(
                ["text/plain", "application/json", "application/xml", "text/xml"], default_match="text/plain"
            )
        except AssertionError, err:
            return HTTPBadRequest(body="bad accept header: %s" % req.accept, content_type="text/plain", request=req)
        return HTTPNoContent(request=req, headers=headers, charset="utf-8")

    @public
    @timing_stats
    def GET(self, req):
        """Handle HTTP GET request."""
        try:
            drive, part, account, container, obj = split_path(unquote(req.path), 4, 5, True)
            validate_device_partition(drive, part)
开发者ID:DylanYu,项目名称:swift,代码行数:31,代码来源:server.py


示例5: HTTPNotFound

        if broker.is_deleted():
            return HTTPNotFound(request=req)
        info = broker.get_info()
        headers = {
            'X-Container-Object-Count': info['object_count'],
            'X-Container-Bytes-Used': info['bytes_used'],
            'X-Timestamp': info['created_at'],
            'X-PUT-Timestamp': info['put_timestamp'],
        }
        headers.update(
            (key, value)
            for key, (value, timestamp) in broker.metadata.iteritems()
            if value != '' and (key.lower() in self.save_headers or
                                key.lower().startswith('x-container-meta-')))
        if get_param(req, 'format'):
            req.accept = FORMAT2CONTENT_TYPE.get(
                get_param(req, 'format').lower(), FORMAT2CONTENT_TYPE['plain'])
        headers['Content-Type'] = req.accept.best_match(
            ['text/plain', 'application/json', 'application/xml', 'text/xml'])
        if not headers['Content-Type']:
            return HTTPNotAcceptable(request=req)
        return HTTPNoContent(request=req, headers=headers, charset='utf-8')

    @public
    @timing_stats
    def GET(self, req):
        """Handle HTTP GET request."""
        try:
            drive, part, account, container, obj = split_path(
                unquote(req.path), 4, 5, True)
            validate_device_partition(drive, part)
        except ValueError, err:
开发者ID:UshF,项目名称:swift,代码行数:32,代码来源:server.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python container_sync_realms.ContainerSyncRealms类代码示例发布时间:2022-05-27
下一篇:
Python constraints.valid_timestamp函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap