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


Python Response.app_iter方法代码示例

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


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

示例1: make_object_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def make_object_response(self, req, metadata, stream=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        resp.headers['Content-Type'] = metadata.get(
            'mime-type', 'application/octet-stream')
        for k, v in metadata.iteritems():
            if k.startswith("user."):
                meta = k[5:]
                if is_sys_or_user_meta('object', meta) or \
                                meta.lower() in self.allowed_headers:
                    resp.headers[meta] = v
        resp.etag = metadata['hash'].lower()
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            resp.app_iter = stream
        resp.content_length = int(metadata['length'])
        try:
            resp.content_encoding = metadata['encoding']
        except KeyError:
            pass
        return resp
开发者ID:GuillaumeDelaporte,项目名称:oio-swift,代码行数:30,代码来源:obj.py

示例2: make_object_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def make_object_response(self, req, metadata, stream=None, ranges=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.iteritems():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        resp.headers['etag'] = metadata['hash'].lower()
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            if ranges:
                resp.app_iter = StreamRangeIterator(stream)
            else:
                resp.app_iter = stream

        resp.content_length = int(metadata['length'])
        try:
            resp.content_encoding = metadata['encoding']
        except KeyError:
            pass
        resp.accept_ranges = 'bytes'
        return resp
开发者ID:fvennetier,项目名称:oio-swift,代码行数:40,代码来源:obj.py

示例3: pass_file

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
 def pass_file(self, req, path, content_type=None):
     """ pass a file to client """
     resp = Response()
     if content_type:
         resp.content_type = content_type
     else:
         (ctype, enc) = guess_type(basename(path))
         resp.content_type = ctype
     resp.charset = None
     try:
         with open(join(self.path, path)) as f:
             resp.app_iter = iter(f.read())
             return resp
     except IOError:
         return HTTPNotFound(request=req)
开发者ID:famao,项目名称:Taylor,代码行数:17,代码来源:taylor.py

示例4: get_working_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
 def get_working_response(self, req):
     source, node = self._get_source_and_node()
     res = None
     if source:
         res = Response(request=req)
         if req.method == "GET" and source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
             res.app_iter = self._make_app_iter(node, source)
             # See NOTE: swift_conn at top of file about this.
             res.swift_conn = source.swift_conn
         res.status = source.status
         update_headers(res, source.getheaders())
         if not res.environ:
             res.environ = {}
         res.environ["swift_x_timestamp"] = source.getheader("x-timestamp")
         res.accept_ranges = "bytes"
         res.content_length = source.getheader("Content-Length")
         if source.getheader("Content-Type"):
             res.charset = None
             res.content_type = source.getheader("Content-Type")
     return res
开发者ID:UoM-ResPlat-DevOps,项目名称:swift,代码行数:22,代码来源:base.py

示例5: make_object_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def make_object_response(self, req, metadata, stream=None):
        conditional_etag = None
        if 'X-Backend-Etag-Is-At' in req.headers:
            conditional_etag = metadata.get(
                req.headers['X-Backend-Etag-Is-At'])

        resp = Response(request=req, conditional_response=True,
                        conditional_etag=conditional_etag)

        if config_true_value(metadata['deleted']):
            resp.headers['Content-Type'] = DELETE_MARKER_CONTENT_TYPE
        else:
            resp.headers['Content-Type'] = metadata.get(
                'mime_type', 'application/octet-stream')
        properties = metadata.get('properties')
        if properties:
            for k, v in properties.iteritems():
                if is_sys_or_user_meta('object', k) or \
                        is_object_transient_sysmeta(k) or \
                        k.lower() in self.allowed_headers:
                    resp.headers[str(k)] = v
        hash_ = metadata.get('hash')
        if hash_ is not None:
            hash_ = hash_.lower()
        resp.headers['etag'] = hash_
        resp.headers['x-object-sysmeta-version-id'] = metadata['version']
        ts = Timestamp(metadata['ctime'])
        resp.last_modified = math.ceil(float(ts))
        if stream:
            # Whether we are bothered with ranges or not, we wrap the
            # stream in order to handle exceptions.
            resp.app_iter = StreamRangeIterator(req, stream)

        length_ = metadata.get('length')
        if length_ is not None:
            length_ = int(length_)
        resp.content_length = length_
        resp.content_encoding = metadata.get('encoding')
        resp.accept_ranges = 'bytes'
        return resp
开发者ID:jfsmig,项目名称:oio-swift,代码行数:42,代码来源:obj.py

示例6: head_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(
                        self, lcontainer, listing, resp,
                        is_slo=(large_object == 'SLO'))

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    try:
                        content_length = sum(o['bytes'] for o in listing)
                        last_modified = \
                            max(o['last_modified'] for o in listing)
                        last_modified = datetime(*map(int, re.split('[^\d]',
                                                 last_modified)[:-1]))
                        etag = md5(
                            ''.join(o['hash'] for o in listing)).hexdigest()
开发者ID:saebyuk,项目名称:swift,代码行数:33,代码来源:obj.py

示例7: __call__

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(
                status='412 Precondition Failed')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok', body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                headers={'x-object-meta-test': 'value'},
                body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok', body='''
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            '''.strip())(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5':
            return self.listing(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/index.html':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c5/503error.html':
            return Response(status='404 Not Found')(env, start_response)
#.........这里部分代码省略.........
开发者ID:ChenZhengtongnju,项目名称:swift,代码行数:103,代码来源:test_staticweb.py

示例8: GETorHEAD_base

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def GETorHEAD_base(self, req, server_type, ring, partition, path):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param ring: the ring to obtain nodes from
        :param partition: partition
        :param path: path for the request
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        source_headers = []
        sources = []
        newest = config_true_value(req.headers.get('x-newest', 'f'))
        headers = self.generate_request_headers(req, additional=req.headers)
        for node in self.iter_nodes(ring, partition):
            start_node_timing = time.time()
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    conn = http_connect(
                        node['ip'], node['port'], node['device'], partition,
                        req.method, path, headers=headers,
                        query_string=req.query_string)
                self.app.set_node_timing(node, time.time() - start_node_timing)
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _('Trying to %(method)s %(path)s') %
                    {'method': req.method, 'path': req.path})
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader('X-PUT-Timestamp', 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append('')
                    bodies.append('')
                    source_headers.append('')
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append('')
                    source_headers.append('')
                    sources.append((possible_source, node))
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                source_headers.append(possible_source.getheaders())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node, _('ERROR Insufficient Storage'))
                elif is_server_error(possible_source.status):
                    self.error_occurred(node, _('ERROR %(status)d %(body)s '
                                                'From %(type)s Server') %
                                        {'status': possible_source.status,
                                         'body': bodies[-1][:1024],
                                         'type': server_type})
        res = None
        if sources:
            sources.sort(key=lambda s: source_key(s[0]))
            source, node = sources.pop()
            for src, _junk in sources:
                self.close_swift_conn(src)
            res = Response(request=req)
            if req.method == 'GET' and \
                    source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ['swift_x_timestamp'] = \
                source.getheader('x-timestamp')
            res.accept_ranges = 'bytes'
            res.content_length = source.getheader('Content-Length')
            if source.getheader('Content-Type'):
                res.charset = None
                res.content_type = source.getheader('Content-Type')
        if not res:
            res = self.best_response(req, statuses, reasons, bodies,
                                     '%s %s' % (server_type, req.method),
                                     headers=source_headers)
        try:
            (account, container) = split_path(req.path_info, 1, 2)
            _set_info_cache(self.app, req.environ, account, container, res)
        except ValueError:
            pass
        try:
            (account, container, obj) = split_path(req.path_info, 3, 3, True)
            _set_object_info_cache(self.app, req.environ, account,
#.........这里部分代码省略.........
开发者ID:sa4250mnpo70,项目名称:swift,代码行数:103,代码来源:base.py

示例9: __call__

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def __call__(self, env, start_response):
        self.calls += 1
        if env['PATH_INFO'] == '/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1':
            return Response(
                status='412 Precondition Failed')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c1':
            return Response(status='401 Unauthorized')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c2':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*'})
        elif env['PATH_INFO'] == '/v1/a/c2/one.txt':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-index': 'index.html',
                                 'x-container-meta-web-listings': 't'})
        elif env['PATH_INFO'] == '/v1/a/c3/index.html':
            return Response(status='200 Ok', body='''
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            ''')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3b':
            return self.listing(env, start_response,
                                {'x-container-read': '.r:*',
                                 'x-container-meta-web-index': 'index.html',
                                 'x-container-meta-web-listings': 't'})
        elif env['PATH_INFO'] == '/v1/a/c3b/index.html':
            resp = Response(status='204 No Content')
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdir3/subsubdir/index.html':
            return Response(status='200 Ok', body='index file')(env,
                                                                start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirx/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdiry/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/subdirz/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c3/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4':
            self.get_c4_called = True
            return self.listing(env, start_response,
                          {'x-container-read': '.r:*',
                           'x-container-meta-web-index': 'index.html',
                           'x-container-meta-web-error': 'error.html',
                           'x-container-meta-web-listings': 't',
                           'x-container-meta-web-listings-css': 'listing.css'})
        elif env['PATH_INFO'] == '/v1/a/c4/one.txt':
            return Response(status='200 Ok',
                headers={'x-object-meta-test': 'value'},
                body='1')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/two.txt':
            return Response(status='503 Service Unavailable')(env,
                                                              start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/subdir/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/unknown/index.html':
            return Response(status='404 Not Found')(env, start_response)
        elif env['PATH_INFO'] == '/v1/a/c4/404error.html':
            return Response(status='200 Ok', body='''
<html>
#.........这里部分代码省略.........
开发者ID:hanxinboy,项目名称:swift,代码行数:103,代码来源:test_staticweb.py

示例10: GETorHEAD_base

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def GETorHEAD_base(self, req, server_type, partition, nodes, path,
                       attempts):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param partition: partition
        :param nodes: nodes
        :param path: path for the request
        :param attempts: number of attempts to try
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        sources = []
        newest = config_true_value(req.headers.get('x-newest', 'f'))
        nodes = iter(nodes)
        while len(statuses) < attempts:
            try:
                node = nodes.next()
            except StopIteration:
                break
            if self.error_limited(node):
                continue
            start_node_timing = time.time()
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    headers = dict(req.headers)
                    headers['Connection'] = 'close'
                    conn = http_connect(
                        node['ip'], node['port'], node['device'], partition,
                        req.method, path, headers=headers,
                        query_string=req.query_string)
                self.app.set_node_timing(node, time.time() - start_node_timing)
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _('Trying to %(method)s %(path)s') %
                    {'method': req.method, 'path': req.path})
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader('X-PUT-Timestamp', 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append('')
                    bodies.append('')
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append('')
                    sources.append(possible_source)
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node)
                elif is_server_error(possible_source.status):
                    self.error_occurred(node, _('ERROR %(status)d %(body)s '
                                                'From %(type)s Server') %
                                        {'status': possible_source.status,
                                         'body': bodies[-1][:1024],
                                         'type': server_type})
        if sources:
            sources.sort(key=source_key)
            source = sources.pop()
            for src in sources:
                self.close_swift_conn(src)
            res = Response(request=req, conditional_response=True)
            if req.method == 'GET' and \
                    source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ['swift_x_timestamp'] = \
                source.getheader('x-timestamp')
            res.accept_ranges = 'bytes'
            res.content_length = source.getheader('Content-Length')
            if source.getheader('Content-Type'):
                res.charset = None
                res.content_type = source.getheader('Content-Type')
            return res
        return self.best_response(req, statuses, reasons, bodies,
                                  '%s %s' % (server_type, req.method))
开发者ID:GoodDingo,项目名称:openstack-swift,代码行数:98,代码来源:base.py

示例11: tmpl

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
                 max_age=self.cookie_max_age,
                 secure=self.secure)
 resp.app_iter = tmpl({'ptype': 'containers',
                       'title': self.title,
                       'lang': lang,
                       'top': self.page_path,
                       'account': acc,
                       'message': msg,
                       'base': base,
                       'whole_containers': whole_cont_list,
                       'containers': cont_list,
                       'container_meta': cont_meta,
                       'container_acl': cont_acl,
                       'containers_unquote': cont_unquote_name,
                       'delete_confirm': delete_confirm,
                       'acl_edit': acl_edit,
                       'meta_edit': meta_edit,
                       'enable_versions': self.enable_versions,
                       'containers_version': cont_version_cont,
                       'enable_container_sync': self.enable_container_sync,
                       'contsync_edit': contsync_edit,
                       'cont_sync_to': cont_sync_to,
                       'cont_sync_key': cont_sync_key,
                       'limit': limit,
                       'prev_p': prev_marker,
                       'next_p': next_marker,
                       'last_p': last_marker,
                       'delimiter': '',
                       'prefix': ''})
 self.token_bank[token].update({'msg': ''})
 self.memcache_update(token)
