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


Python wsgi.make_subrequest函数代码示例

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


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

示例1: create_container

 def create_container(self, req, container_path):
     """
     Checks if the container exists and if not try to create it.
     :params container_path: an unquoted path to a container to be created
     :returns: True if created container, False if container exists
     :raises CreateContainerError: when unable to create container
     """
     head_cont_req = make_subrequest(
         req.environ, method='HEAD', path=wsgi_quote(container_path),
         headers={'X-Auth-Token': req.headers.get('X-Auth-Token')},
         swift_source='EA')
     resp = head_cont_req.get_response(self.app)
     if resp.is_success:
         return False
     if resp.status_int == HTTP_NOT_FOUND:
         create_cont_req = make_subrequest(
             req.environ, method='PUT', path=wsgi_quote(container_path),
             headers={'X-Auth-Token': req.headers.get('X-Auth-Token')},
             swift_source='EA')
         resp = create_cont_req.get_response(self.app)
         if resp.is_success:
             return True
     raise CreateContainerError(
         "Create Container Failed: " + container_path,
         resp.status_int, resp.status)
开发者ID:mahak,项目名称:swift,代码行数:25,代码来源:bulk.py

示例2: __call__

    def __call__(self, request):
        try:
            (version, account, container, objname) = split_path(request.path_info, 4, 4, True)
        except ValueError:
            return self.app

        preview_path = '/%s/%s/%s_%s/%s' % (version, account, container, self.suffix, objname)

        if request.method == 'GET' and request.params.has_key('preview'):
            request.path_info = preview_path
       
        if request.method == 'PUT':
            if hasattr(request, 'body_file'):
                data = ""
                while True:
                    chunk = request.body_file.read()
                    if not chunk:
                        break
                    data += chunk
                request.body = data
                preview = create_preview(data)
            else:
                preview = create_preview(request.body)
            if preview:
                sub = wsgi.make_subrequest(request.environ, path=preview_path, body=preview)
                sub.get_response(self.app)

        if request.method == 'DELETE':
            sub = wsgi.make_subrequest(request.environ, path=preview_path)
            sub.get_response(self.app)

        return self.app
开发者ID:greenx,项目名称:swift-middleware-sample,代码行数:32,代码来源:middleware.py

示例3: do_delete

 def do_delete(obj_name, delete_path):
     delete_obj_req = make_subrequest(
         req.environ, method='DELETE', path=quote(delete_path),
         headers={'X-Auth-Token': req.headers.get('X-Auth-Token')},
         body='', agent='%(orig)s ' + user_agent,
         swift_source=swift_source)
     return (delete_obj_req.get_response(self.app), obj_name, 0)
开发者ID:jgmerritt,项目名称:swift,代码行数:7,代码来源:bulk.py

示例4: PUT

    def PUT(self, req):
        """HTTP PUT request handler."""
        container_info = self.container_info(
            self.account_name, self.container_name, req)

        req.acl = container_info['write_acl']
        req.environ['swift_sync_key'] = container_info['sync_key']

        # is request authorized
        if 'swift.authorize' in req.environ:
            aresp = req.environ['swift.authorize'](req)
            if aresp:
                return aresp

        old_slo_manifest = None
        # If versioning is disabled, we must check if the object exists.
        # If it's a SLO, we will have to delete the parts if the current
        # operation is a success.
        if (self.app.delete_slo_parts and
                not container_info['sysmeta'].get('versions-location', None)):
            try:
                dest_info = get_object_info(req.environ, self.app)
                if 'slo-size' in dest_info['sysmeta']:
                    manifest_env = req.environ.copy()
                    manifest_env['QUERY_STRING'] = 'multipart-manifest=get'
                    manifest_req = make_subrequest(manifest_env, 'GET')
                    manifest_resp = manifest_req.get_response(self.app)
                    old_slo_manifest = json.loads(manifest_resp.body)
            except Exception as exc:
                self.app.logger.warn(('Failed to check existence of %s. If '
                                      'overwriting a SLO, old parts may '
                                      'remain. Error was: %s') %
                                     (req.path, exc))

        self._update_content_type(req)

        self._update_x_timestamp(req)

        # check constraints on object name and request headers
        error_response = check_object_creation(req, self.object_name) or \
            check_content_type(req)
        if error_response:
            return error_response

        if req.headers.get('Oio-Copy-From'):
            return self._link_object(req)

        data_source = req.environ['wsgi.input']
        if req.content_length:
            data_source = ExpectedSizeReader(data_source, req.content_length)

        headers = self._prepare_headers(req)
        with closing_if_possible(data_source):
            resp = self._store_object(req, data_source, headers)
        if old_slo_manifest and resp.is_success:
            self.app.logger.debug(
                'Previous object %s was a SLO, deleting parts',
                req.path)
            self._delete_slo_parts(req, old_slo_manifest)
        return resp
