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


Python constraints.FORMAT2CONTENT_TYPE类代码示例

本文整理汇总了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;未经允许,请勿转载。