开发者ID:famao,项目名称:Taylor,代码行数:33,代码来源:taylor.py

示例12: head_response

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
                if req.method == 'HEAD':
                    # These shenanigans are because swob translates the HEAD
                    # request into a swob EmptyResponse for the body, which
                    # has a len, which eventlet translates as needing a
                    # content-length header added. So we call the original
                    # swob resp for the headers but return an empty iterator
                    # for the body.

                    def head_response(environ, start_response):
                        resp(environ, start_response)
                        return iter([])

                    head_response.status_int = resp.status_int
                    return head_response
                else:
                    resp.app_iter = SegmentedIterable(
                        self, lcontainer, listing, resp)

            else:
                # For objects with a reasonable number of segments, we'll serve
                # them with a set content-length and computed etag.
                if listing:
                    listing = list(listing)
                    content_length = sum(o['bytes'] for o in listing)
                    last_modified = max(o['last_modified'] for o in listing)
                    last_modified = datetime(*map(int, re.split('[^\d]',
                                             last_modified)[:-1]))
                    etag = md5(
                        ''.join(o['hash'] for o in listing)).hexdigest()
                else:
                    content_length = 0
                    last_modified = resp.last_modified
开发者ID:klrmn,项目名称:swift,代码行数:34,代码来源:obj.py