开发者ID:fvennetier,项目名称:oio-swift,代码行数:60,代码来源:obj.py

示例5: _fetch_sub_slo_segments

    def _fetch_sub_slo_segments(self, req, version, acc, con, obj):
        """
        Fetch the submanifest, parse it, and return it.
        Raise exception on failures.
        """
        sub_req = make_subrequest(
            req.environ,
            path="/".join(["", version, acc, con, obj]),
            method="GET",
            headers={"x-auth-token": req.headers.get("x-auth-token")},
            agent=("%(orig)s " + "SLO MultipartGET"),
            swift_source="SLO",
        )
        sub_resp = sub_req.get_response(self.slo.app)

        if not is_success(sub_resp.status_int):
            close_if_possible(sub_resp.app_iter)
            raise ListingIterError(
                "ERROR: while fetching %s, GET of submanifest %s "
                "failed with status %d" % (req.path, sub_req.path, sub_resp.status_int)
            )

        try:
            with closing_if_possible(sub_resp.app_iter):
                return json.loads("".join(sub_resp.app_iter))
        except ValueError as err:
            raise ListingIterError(
                "ERROR: while fetching %s, JSON-decoding of submanifest %s "
                "failed with %s" % (req.path, sub_req.path, err)
            )
开发者ID:pchng,项目名称:swift,代码行数:30,代码来源:slo.py

示例6: create_link

def create_link(vertigo, link_path, dest_path, heads):
    """
    Creates a link to a real object

    :param vertigo: swift_vertigo.vertigo_handler.VertigoProxyHandler instance
    :param link_path: swift path of the link
    :param dest_path: swift path of the object to link
    :param headers: original object headers
    """
    vertigo.logger.debug('Vertigo - Creating link from %s to %s' % (link_path,
                                                                    dest_path))

    new_env = dict(vertigo.request.environ)
    if 'HTTP_TRANSFER_ENCODING' in new_env.keys():
        del new_env['HTTP_TRANSFER_ENCODING']

    if 'HTTP_X_COPY_FROM' in new_env.keys():
        del new_env['HTTP_X_COPY_FROM']

    auth_token = vertigo.request.headers.get('X-Auth-Token')

    link_path = os.path.join('/', vertigo.api_version,
                             vertigo.account, link_path)

    sub_req = make_subrequest(
        new_env, 'PUT', link_path,
        headers={'X-Auth-Token': auth_token,
                 'Content-Length': 0,
                 'Content-Type': 'vertigo/link',
                 'Original-Content-Length': heads["Content-Length"],
                 'X-Object-Sysmeta-Vertigo-Link-to': dest_path},
        swift_source='Vertigo')
    resp = sub_req.get_response(vertigo.app)

    return resp
开发者ID:iostackproject,项目名称:vertigo,代码行数:35,代码来源:utils.py

示例7: verify_access

