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


Python utils.split_path函数代码示例

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


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

示例1: _extract_path

    def _extract_path(self, path):
        account = self.account
        # Remove leading '/' to be consistent with split_path()
        obj = path[1:]
        container = None

        try:
            if self.strip_v1:
                version, tail = split_path('/' + obj, 1, 2, True)
                if version in ('v1', 'v1.0'):
                    obj = tail

            if obj is not None and self.account_first:
                account, tail = split_path('/' + obj, 1, 2, True)
                obj = tail

            if obj is not None and self.swift3_compat:
                container, tail = split_path('/' + obj, 1, 2, True)
                obj = tail

            # Do not yield an empty object name
            if not obj:
                obj = None
        except ValueError:
            raise HTTPBadRequest()

        return account, container, obj
开发者ID:jfsmig,项目名称:oio-swift,代码行数:27,代码来源:autocontainerbase.py

示例2: __call__

    def __call__(self, request):
       
        if request.method not in ("PUT","COPY"):
            return self.app

        try:
            split_path(request.path,2, 4, rest_with_last=True)
        except ValueError:
            return self.app

        new_quota = request.headers.get('X-Account-Meta-Quota-Bytes')
        if new_quota:
            if not new_quota.isdigit():
                return jresponse('-1', 'bad request', request, 400)
            return self.app

        account_info = get_account_info(request.environ, self.app)
        new_size = int(account_info['bytes']) + (request.content_length or 0)
        quota = int(account_info['meta'].get('quota-bytes', -1))

        if 0 <= quota < new_size:
            respbody='Your request is too large.'
            return jresponse('-1', respbody, request,413)

        return self.app
开发者ID:sun7shines,项目名称:Cloudfs,代码行数:25,代码来源:account_quotas.py

示例3: test_split_path

 def test_split_path(self):
     """ Test swift.common.utils.split_account_path """
     self.assertRaises(ValueError, utils.split_path, "")
     self.assertRaises(ValueError, utils.split_path, "/")
     self.assertRaises(ValueError, utils.split_path, "//")
     self.assertEquals(utils.split_path("/a"), ["a"])
     self.assertRaises(ValueError, utils.split_path, "//a")
     self.assertEquals(utils.split_path("/a/"), ["a"])
     self.assertRaises(ValueError, utils.split_path, "/a/c")
     self.assertRaises(ValueError, utils.split_path, "//c")
     self.assertRaises(ValueError, utils.split_path, "/a/c/")
     self.assertRaises(ValueError, utils.split_path, "/a//")
     self.assertRaises(ValueError, utils.split_path, "/a", 2)
     self.assertRaises(ValueError, utils.split_path, "/a", 2, 3)
     self.assertRaises(ValueError, utils.split_path, "/a", 2, 3, True)
     self.assertEquals(utils.split_path("/a/c", 2), ["a", "c"])
     self.assertEquals(utils.split_path("/a/c/o", 3), ["a", "c", "o"])
     self.assertRaises(ValueError, utils.split_path, "/a/c/o/r", 3, 3)
     self.assertEquals(utils.split_path("/a/c/o/r", 3, 3, True), ["a", "c", "o/r"])
     self.assertEquals(utils.split_path("/a/c", 2, 3, True), ["a", "c", None])
     self.assertRaises(ValueError, utils.split_path, "/a", 5, 4)
     self.assertEquals(utils.split_path("/a/c/", 2), ["a", "c"])
     self.assertEquals(utils.split_path("/a/c/", 2, 3), ["a", "c", ""])
     try:
         utils.split_path("o\nn e", 2)
     except ValueError, err:
         self.assertEquals(str(err), "Invalid path: o%0An%20e")
开发者ID:colecrawford,项目名称:swift,代码行数:27,代码来源:test_utils.py