示例13: GETorHEAD_base

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def GETorHEAD_base(self, req, server_type, partition, nodes, path, attempts):
        """
        Base handler for HTTP GET or HEAD requests.

        :param req: swob.Request object
        :param server_type: server type
        :param partition: partition
        :param nodes: nodes
        :param path: path for the request
        :param attempts: number of attempts to try
        :returns: swob.Response object
        """
        statuses = []
        reasons = []
        bodies = []
        sources = []
        newest = config_true_value(req.headers.get("x-newest", "f"))
        nodes = iter(nodes)
        while len(statuses) < attempts:
            try:
                node = nodes.next()
            except StopIteration:
                break
            if self.error_limited(node):
                continue
            try:
                with ConnectionTimeout(self.app.conn_timeout):
                    headers = dict(req.headers)
                    headers["Connection"] = "close"
                    conn = http_connect(
                        node["ip"],
                        node["port"],
                        node["device"],
                        partition,
                        req.method,
                        path,
                        headers=headers,
                        query_string=req.query_string,
                    )
                with Timeout(self.app.node_timeout):
                    possible_source = conn.getresponse()
                    # See NOTE: swift_conn at top of file about this.
                    possible_source.swift_conn = conn
            except (Exception, Timeout):
                self.exception_occurred(
                    node, server_type, _("Trying to %(method)s %(path)s") % {"method": req.method, "path": req.path}
                )
                continue
            if self.is_good_source(possible_source):
                # 404 if we know we don't have a synced copy
                if not float(possible_source.getheader("X-PUT-Timestamp", 1)):
                    statuses.append(HTTP_NOT_FOUND)
                    reasons.append("")
                    bodies.append("")
                    self.close_swift_conn(possible_source)
                else:
                    statuses.append(possible_source.status)
                    reasons.append(possible_source.reason)
                    bodies.append("")
                    sources.append(possible_source)
                    if not newest:  # one good source is enough
                        break
            else:
                statuses.append(possible_source.status)
                reasons.append(possible_source.reason)
                bodies.append(possible_source.read())
                if possible_source.status == HTTP_INSUFFICIENT_STORAGE:
                    self.error_limit(node)
                elif is_server_error(possible_source.status):
                    self.error_occurred(
                        node,
                        _("ERROR %(status)d %(body)s " "From %(type)s Server")
                        % {"status": possible_source.status, "body": bodies[-1][:1024], "type": server_type},
                    )
        if sources:
            sources.sort(key=source_key)
            source = sources.pop()
            for src in sources:
                self.close_swift_conn(src)
            res = Response(request=req, conditional_response=True)
            if req.method == "GET" and source.status in (HTTP_OK, HTTP_PARTIAL_CONTENT):
                res.app_iter = self._make_app_iter(node, source)
                # See NOTE: swift_conn at top of file about this.
                res.swift_conn = source.swift_conn
            res.status = source.status
            update_headers(res, source.getheaders())
            if not res.environ:
                res.environ = {}
            res.environ["swift_x_timestamp"] = source.getheader("x-timestamp")
            res.accept_ranges = "bytes"
            res.content_length = source.getheader("Content-Length")
            if source.getheader("Content-Type"):
                res.charset = None
                res.content_type = source.getheader("Content-Type")
            return res
        return self.best_response(req, statuses, reasons, bodies, "%s %s" % (server_type, req.method))