def verify_access(vertigo, path):
    """
    Verifies access to the specified object in swift

    :param vertigo: swift_vertigo.vertigo_handler.VertigoProxyHandler instance
    :param path: swift path of the object to check
    :returns: headers of the object whether exists
    """
    vertigo.logger.debug('Vertigo - Verify access to %s' % path)

    new_env = dict(vertigo.request.environ)
    if 'HTTP_TRANSFER_ENCODING' in new_env.keys():
        del new_env['HTTP_TRANSFER_ENCODING']

    for key in DEFAULT_MD_STRING.keys():
        env_key = 'HTTP_X_VERTIGO_' + key.upper()
        if env_key in new_env.keys():
            del new_env[env_key]

    auth_token = vertigo.request.headers.get('X-Auth-Token')
    sub_req = make_subrequest(
        new_env, 'HEAD', path,
        headers={'X-Auth-Token': auth_token},
        swift_source='Vertigo')

    return sub_req.get_response(vertigo.app)
开发者ID:iostackproject,项目名称:vertigo,代码行数:26,代码来源:utils.py

示例8: _fetch_sub_slo_segments

    def _fetch_sub_slo_segments(self, req, version, acc, con, obj):
        """
        Fetch the submanifest, parse it, and return it.
        Raise exception on failures.
        """
        sub_req = make_subrequest(
            req.environ, path='/'.join(['', version, acc, con, obj]),
            method='GET',
            headers={'x-auth-token': req.headers.get('x-auth-token')},
            agent=('%(orig)s ' + 'SLO MultipartGET'), swift_source='SLO')
        sub_resp = sub_req.get_response(self.slo.app)

        if not is_success(sub_resp.status_int):
            close_if_possible(sub_resp.app_iter)
            raise ListingIterError(
                'ERROR: while fetching %s, GET of submanifest %s '
                'failed with status %d' % (req.path, sub_req.path,
                                           sub_resp.status_int))

        try:
            with closing_if_possible(sub_resp.app_iter):
                return json.loads(''.join(sub_resp.app_iter))
        except ValueError as err:
            raise ListingIterError(
                'ERROR: while fetching %s, JSON-decoding of submanifest %s '
                'failed with %s' % (req.path, sub_req.path, err))
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:26,代码来源:slo.py

示例9: POST

    def POST(self):
        """
        POST handler on Proxy
        Deals with storlet ACL updates
        """

        # Get the current container's ACL
        # We perform a sub request rather than get_container_info
        # since get_container_info bypasses authorization, and we
        # prefer to be on the safe side.
        target = ["", self.api_version, self.account, self.container]
        sub_req = make_subrequest(self.request.environ, "HEAD", "/".join(target), agent=self.agent)
        sub_resp = sub_req.get_response(self.app)
        if sub_resp.status_int != 204:
            self.logger.info("Failed to retreive container metadata")
            return HTTPUnauthorized(("Unauthorized to get or modify " "the container ACL"))

        # Add the requested ACL
        read_acl = sub_resp.headers.get("X-Container-Read", None)
        if read_acl:
            new_read_acl = ",".join([read_acl, self.acl_string])
        else:
            new_read_acl = self.acl_string

        self.request.headers["X-Container-Read"] = new_read_acl
        resp = self.request.get_response(self.app)
        self.logger.info("Got post response, %s" % resp.status)
        return resp
开发者ID:openstack,项目名称:storlets,代码行数:28,代码来源:proxy.py

示例10: verify_access_to_storlet

    def verify_access_to_storlet(self):
        """
        Verify access to the storlet object

        :return: storlet parameters
        :raises HTTPUnauthorized: If it fails to verify access
        """
        sobj = self.request.headers.get("X-Run-Storlet")
        spath = "/".join(["", self.api_version, self.account, self.storlet_container, sobj])
        self.logger.debug("Verify access to %s" % spath)

        new_env = dict(self.request.environ)
        if "HTTP_TRANSFER_ENCODING" in new_env.keys():
            del new_env["HTTP_TRANSFER_ENCODING"]

        for key in CONDITIONAL_KEYS:
            env_key = "HTTP_" + key
            if env_key in new_env.keys():
                del new_env[env_key]

        auth_token = self.request.headers.get("X-Auth-Token")
        storlet_req = make_subrequest(
            new_env, "HEAD", spath, headers={"X-Auth-Token": auth_token}, swift_source=self.agent
        )

        resp = storlet_req.get_response(self.app)
        if not resp.is_success:
            raise HTTPUnauthorized("Failed to verify access to the storlet", request=self.request)

        params = self._parse_storlet_params(resp.headers)
        for key in ["Content-Length", "X-Timestamp"]:
            params[key] = resp.headers[key]
        return params
