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


Python cbException.cbException函数代码示例

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


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

示例1: work

    def work(self):
        request = self.request
        exists = self.user.exists(self.bucketName)

        if self.acl:
            if not exists:
                raise cbException('NoSuchBucket')
            (perms, data_key) = self.user.get_perms(self.bucketName)
            ndx = perms.find("W")
            if ndx < 0:
                raise cbException('AccessDenied')

            rc = self.grant_public_permissions(self.bucketName, self.objectName)
            if not rc:
                xml = self.request.content.read()
                pycb.log(logging.INFO, "xml %s" % (xml))
                grants = parse_acl_request(xml)
                for g in grants:
                    pycb.log(logging.INFO, "granting %s to %s" % (g[2], g[0]))
                    self.user.grant(g[0], self.bucketName, perms=g[2])
        else:
            if exists:
                raise cbException('BucketAlreadyExists')
            self.user.put_bucket(self.bucketName)
            self.grant_public_permissions(self.bucketName, self.objectName)

        self.set_common_headers()
        self.setHeader(request, 'Content-Length', 0)
        self.setHeader(request, 'Connection', 'close')
        self.setHeader(request, 'Location', "/" + self.bucketName)
        self.setResponseCode(request, 200, 'OK')

        self.finish(request)
开发者ID:Annatara,项目名称:nimbus,代码行数:33,代码来源:cbRequest.py

示例2: work

 def work(self):
     pycb.log(logging.INFO, "===== def work of cbRequest.py")
     exists = self.user.exists(self.bucketName)
     if not exists:
         raise cbException('NoSuchBucket')
     (perms, data_key) = self.user.get_perms(self.bucketName)
     ndx = perms.find("w")
     if ndx < 0:
         raise cbException('AccessDenied')
     self.deleteIt(data_key)
开发者ID:xxy-php,项目名称:code,代码行数:10,代码来源:cbRequest.py

示例3: parse_acl_request

def parse_acl_request(xml):
    dom = parseString(xml)
    grant_a = dom.getElementsByTagName("Grant")
    grants = []
    users = {}

    for g in grant_a:
        email = getText(g.getElementsByTagName("DisplayName")[0].childNodes)
        id = getText(g.getElementsByTagName("ID")[0].childNodes)
        perm_set = g.getElementsByTagName("Permission")

        perms = ""
        for p in perm_set:
            requested_perm = getText(p.childNodes)

            if requested_perm not in perms_strings:
                raise cbException('InvalidArgument')

            pv = perms_strings[requested_perm]
            ndx = perms.find(pv)
            if ndx < 0:
                perms = perms + pv

        if id in users.keys():
            (i, e, p) = users[id]
            perms = perms + p
        users[id] = (id, email, perms)

    return users.values()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:29,代码来源:cbRequest.py

示例4: __init__

    def __init__(self, data_key, access="r", openIt=True):
        self.fname = data_key
        self.metafname = data_key + ".meta"
        self.data_key = data_key
        self.blockSize = pycb.config.block_size
        self.hashValue = None
        self.delete_on_close = False
        self.md5er = hashlib.md5()
        self.access = access

        self.seek_count = 0

        if not openIt:
            return

        try:
            # this allows head to be very fast
            if access == "r":
                mFile = open(self.metafname, 'r')
                self.hashValue = mFile.readline()
                mFile.close()
        except:
            pass

        try:
            self.file = open(self.fname, access)
        except OSError, (OsEx):
            if OsEx.errno == errno.ENOENT:
               raise cbException('NoSuchKey')
开发者ID:Annatara,项目名称:nimbus,代码行数:29,代码来源:cbPosixBackend.py

示例5: seek

 def seek(self, offset, whence=None):
     pycb.log(logging.INFO, "===== def seek of cbPosixBackend.py")
     self.seek_count = self.seek_count + 1
     pycb.log(logging.WARNING, "Someone is seeking %s %d :: %d" % (self.fname, offset, self.seek_count), tb=traceback)
     if self.seek_count > 1:
         raise cbException('InternalError')
     return self.file.seek(offset, whence)
开发者ID:xxy-php,项目名称:code,代码行数:7,代码来源:cbPosixBackend.py

示例6: get_uf

 def get_uf(self, bucketName, objectName=None):
     file = self.get_file_obj(bucketName, objectName)
     if file == None:
         pycb.log(logging.INFO, "b:o not found %s:%s" % (bucketName, str(objectName)))
         raise cbException('NoSuchKey')
     uf = UserFile(file, self.user)
     return uf
开发者ID:oldpatricka,项目名称:nimbus,代码行数:7,代码来源:cbAuthzSecurity.py