示例4: __call__

    def __call__(self, env, start_response):
        """
        If called with header X-Pid-Create and Method PUT become active and
        create a PID and store it with the object
        :param env: request environment
        :param start_response: function that we call when creating response
        :return:
        """
        self.start_response = start_response
        request = Request(env)
        if request.method == 'PUT':
            if 'X-Pid-Create' in list(request.headers.keys()):
                url = '{}{}'.format(request.host_url, request.path_info)
                if 'X-Pid-Parent' in list(request.headers.keys()):
                    parent = request.headers['X-Pid-Parent']
                else:
                    parent = None
                success, pid = create_pid(object_url=url,
                                          api_url=self.conf.get('api_url'),
                                          username=self.conf.get('username'),
                                          password=self.conf.get('password'),
                                          parent=parent)
                if success:
                    self.logger.info('Created a PID for {}'.format(url))
                    request.headers['X-Object-Meta-PID'] = pid
                    response = PersistentIdentifierResponse(
                        pid=pid,
                        add_checksum=self.add_checksum,
                        username=self.conf.get('username'),
                        password=self.conf.get('password'),
                        start_response=start_response,
                        logger=self.logger)
                    return self.app(env, response.finish_response)
                else:
                    self.logger.error('Unable to create  a PID for {},'
                                      'because of {}'.format(url, pid))
                    return Response(
                        status=502,
                        body='Could not contact PID API')(env, start_response)
        elif request.method in ['GET', 'HEAD']:
            # only modify response if we have a request for a object
            try:
                split_path(request.path_info, 4, 4, True)
            except ValueError:
                return self.app(env, start_response)

            object_metadata = get_object_info(
                env=request.environ,
                app=self.app,
                swift_source='PersistentIdentifierMiddleware')['meta']
            if 'pid' in object_metadata.keys():
                response = PersistentIdentifierResponse(
                    pid='',
                    add_checksum='',
                    username='',
                    password='',
                    start_response=start_response,
                    logger=self.logger)
                return self.app(env, response.finish_response_pidurl)
        return self.app(env, start_response)
开发者ID:BeneDicere,项目名称:swift-persistent-identifier,代码行数:60,代码来源:persistent_identifier_middleware.py

