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


Python Request.environ['PATH_INFO']方法代码示例

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


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

示例1: __call__

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import environ['PATH_INFO'] [as 别名]

#.........这里部分代码省略.........
                # (json is default format)
                out = self.format_object_status_info_for_reporting(
                    req, replicas_status) + '\n'
                # Report object status
                return Response(status=HTTP_OK,
                                body=out,
                                content_type="text/plain")(env, start_response)

        # Process container request
        if (container and not obj and
           ((method == 'POST' and ('MIGRATE' in query or 'RECALL' in query))
                or method == 'GET' and 'STATUS' in query)):
            self.logger.debug('Process container request')
            # Get list of objects
            list_url = 'http://%(ip)s:8080%(url)s'
            list_req = list_url % {'ip': self.ip,
                                   'url': req.path}
            self.logger.debug('list_req: %s', list_req)
            self.logger.debug('req.headers: %s', str(req.headers))
            token = req.headers['X-Storage-Token']
            self.logger.debug('token: %s', token)
            headers = {'X-Storage-Token': token}
            response = requests.get(list_req, headers=headers)
            self.logger.debug('response.headers: %s', str(response.headers))
            self.logger.debug('list: %s', str(response.content))
            objects = response.content.strip().split('\n')
            # Submit migration or recall
            if method == 'POST':
                if 'MIGRATE' in query:
                    hlm_req = 'MIGRATE'
                    hlm_backend = self.migrate_backend
                elif 'RECALL' in query:
                    hlm_req = 'RECALL'
                    hlm_backend = self.recall_backend
                # submit hlm requests
                success = 0
                failure = 0
                for obj in objects:
                    self.logger.debug('obj: %s', obj)
                    status, out = self.submit_object_replicas_migration_recall(
                        req, account, container, obj, hlm_req, hlm_backend)
                    self.logger.debug('submit_object_replicas_migr.._recall()')
                    if status == SUBMITTED_FORWARDED_REQUEST:
                        self.logger.debug('SUBMITTED_FORWARDED_REQUEST')
                        return Response(status=HTTP_OK,
                                        body='Accepted remote replica'
                                        'HLM request',
                                        content_type="text/plain")(
                            env, start_response)
                    elif status == FAILED_SUBMITTING_REQUEST:
                        self.logger.debug('FAILED_SUBMITTING_REQUEST')
                        failure += 1
                    elif status == SUBMITTED_REQUESTS:
                        self.logger.debug('SUBMITTED_REQUESTS')
                        success += 1
                if failure == 0:
                    return Response(status=HTTP_OK,
                                    body='Submitted %s requests.\n' % hlm_req,
                                    content_type="text/plain")(env,
                                                               start_response)
                elif success == 0:
                    return Response(status=HTTP_INTERNAL_SERVER_ERROR,
                                    body='Failed to submit %s requests.\n' %
                                    hlm_req,
                                    content_type="text/plain")(env,
                                                               start_response)
                else:
                    return Response(status=HTTP_OK,
                                    body="Submitting %s requests"
                                    " is only partially"
                                    " successful.\n" % hlm_req,
                                    content_type="text/plain")(env,
                                                               start_response)
            elif method == 'GET':
                # submit hlm requests
                accumulated_out = "["
                for obj in objects:
                    self.logger.debug('obj: %s', obj)

                    # Get status of each replica
                    # rewrite req.path to point to object instead of container
                    req_orig_path = req.environ['PATH_INFO']
                    req.environ['PATH_INFO'] += "/" + obj
                    rc, out, replicas_status = self.get_object_replicas_status(
                        req, account, container, obj)

                    # Prepare/format object status info to report
                    # (json is default format)
                    accumulated_out += self.format_object_status_info_for_reporting(
                        req, replicas_status) + ','

                    req.environ['PATH_INFO'] = req_orig_path

                # Report accumulated object status
                accumulated_out = accumulated_out[:-1] + ']'
                return Response(status=HTTP_OK,
                                body=accumulated_out,
                                content_type="text/plain")(env, start_response)

        return self.app(env, start_response)
开发者ID:ibm-research,项目名称:SwiftHLM,代码行数:104,代码来源:middleware.py


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