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


Python types.ObjectDoesNotExistError方法代码示例

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


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

示例1: _download_bytes

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def _download_bytes(self, container, object_name, missing=None):
        tempdir = tempfile.mkdtemp()
        tempfilepath = os.path.join(
            tempdir, '_tmp_wheelhouse_uploader_download_' + object_name)
        try:
            container.get_object(object_name).download(tempfilepath)
            with open(tempfilepath, 'rb') as f:
                return f.read()
        except ObjectDoesNotExistError:
            return missing
        finally:
            try:
                shutil.rmtree(tempdir)
            except OSError:
                # Ignore permission errors on temporary directories
                print("WARNING: faile to delete", tempdir) 
开发者ID:ogrisel,项目名称:wheelhouse-uploader,代码行数:18,代码来源:upload.py

示例2: test_cloud_master_key_store_s3

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def test_cloud_master_key_store_s3(request, tmpdir):
    try:
        access_key = request.config.getoption('--aws-access-key')
        secret_key = request.config.getoption('--aws-secret-key')
        bucket_name = request.config.getoption('--aws-s3-bucket')
    except ValueError:
        access_key = secret_key = bucket_name = None
    if access_key is None or secret_key is None or bucket_name is None:
        skip(
            '--aws-access-key/--aws-secret-key/--aws-s3-bucket are not '
            'provided; skipped'
        )
    driver_cls = get_driver(Provider.S3)
    driver = driver_cls(access_key, secret_key)
    container = driver.get_container(container_name=bucket_name)
    tmpname = ''.join(map('{:02x}'.format, os.urandom(16)))
    s = CloudMasterKeyStore(driver, container, tmpname)
    key = RSAKey.generate(1024)
    # load() -- when not exists
    with raises(EmptyStoreError):
        s.load()
    try:
        # save()
        s.save(key)
        obj = driver.get_object(container.name, tmpname)
        dest = tmpdir / tmpname
        obj.download(str(dest))
        saved = read_private_key_file(dest.open())
        assert isinstance(saved, RSAKey)
        assert saved.get_base64() == key.get_base64()
        # load() -- when exists
        loaded = s.load()
        assert isinstance(loaded, RSAKey)
        assert loaded.get_base64() == key.get_base64()
    finally:
        try:
            o = driver.get_object(container.name, tmpname)
        except ObjectDoesNotExistError:
            pass
        else:
            o.delete() 
开发者ID:spoqa,项目名称:geofront,代码行数:43,代码来源:cloud_test.py

示例3: load

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def load(self) -> PKey:
        try:
            obj = self.driver.get_object(self.container.name, self.object_name)
        except ObjectDoesNotExistError:
            raise EmptyStoreError()
        with io.BytesIO() as buffer_:
            for chunk in self.driver.download_object_as_stream(obj):
                if isinstance(chunk, str):  # DummyDriver yields str, not bytes
                    chunk = chunk.encode()
                buffer_.write(chunk)
            buffer_.seek(0)
            with io.TextIOWrapper(buffer_) as tio:
                return read_private_key_file(tio) 
开发者ID:spoqa,项目名称:geofront,代码行数:15,代码来源:cloud.py

示例4: __download_blob

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def __download_blob(connection, src, dest, bucket_name):
    """
    This function is called by StorageJob. It may be called concurrently by multiple threads.

    :param connection: A storage connection which is created and managed by StorageJob
    :param src: The file to download
    :param dest: The path to where the file should be downloaded
    :param bucket_name: The name of the bucket from which the file will be downloaded
    :return:
    """
    try:
        logging.debug("[Storage] Getting object {}".format(src))
        blob = connection.get_object(bucket_name, str(src))
        # we must make sure the blob gets stored under sub-folder (if there is any)
        # the dest variable only points to the table folder, so we need to add the sub-folder
        src_path = pathlib.Path(src)
        blob_dest = '{}/{}'.format(dest, src_path.parent.name) if src_path.parent.name.startswith('.') else dest
        index = blob.name.rfind("/")
        if index > 0:
            file_name = blob.name[blob.name.rfind("/") + 1:]
        else:
            file_name = blob.name

        with open("{}/{}".format(blob_dest, file_name), "wb") as file_handle:
            for chunk in blob.as_stream():
                file_handle.write(chunk)
    except ObjectDoesNotExistError:
        return None 
开发者ID:thelastpickle,项目名称:cassandra-medusa,代码行数:30,代码来源:concurrent.py

示例5: __download_blob

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def __download_blob(storage, connection, src, dest, bucket, multi_part_upload_threshold):
    """
    This function is called by StorageJob. It may be called concurrently by multiple threads.

    :param connection: A storage connection which is created and managed by StorageJob
    :param src: The file to download
    :param dest: The path to where the file should be downloaded
    :param bucket: Bucket from which the file will be downloaded
    :return:
    """
    try:
        logging.debug("[Storage] Getting object {}".format(src))
        blob = connection.get_object(bucket.name, str(src))

        # we must make sure the blob gets stored under sub-folder (if there is any)
        # the dest variable only points to the table folder, so we need to add the sub-folder
        src_path = pathlib.Path(src)
        blob_dest = (
            "{}/{}".format(dest, src_path.parent.name)
            if src_path.parent.name.startswith(".")
            else dest
        )

        if int(blob.size) >= multi_part_upload_threshold:
            # Files larger than the configured threshold should be uploaded as multi part
            logging.debug("Downloading {} as multi part".format(blob_dest))
            _download_multi_part(storage, connection, src_path, bucket, blob_dest)
        else:
            logging.debug("Downloading {} as single part".format(blob_dest))
            _download_single_part(connection, blob, blob_dest)

    except ObjectDoesNotExistError:
        return None 