示例5: GETorHEAD_base

    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
        """
        backend_headers = self.generate_request_headers(
            req, additional=req.headers)

        handler = GetOrHeadHandler(self.app, req, server_type, ring,
                                   partition, path, backend_headers)
        res = handler.get_working_response(req)

        if not res:
            res = self.best_response(
                req, handler.statuses, handler.reasons, handler.bodies,
                '%s %s' % (server_type, req.method),
                headers=handler.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,
                                   container, obj, res)
        except ValueError:
            pass
        return res
开发者ID:morucci,项目名称:swift,代码行数:35,代码来源:base.py

示例6: test_split_path

 def test_split_path(self):
     """ Test swift.common.utils.split_account_path """
     self.assertRaises(ValueError, utils.split_path, '')
     self.assertRaises(ValueError, utils.split_path, '/')
     self.assertRaises(ValueError, utils.split_path, '//')
     self.assertEquals(utils.split_path('/a'), ['a'])
     self.assertRaises(ValueError, utils.split_path, '//a')
     self.assertEquals(utils.split_path('/a/'), ['a'])
     self.assertRaises(ValueError, utils.split_path, '/a/c')
     self.assertRaises(ValueError, utils.split_path, '//c')
     self.assertRaises(ValueError, utils.split_path, '/a/c/')
     self.assertRaises(ValueError, utils.split_path, '/a//')
     self.assertRaises(ValueError, utils.split_path, '/a', 2)
     self.assertRaises(ValueError, utils.split_path, '/a', 2, 3)
     self.assertRaises(ValueError, utils.split_path, '/a', 2, 3, True)
     self.assertEquals(utils.split_path('/a/c', 2), ['a', 'c'])
     self.assertEquals(utils.split_path('/a/c/o', 3), ['a', 'c', 'o'])
     self.assertRaises(ValueError, utils.split_path, '/a/c/o/r', 3, 3)
     self.assertEquals(utils.split_path('/a/c/o/r', 3, 3, True),
                       ['a', 'c', 'o/r'])
     self.assertEquals(utils.split_path('/a/c', 2, 3, True),
                       ['a', 'c', None])
     self.assertRaises(ValueError, utils.split_path, '/a', 5, 4)
     self.assertEquals(utils.split_path('/a/c/', 2), ['a', 'c'])
     self.assertEquals(utils.split_path('/a/c/', 2, 3), ['a', 'c', ''])
     try:
         utils.split_path('o\nn e', 2)
     except ValueError, err:
         self.assertEquals(str(err), 'Invalid path: o%0An%20e')
开发者ID:AsylumCorp,项目名称:swift,代码行数:29,代码来源:test_utils.py

示例7: check_copy_source

    def check_copy_source(self, app):
        """
        check_copy_source checks the copy source existence and if copying an
        object to itself, for illegal request parameters
        """
        if 'X-Amz-Copy-Source' in self.headers:
            src_path = unquote(self.headers['X-Amz-Copy-Source'])
            src_path = src_path if src_path.startswith('/') else \
                ('/' + src_path)
            src_bucket, src_obj = split_path(src_path, 0, 2, True)
            headers = swob.HeaderKeyDict()
            headers.update(self._copy_source_headers())

            src_resp = self.get_response(app, 'HEAD', src_bucket, src_obj,
                                         headers=headers)
            if src_resp.status_int == 304:  # pylint: disable-msg=E1101
                raise PreconditionFailed()

            self.headers['X-Amz-Copy-Source'] = \
                '/' + self.headers['X-Amz-Copy-Source'].lstrip('/')
            source_container, source_obj = \
                split_path(self.headers['X-Amz-Copy-Source'], 1, 2, True)

            if (self.container_name == source_container and
                    self.object_name == source_obj):
                if self.headers.get('x-amz-metadata-directive',
                                    'COPY') == 'COPY':
                    raise InvalidRequest("This copy request is illegal "
                                         "because it is trying to copy an "
                                         "object to itself without "
                                         "changing the object's metadata, "
                                         "storage class, website redirect "
                                         "location or encryption "
                                         "attributes.")
开发者ID:tipabu,项目名称:swift3,代码行数:34,代码来源:request.py

示例8: handle_get_token

    def handle_get_token(self, req):
        """
        Handles the various `request for token and service end point(s)` calls.
        There are various formats to support the various auth servers in the
        past. Examples::

            GET <auth-prefix>/v1/<act>/auth
            GET <auth-prefix>/auth
            GET <auth-prefix>/v1.0

        All formats require GSS (Kerberos) authentication.

        On successful authentication, the response will have X-Auth-Token
        set to the token to use with Swift.

        :param req: The swob.Request to process.
        :returns: swob.Response, 2xx on success with data set as explained
                  above.
        """
        # Validate the request info
        try:
            pathsegs = split_path(req.path_info, 1, 3, True)
        except ValueError:
            self.logger.increment('errors')
            return HTTPNotFound(request=req)
        if not ((pathsegs[0] == 'v1' and pathsegs[2] == 'auth')
                or pathsegs[0] in ('auth', 'v1.0')):
                    return HTTPBadRequest(request=req)

        return HTTPSeeOther(location=self.ext_authentication_url)
开发者ID:prashanthpai,项目名称:swiftkrbauth,代码行数:30,代码来源:kerbauth.py

示例9: handle_ring

 def handle_ring(self, env, start_response):
     """handle requests to /ring"""
     base, ringfile = split_path(env["PATH_INFO"], minsegs=1, maxsegs=2, rest_with_last=True)
     if ringfile not in self.ring_files:
         start_response("404 Not Found", [("Content-Type", "text/plain")])
         return ["Not Found\r\n"]
     target = pathjoin(self.swiftdir, ringfile)
     try:
         self._validate_file(target)
     except LockTimeout:
         self.logger.exception("swiftdir locked for update")
         start_response("503 Service Unavailable", [("Content-Type", "application/octet-stream")])
         return ["Service Unavailable\r\n"]
     except (OSError, IOError):
         self.logger.exception("Oops")
         start_response("503 Service Unavailable", [("Content-Type", "text/plain")])
         return ["Service Unavailable\r\n"]
     if "HTTP_IF_NONE_MATCH" in env:
         if env["HTTP_IF_NONE_MATCH"] == self.current_md5[target]:
             headers = [("Content-Type", "application/octet-stream")]
             start_response("304 Not Modified", headers)
             return ["Not Modified\r\n"]
     if env["REQUEST_METHOD"] == "GET":
         headers = [("Content-Type", "application/octet-stream")]
         headers.append(("Etag", self.current_md5[target]))
         start_response("200 OK", headers)
         return FileIterable(target)
     elif env["REQUEST_METHOD"] == "HEAD":
         headers = [("Content-Type", "application/octet-stream")]
         headers.append(("Etag", self.current_md5[target]))
         start_response("200 OK", headers)
         return []
     else:
         start_response("501 Not Implemented", [("Content-Type", "text/plain")])
         return ["Not Implemented\r\n"]
开发者ID:pandemicsyn,项目名称:swift-ring-master,代码行数:35,代码来源:ringmasterwsgi.py

示例10: authenticate

    def authenticate(self, app):
        """
        authenticate method will run pre-authenticate request and retrieve
        account information.
        Note that it currently supports only keystone and tempauth.
        (no support for the third party authentication middleware)
        """
        sw_req = self.to_swift_req('TEST', None, None, body='')
        # don't show log message of this request
        sw_req.environ['swift.proxy_access_log_made'] = True

        sw_resp = sw_req.get_response(app)

        if not sw_req.remote_user:
            raise SignatureDoesNotMatch()

        _, self.account, _ = split_path(sw_resp.environ['PATH_INFO'],
                                        2, 3, True)
        self.account = utf8encode(self.account)

        if 'HTTP_X_USER_NAME' in sw_resp.environ:
            # keystone
            self.user_id = "%s:%s" % (sw_resp.environ['HTTP_X_TENANT_NAME'],
                                      sw_resp.environ['HTTP_X_USER_NAME'])
            self.user_id = utf8encode(self.user_id)
            self.keystone_token = sw_req.environ['HTTP_X_AUTH_TOKEN']
        else:
            # tempauth
            self.user_id = self.access_key
开发者ID:yinyinbigdata,项目名称:swift3-stackforge,代码行数:29,代码来源:request.py

示例11: DELETE

 def DELETE(self, req):
     """Handle HTTP DELETE request."""
     try:
         drive, part, account = split_path(unquote(req.path), 3)
     except ValueError, err:
         return HTTPBadRequest(body=str(err), content_type='text/plain',
                                                 request=req)
开发者ID:mja054,项目名称:swift_plugin,代码行数:7,代码来源:server.py

示例12: get_account_info

def get_account_info(env, app, swift_source=None):
    """
    Get the info structure for an account, based on env and app.
    This is useful to middlewares.
    Note: This call bypasses auth. Success does not imply that the
          request has authorization to the account_info.
    """
    cache = cache_from_env(env)
    if not cache:
        return None
    (version, account, _junk, _junk) = \
        split_path(env['PATH_INFO'], 2, 4, True)
    cache_key = get_account_memcache_key(account)
    # Use a unique environment cache key per account.  If you copy this env
    # to make a new request, it won't accidentally reuse the old account info
    env_key = 'swift.%s' % cache_key
    if env_key not in env:
        account_info = cache.get(cache_key)
        if not account_info:
            resp = make_pre_authed_request(
                env, 'HEAD', '/%s/%s' % (version, account),
                swift_source=swift_source,
            ).get_response(app)
            account_info = headers_to_account_info(
                resp.headers, resp.status_int)
        env[env_key] = account_info
    return env[env_key]
开发者ID:CiscoAS,项目名称:swift,代码行数:27,代码来源:base.py

示例13: __call__

    def __call__(self, req):
         
        container = split_path(req.path, 1, 4, True)[2]
        if 'batch' == container:
            return self.handle_batch(req)

        return self.app
开发者ID:sun3shines,项目名称:swift-1.7.4,代码行数:7,代码来源:batch.py

示例14: parse_raw_obj

def parse_raw_obj(obj_info):
    """
    Translate a reconciler container listing entry to a dictionary
    containing the parts of the misplaced object queue entry.

    :param obj_info: an entry in an a container listing with the
                     required keys: name, content_type, and hash

    :returns: a queue entry dict with the keys: q_policy_index, account,
              container, obj, q_op, q_ts, q_record, and path
    """
    raw_obj_name = obj_info['name'].encode('utf-8')

    policy_index, obj_name = raw_obj_name.split(':', 1)
    q_policy_index = int(policy_index)
    account, container, obj = split_path(obj_name, 3, 3, rest_with_last=True)
    try:
        q_op = {
            'application/x-put': 'PUT',
            'application/x-delete': 'DELETE',
        }[obj_info['content_type']]
    except KeyError:
        raise ValueError('invalid operation type %r' %
                         obj_info.get('content_type', None))
    return {
        'q_policy_index': q_policy_index,
        'account': account,
        'container': container,
        'obj': obj,
        'q_op': q_op,
        'q_ts': Timestamp(obj_info['hash']),
        'q_record': last_modified_date_to_timestamp(
            obj_info['last_modified']),
        'path': '/%s/%s/%s' % (account, container, obj)
    }
开发者ID:701,项目名称:swift,代码行数:35,代码来源:reconciler.py

示例15: __init__

    def __init__(self, app, req, logger):
        """
        Constructor
        :param app:
        :param req:
        :raise: ValueError, HTTPNotFound, KeyAttribute, ImageInvalid
        """
        self.app = app
        self.req = req
        self.logger = logger
        self.resp_dict = {'Response Status': HTTPCreated().status,
                          'Response Body': '',
                          'Number Files Created': 0}
        self.env = req.environ
        self.resize_dimensions = [TYPE_IMAGE_LARGE, TYPE_IMAGE_MEDIUM]

        try:
            self.version, self.account, self.container, self.obj = split_path(self.req.path, 1, 4, True)
        except ValueError:
            raise HTTPNotFound(request=self.req)

        if not self.obj:
            raise ImageInvalid("Not an Image")

        if not str.lower(self.obj.split(".")[-1]) in IMAGE_TYPE:
            raise ImageInvalid("Not an Image")

        self.request_body = self.env['wsgi.input'].read(int(self.env['CONTENT_LENGTH']))
        flo = cStringIO.StringIO(self.request_body)
        try:
            self.orig_image = Image.open(flo)
        except IOError:
            raise ImageInvalid("Not an Image")
开发者ID:jannatunnoor,项目名称:test_swift,代码行数:33,代码来源:ibuck.py


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