示例7: __init__

    def __init__(self, data_key, access="r", openIt=True):
#       file like stuff
        #self.closed = True
        #self.encoding = 
        #self.errors
        #self.mode
        #self.name
        #self.newlines
        #self.softspace

        self.fname = data_key
        self.metafname = data_key + ".meta"
        self.data_key = data_key
        self.blockSize = 1024*512
        self.hashValue = None
        self.delete_on_close = False
        self.md5er = hashlib.md5()

        if not openIt:
            return

        try:
            mFile = open(self.metafname, 'r')
            self.hashValue = mFile.readline()
            mFile.close()
        except:
            pass

        try:
            self.file = open(self.fname, access)
        except OSError, (OsEx):
            if OsEx.errno == errno.ENOENT:
               raise cbException('NoSuchKey')
开发者ID:oldpatricka,项目名称:nimbus,代码行数:33,代码来源:cbPosixBackend.py

示例8: delete_bucket

 def delete_bucket(self, bucketName):
     try:
         file = self.get_file_obj(bucketName)
         kids = file.get_all_children()
         if len(list(kids)) != 0:
             raise cbException('BucketNotEmpty')
         file.delete()
     finally:
         self.db_obj.commit()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:9,代码来源:cbAuthzSecurity.py

示例9: __init__

 def __init__(self, alias_name, con_str):
     self.db_obj = DB(con_str=con_str)
     alias = User.find_alias(self.db_obj, alias_name, pynimbusauthz.alias_type_s3)
     a_list = list(alias)
     if len(a_list) < 1:
         raise cbException('AccessDenied')
     # pick the first one, hmmm XXX
     self.alias = a_list[0]
     self.user = self.alias.get_canonical_user()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:9,代码来源:cbAuthzSecurity.py

示例10: check_permissions

    def check_permissions(self):
        pycb.log(logging.INFO, "===== def check_permissions of cbRequest.py")
        srcExists = self.user.exists(self.srcBucketName, self.srcObjectName)
        if not srcExists:
            raise cbException('NoSuchKey')
        (perms, src_data_key) = self.user.get_perms(self.srcBucketName, self.srcObjectName)
        # make sure that we can read the source
        ndx = perms.find("r")
        if ndx < 0:
            raise cbException('AccessDenied')

        # make sure we can write to the destination
        dstExists = self.user.exists(self.dstBucketName, self.dstObjectName)

        (bperms, bdata_key) = self.user.get_perms(self.dstBucketName)
        ndx = bperms.find("w")
        if ndx < 0:
            raise cbException('AccessDenied')

        dst_data_key = None
        dst_size = 0
        if dstExists:
            (perms, dst_data_key) = self.user.get_perms(self.dstBucketName, self.dstObjectName)
            ndx = perms.find("w")
            if ndx < 0:
                raise cbException('AccessDenied')

            (dst_size, ctm, md5) = self.user.get_info(self.dstBucketName, self.dstObjectName)
        (src_size, self.src_ctm, self.src_md5) = self.user.get_info(self.srcBucketName, self.srcObjectName)

        # check the quota
        remaining_quota = self.user.get_remaining_quota()
        if remaining_quota != User.UNLIMITED:
            if remaining_quota < src_size - dst_size:
                pycb.log(logging.INFO, "user %s did not pass quota.  file size %d quota %d" % (self.user, src_size, remaining_quota))
                raise cbException('AccountProblem')

        # if we get to here we are allowed to do the copy
        if dst_data_key == None:
            self.dst_file = self.bucketIface.put_object(self.dstBucketName, self.dstObjectName)
        else:
            self.dst_file = self.bucketIface.get_object(dst_data_key)
        self.dst_file.set_delete_on_close(True)
        self.src_file = self.bucketIface.get_object(src_data_key) 
开发者ID:xxy-php,项目名称:code,代码行数:44,代码来源:cbRequest.py