开发者ID:WIZARD-CXY,项目名称:swift,代码行数:98,代码来源:base.py

示例14: __call__

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def __call__(self, env, start_response):
        self.calls += 1
        if env["PATH_INFO"] == "/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1":
            return Response(status="412 Precondition Failed")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c1":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2":
            return self.listing(env, start_response, {"x-container-read": ".r:*"})
        elif env["PATH_INFO"] == "/v1/a/c2/one.txt":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3":
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-listings": "t",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c3/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            """,
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b":
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-listings": "t",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c3b/index.html":
            resp = Response(status="204 No Content")
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/index.html":
            return Response(status="200 Ok", body="index file")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4":
            self.get_c4_called = True
            return self.listing(
                env,
                start_response,
                {
                    "x-container-read": ".r:*",
                    "x-container-meta-web-index": "index.html",
                    "x-container-meta-web-error": "error.html",
                    "x-container-meta-web-listings": "t",
                    "x-container-meta-web-listings-css": "listing.css",
                    "x-container-meta-web-directory-type": "text/dir",
                },
            )
        elif env["PATH_INFO"] == "/v1/a/c4/one.txt":
            return Response(status="200 Ok", headers={"x-object-meta-test": "value"}, body="1")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/two.txt":
            return Response(status="503 Service Unavailable")(env, start_response)