开发者ID:thelastpickle,项目名称:cassandra-medusa,代码行数:35,代码来源:concurrent.py

示例6: get_blob

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def get_blob(self, path):
        try:
            logging.debug("[Storage] Getting object {}".format(path))
            return self.driver.get_object(self.bucket.name, str(path))
        except ObjectDoesNotExistError:
            return None 
开发者ID:thelastpickle,项目名称:cassandra-medusa,代码行数:8,代码来源:abstract_storage.py

示例7: upload_file

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def upload_file(self, filepath, container_name):
        # drivers are not thread safe, hence we create one per upload task
        # to make it possible to use a thread pool executor
        driver = self.make_driver()
        filename = os.path.basename(filepath)
        container = driver.get_container(container_name)

        size_mb = os.stat(filepath).st_size / 1e6
        print("Uploading %s [%0.3f MB]" % (filepath, size_mb))
        driver.upload_object(file_path=filepath,
                             container=container,
                             object_name=filename)

        if self.delete_previous_dev_packages:
            existing_filenames = self._get_package_filenames(driver, container)
            if filename not in existing_filenames:
                # Eventual consistency listing might cause the just uploaded
                # file not be missing. Ensure this is never the case.
                existing_filenames.append(filename)
            previous_dev_filenames = matching_dev_filenames(filename,
                                                            existing_filenames)

            # Only keep the last 5 dev builds
            for filename in previous_dev_filenames[5:]:
                print("Deleting old dev package %s" % filename)
                try:
                    obj = container.get_object(filename)
                    driver.delete_object(obj)
                except ObjectDoesNotExistError:
                    pass 
开发者ID:ogrisel,项目名称:wheelhouse-uploader,代码行数:32,代码来源:upload.py

示例8: _get_object

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def _get_object(self, name):
        """Get object by its name. Return None if object not found"""
        clean_name = self._clean_name(name)
        try:
            return self.driver.get_object(self.bucket, clean_name)
        except ObjectDoesNotExistError:
            return None 
开发者ID:jschneier,项目名称:django-storages,代码行数:9,代码来源:apache_libcloud.py

示例9: __contains__

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def __contains__(self, object_name):
        """
        ie: `if name in storage` or `if name not in storage`
        Test if object exists
        :param object_name: the object name
        :return bool:
        """
        try:
            self.driver.get_object(self.container.name, object_name)
            return True
        except ObjectDoesNotExistError:
            return False 
开发者ID:mardix,项目名称:flask-cloudy,代码行数:14,代码来源:flask_cloudy.py

示例10: get

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def get(self, request, *args, **kwargs):
        try:
            project_id = request.query_params['project_id']
            file_format = request.query_params['upload_format']
            cloud_container = request.query_params['container']
            cloud_object = request.query_params['object']
        except KeyError as ex:
            raise ValidationError('query parameter {} is missing'.format(ex))

        try:
            cloud_file = self.get_cloud_object_as_io(cloud_container, cloud_object)
        except ContainerDoesNotExistError:
            raise ValidationError('cloud container {} does not exist'.format(cloud_container))
        except ObjectDoesNotExistError:
            raise ValidationError('cloud object {} does not exist'.format(cloud_object))

        TextUploadAPI.save_file(
            user=request.user,
            file=cloud_file,
            file_format=file_format,
            project_id=project_id,
        )

        next_url = request.query_params.get('next')

        if next_url == 'about:blank':
            return Response(data='', content_type='text/plain', status=status.HTTP_201_CREATED)

        if next_url:
            return redirect(next_url)

        return Response(status=status.HTTP_201_CREATED) 
开发者ID:doccano,项目名称:doccano,代码行数:34,代码来源:views.py

示例11: test_malicious_local_get_blob

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def test_malicious_local_get_blob(self):
        with self.assertRaises(ObjectDoesNotExistError):
            blob = storage.get_blob(obj_name='../README.md')

        with self.assertRaises(ObjectDoesNotExistError):
            blob = storage.get_blob(obj_name='/bin/bash')

        with self.assertRaises(ObjectDoesNotExistError):
            blob = storage.get_blob(obj_name='foobar.txt') 
开发者ID:okpy,项目名称:ok,代码行数:11,代码来源:test_files.py

示例12: delete_silently

# 需要导入模块: from libcloud.storage import types [as 别名]
# 或者: from libcloud.storage.types import ObjectDoesNotExistError [as 别名]
def delete_silently(blob):
    try:
        blob.delete()
    except (ObjectDoesNotExistError, OSError):
        pass 
开发者ID:okpy,项目名称:ok,代码行数:7,代码来源:test_files.py


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