示例11: request_object_factory

    def request_object_factory(self, request, user, path, requestId):
        pycb.log(logging.INFO, "===== def request_object_factory of cumulus.py")
        pycb.log(logging.INFO, "path %s" % (path))
        # handle the one service operation
        if path == "/":
            if request.method == 'GET':
                cbR = cbGetService(request, user, requestId, pycb.config.bucket)
                return cbR
            raise cbException('InvalidArgument')

        (bucketName, objectName) = path_to_bucket_object(path)
        init_redirector(request, bucketName, objectName)

        pycb.log(logging.INFO, "path %s bucket %s object %s" % (path, bucketName, str(objectName)))
        if request.method == 'GET':
            if objectName == None:
                cbR = cbGetBucket(request, user, bucketName, requestId, pycb.config.bucket)
            else:
                cbR = cbGetObject(request, user, bucketName, objectName, requestId, pycb.config.bucket)
            return cbR
        elif request.method == 'PUT':
            if objectName == None:
                cbR = cbPutBucket(request, user, bucketName, requestId, pycb.config.bucket)
            else:
                args = request.getAllHeaders()
                if 'x-amz-copy-source' in args:
                    (srcBucketName, srcObjectName) = path_to_bucket_object(args['x-amz-copy-source'])
                    cbR = cbCopyObject(request, user, requestId, pycb.config.bucket, srcBucketName, srcObjectName, bucketName, objectName)
                else:
                    cbR = cbPutObject(request, user, bucketName, objectName, requestId, pycb.config.bucket)
            return cbR
        elif request.method == 'POST':
            pycb.log(logging.ERROR, "Nothing to handle POST")
        elif request.method == 'DELETE':
            if objectName == None:
                cbR = cbDeleteBucket(request, user, bucketName, requestId, pycb.config.bucket)
            else:
                cbR = cbDeleteObject(request, user, bucketName, objectName, requestId, pycb.config.bucket)
            return cbR
        elif request.method == 'HEAD' and objectName != None:
            cbR = cbHeadObject(request, user, bucketName, objectName, requestId, pycb.config.bucket)
            return cbR

        raise cbException('InvalidArgument')
开发者ID:xxy-php,项目名称:code,代码行数:44,代码来源:cumulus.py

示例12: send_access_error

 def send_access_error(self, req):
     ex = cbException('AccessDenied')
     m_msg = "HTTP/1.1 %s %s\r\n" % (ex.httpCode, ex.httpDesc)
     self.transport.write(m_msg)
     m_msg = "%s: %s\r\n" % (('x-amz-request-id', str(uuid.uuid1())))
     self.transport.write(m_msg)
     self.transport.write('content-type: text/html')
     e_msg = ex.make_xml_string(self._path, str(uuid.uuid1()))
     self.transport.write(e_msg)
     self.transport.loseConnection()
开发者ID:acarpena,项目名称:nimbus,代码行数:10,代码来源:cumulus.py

示例13: get_owner

 def get_owner(self, bucketName, objectName=None):
     try:
         uf = self.get_uf(bucketName, objectName)
         o = uf.get_owner()
         uas = list(o.get_alias_by_type(pynimbusauthz.alias_type_s3))
         if len(uas) < 1:
             raise cbException('InternalError')
         return (uas[0].get_name(), uas[0].get_friendly_name())
     finally:
         self.db_obj.commit()
开发者ID:oldpatricka,项目名称:nimbus,代码行数:10,代码来源:cbAuthzSecurity.py

示例14: parse_acl_request

def parse_acl_request(xml):
    pycb.log(logging.INFO, "===== def parse_acl_request of cbRequest.py")
    dom = parseString(xml)
    grant_a = dom.getElementsByTagName("Grant")
    grants = []
    users = {}

    for g in grant_a:
        el = g.getElementsByTagName("URI")
        if el != None and len(el) >= 1:
            u = getText(el[0].childNodes)
            if u == "http://acs.amazonaws.com/groups/global/AllUsers":
                id = "CumulusPublicUser"
                email = ""
            else:
                raise cbException('InvalidArgument')
        else:
            el = g.getElementsByTagName("DisplayName")
            if el == None or len(el) < 1:
                email = None
            else:
                email = getText(el[0].childNodes)
            id = getText(g.getElementsByTagName("ID")[0].childNodes)
        perm_set = g.getElementsByTagName("Permission")

        perms = ""
        for p in perm_set:
            requested_perm = getText(p.childNodes)

            if requested_perm not in perms_strings:
                raise cbException('InvalidArgument')

            pv = perms_strings[requested_perm]
            ndx = perms.find(pv)
            if ndx < 0:
                perms = perms + pv

        if id in users.keys():
            (i, e, p) = users[id]
            perms = perms + p
        users[id] = (id, email, perms)

    return users.values()
开发者ID:xxy-php,项目名称:code,代码行数:43,代码来源:cbRequest.py

示例15: delete_bucket

 def delete_bucket(self, bucketName):
     pycb.log(logging.INFO, "===== def delete_bucket of cbAuthzSecurity.py")
     try:
         file = self.get_file_obj(bucketName)
         kids = file.get_all_children()
         if len(list(kids)) != 0:
             raise cbException('BucketNotEmpty')
         file.delete()
     finally:
         self.db_obj.commit()
开发者ID:xxy-php,项目名称:code,代码行数:10,代码来源:cbAuthzSecurity.py


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