#.........这里部分代码省略.........
开发者ID:chmouel,项目名称:swift,代码行数:103,代码来源:test_staticweb.py

示例15: __call__

# 需要导入模块: from swift.common.swob import Response [as 别名]
# 或者: from swift.common.swob.Response import app_iter [as 别名]
    def __call__(self, env, start_response):
        self.calls += 1
        if "swift.authorize" in env:
            resp = env["swift.authorize"](Request(env))
            if resp:
                return resp(env, start_response)
        if env["PATH_INFO"] == "/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1":
            return Response(status="412 Precondition Failed")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c1":
            return Response(status="401 Unauthorized")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c2/one.txt":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/index.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body>
        <h1>Test main index.html file.</h1>
        <p>Visit <a href="subdir">subdir</a>.</p>
        <p>Don't visit <a href="subdir2/">subdir2</a> because it doesn't really
           exist.</p>
        <p>Visit <a href="subdir3">subdir3</a>.</p>
        <p>Visit <a href="subdir3/subsubdir">subdir3/subsubdir</a>.</p>
    </body>
</html>
            """,
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b":
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3b/index.html":
            resp = Response(status="204 No Content")
            resp.app_iter = iter([])
            return resp(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdir3/subsubdir/index.html":
            return Response(status="200 Ok", body="index file")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirx/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdiry/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/subdirz/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c3/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4":
            self.get_c4_called = True
            return self.listing(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/one.txt":
            return Response(status="200 Ok", headers={"x-object-meta-test": "value"}, body="1")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/two.txt":
            return Response(status="503 Service Unavailable")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/subdir/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/unknown/index.html":
            return Response(status="404 Not Found")(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c4/404error.html":
            return Response(
                status="200 Ok",
                body="""
<html>
    <body style="background: #000000; color: #ffaaaa">
        <p>Chrome's 404 fancy-page sucks.</p>
    </body>
</html>
            """.strip(),
            )(env, start_response)
        elif env["PATH_INFO"] == "/v1/a/c5":
            return self.listing(env, start_response)
#.........这里部分代码省略.........
开发者ID:harrisonfeng,项目名称:swift,代码行数:103,代码来源:test_staticweb.py


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