开发者ID:openstack,项目名称:storlets,代码行数:33,代码来源:proxy.py

示例11: _get_object_list

    def _get_object_list(self, path):
        """
        Gets an object list of a specified path. The path may be '*', that means
        it returns all objects inside the container or a pseudo-folder, that means
        it only returns the objects inside the pseudo-folder.
        :param path: pseudo-folder path (ended with *), or '*'
        :return: list of objects
        """
        obj_list = list()

        dest_path = os.path.join('/', self.api_version, self.account, self.container)
        new_env = dict(self.request.environ)
        auth_token = self.request.headers.get('X-Auth-Token')

        if path == '*':
            # All objects inside a container hierarchy
            obj_list.append('')
        else:
            # All objects inside a pseudo-folder hierarchy
            obj_split = self.obj.rsplit('/', 1)
            pseudo_folder = obj_split[0] + '/'
            new_env['QUERY_STRING'] = 'prefix='+pseudo_folder

        sub_req = make_subrequest(new_env, 'GET', dest_path,
                                  headers={'X-Auth-Token': auth_token},
                                  swift_source='Vertigo')
        response = sub_req.get_response(self.app)
        for obj in response.body.split('\n'):
            if obj != '':
                obj_list.append(obj)

        self._augment_object_list(obj_list)

        return obj_list
开发者ID:iostackproject,项目名称:vertigo,代码行数:34,代码来源:proxy.py

示例12: _get_container_listing

    def _get_container_listing(self, req, version, account, container,
                               prefix, marker=''):
        '''
        :param version: whatever
        :param account: native
        :param container: native
        :param prefix: native
        :param marker: native
        '''
        con_req = make_subrequest(
            req.environ,
            path=wsgi_quote('/'.join([
                '', str_to_wsgi(version),
                str_to_wsgi(account), str_to_wsgi(container)])),
            method='GET',
            headers={'x-auth-token': req.headers.get('x-auth-token')},
            agent=('%(orig)s ' + 'DLO MultipartGET'), swift_source='DLO')
        con_req.query_string = 'prefix=%s' % quote(prefix)
        if marker:
            con_req.query_string += '&marker=%s' % quote(marker)

        con_resp = con_req.get_response(self.dlo.app)
        if not is_success(con_resp.status_int):
            if req.method == 'HEAD':
                con_resp.body = b''
            return con_resp, None
        with closing_if_possible(con_resp.app_iter):
            return None, json.loads(b''.join(con_resp.app_iter))
开发者ID:mahak,项目名称:swift,代码行数:28,代码来源:dlo.py

示例13: _check_conditions

    def _check_conditions(self, filter_metadata):
        """
        This method ckecks the object_tag, object_type and object_size parameters
        introduced by the dashborad to run the filter.
        """
        if not filter_metadata['object_type'] and \
           not filter_metadata['object_tag'] and \
           not filter_metadata['object_size']:
            return True

        metadata = {}
        if self.method == 'put':
            for key in self.request.headers.keys():
                metadata[key.lower()] = self.request.headers.get(key)
        else:
            sub_req = make_subrequest(self.request.environ, method='HEAD',
                                      path=self.request.path_info,
                                      headers=self.request.headers,
                                      swift_source='Crystal Filter Middleware')
            resp = sub_req.get_response(self.app)
            metadata = resp.headers

        correct_type = True
        correct_size = True
        correct_tags = True

        try:
            if filter_metadata['object_type']:
                object_name = filter_metadata['object_name']
                filename = self.request.environ['PATH_INFO']
                pattern = re.compile(object_name)
                if not pattern.search(filename):
                    correct_type = False

            if filter_metadata['object_tag']:
                tags = filter_metadata['object_tag'].split(',')
                tag_checking = list()
                for tag in tags:
                    key, value = tag.split(':')
                    meta_key = ('X-Object-Meta-'+key).lower()
                    sysmeta_key = ('X-Object-Sysmeta-Meta-'+key).lower()
                    correct_tag = (meta_key in metadata and
                                   metadata[meta_key] == value) or \
                                  (sysmeta_key in metadata and
                                   metadata[sysmeta_key] == value)
                    tag_checking.append(correct_tag)
                correct_tags = all(tag_checking)

            if filter_metadata['object_size']:
                object_size = filter_metadata['object_size']
                op = mappings[object_size[0]]
                obj_lenght = int(object_size[1])
                correct_size = op(int(metadata['Content-Length']),
                                  obj_lenght)
        except Exception as e:
            self.logger.error(str(e))
            return False

        return correct_type and correct_size and correct_tags
开发者ID:Crystal-SDS,项目名称:Crystal-Filter-Middleware,代码行数:59,代码来源:proxy.py

示例14: get_container_metadata

def get_container_metadata(vertigo, container):
    new_env = dict(vertigo.request.environ)
    auth_token = vertigo.request.headers.get('X-Auth-Token')
    sub_req = make_subrequest(new_env, 'HEAD', container,
                              headers={'X-Auth-Token': auth_token},
                              swift_source='Vertigo')
    response = sub_req.get_response(vertigo.app)
    return response.headers
开发者ID:iostackproject,项目名称:vertigo,代码行数:8,代码来源:utils.py

示例15: handle_slo_get_or_head

    def handle_slo_get_or_head(self, req, start_response):
        """
        Takes a request and a start_response callable and does the normal WSGI
        thing with them. Returns an iterator suitable for sending up the WSGI
        chain.

        :param req: swob.Request object; is a GET or HEAD request aimed at
                    what may be a static large object manifest (or may not).
        :param start_response: WSGI start_response callable
        """
        resp_iter = self._app_call(req.environ)

        # make sure this response is for a static large object manifest
        for header, value in self._response_headers:
            if (header.lower() == 'x-static-large-object' and
                    config_true_value(value)):
                break
        else:
            # Not a static large object manifest. Just pass it through.
            start_response(self._response_status,
                           self._response_headers,
                           self._response_exc_info)
            return resp_iter

        # Handle pass-through request for the manifest itself
        if req.params.get('multipart-manifest') == 'get':
            new_headers = []
            for header, value in self._response_headers:
                if header.lower() == 'content-type':
                    new_headers.append(('Content-Type',
                                        'application/json; charset=utf-8'))
                else:
                    new_headers.append((header, value))
            self._response_headers = new_headers
            start_response(self._response_status,
                           self._response_headers,
                           self._response_exc_info)
            return resp_iter

        if self._need_to_refetch_manifest(req):
            req.environ['swift.non_client_disconnect'] = True
            close_if_possible(resp_iter)
            del req.environ['swift.non_client_disconnect']

            get_req = make_subrequest(
                req.environ, method='GET',
                headers={'x-auth-token': req.headers.get('x-auth-token')},
                agent=('%(orig)s ' + 'SLO MultipartGET'), swift_source='SLO')
            resp_iter = self._app_call(get_req.environ)

        # Any Content-Range from a manifest is almost certainly wrong for the
        # full large object.
        resp_headers = [(h, v) for h, v in self._response_headers
                        if not h.lower() == 'content-range']

        response = self.get_or_head_response(
            req, resp_headers, resp_iter)
        return response(req.environ, start_response)
开发者ID:iloveyou416068,项目名称:swift-1,代码行数:58,代码来源:slo.py


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