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


Python s3boto3.S3Boto3Storage方法代码示例

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


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

示例1: run

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def run(self, id_filename):
        s3 = S3Boto3Storage().connection
        obj = s3.Object(self.output_bucket, id_filename)
        arxiv_id_str = obj.get()["Body"].read().decode("utf-8")
        arxiv_ids = [s.strip() for s in arxiv_id_str.split() if s.strip()]

        # We can't access database inside our gevent pool because of max
        # connections, so first figure out which IDs we actually want to
        # render.
        arxiv_ids, source_paths = self.filter_unrenderable_ids(arxiv_ids)

        # Stagger the starting of jobs a bit so we don't break Hyper.sh
        def slow_arxiv_ids():
            for arxiv_id in arxiv_ids:
                yield arxiv_id
                time.sleep(0.1)

        pool = Pool(self.concurrency)
        manifest = pool.imap_unordered(self.render, slow_arxiv_ids(), source_paths)
        # Failed renders are None
        manifest = (obj for obj in manifest if obj)
        # Read the iterator, starting the actual processing
        manifest = list(manifest)
        self.write_manifest(manifest) 
开发者ID:arxiv-vanity,项目名称:arxiv-vanity,代码行数:26,代码来源:bulk_render.py

示例2: ready

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def ready(self):
        from django.core.files.storage import default_storage
        from storages.backends.s3boto3 import S3Boto3Storage
        from django import forms

        from .forms import S3FileInputMixin

        if isinstance(default_storage, S3Boto3Storage) and \
                S3FileInputMixin not in forms.ClearableFileInput.__bases__:
            forms.ClearableFileInput.__bases__ = \
                (S3FileInputMixin,) + forms.ClearableFileInput.__bases__

        elif S3FileInputMixin in forms.ClearableFileInput.__bases__:
            forms.ClearableFileInput.__bases__ = tuple(
                cls for cls in forms.ClearableFileInput.__bases__
                if cls is not S3FileInputMixin
            )

        checks.register(storage_check, checks.Tags.security, deploy=True) 
开发者ID:codingjoe,项目名称:django-s3file,代码行数:21,代码来源:apps.py

示例3: serve_document_from_s3

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def serve_document_from_s3(document, request):
    # Skip this hook if not using django-storages boto3 backend.
    if not issubclass(get_storage_class(), S3Boto3Storage):
        return

    # Send document_served signal.
    document_served.send(sender=get_document_model(), instance=document,
                         request=request)

    # Get direct S3 link.
    file_url = document.file.url

    # Generate redirect response and add never_cache headers.
    response = redirect(file_url)
    del response['Cache-control']
    add_never_cache_headers(response)
    return response 
开发者ID:torchbox,项目名称:wagtail-torchbox,代码行数:19,代码来源:wagtail_hooks.py

示例4: write_manifest

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def write_manifest(self, manifest):
        s3 = S3Boto3Storage().connection
        manifest_json = json.dumps(manifest, indent=2)
        s3.Object(self.output_bucket, "manifest.json").put(Body=manifest_json) 
开发者ID:arxiv-vanity,项目名称:arxiv-vanity,代码行数:6,代码来源:bulk_render.py

示例5: get_manifest

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def get_manifest():
    """
    Download and parse manifest from arxiv S3 bucket.
    """
    connection = S3Boto3Storage().connection
    obj = connection.Object("arxiv", "src/arXiv_src_manifest.xml")
    s = obj.get(RequestPayer="requester")["Body"].read()
    return parse_manifest(s) 
开发者ID:arxiv-vanity,项目名称:arxiv-vanity,代码行数:10,代码来源:bulk_sources.py

示例6: download_tarball

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def download_tarball(key, local_filename):
    connection = S3Boto3Storage().connection
    bucket = connection.Bucket("arxiv")
    bucket.download_file(key, local_filename, {"RequestPayer": "requester"}) 
开发者ID:arxiv-vanity,项目名称:arxiv-vanity,代码行数:6,代码来源:bulk_sources.py

示例7: setUp

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def setUp(self):
        self.storage = s3boto3.S3Boto3Storage()
        self.storage._connections.connection = mock.MagicMock() 
开发者ID:jschneier,项目名称:django-storages,代码行数:5,代码来源:test_s3boto3.py

示例8: test_location_leading_slash

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def test_location_leading_slash(self):
        msg = (
            "S3Boto3Storage.location cannot begin with a leading slash. "
            "Found '/'. Use '' instead."
        )
        with self.assertRaises(ImproperlyConfigured, msg=msg):
            s3boto3.S3Boto3Storage(location='/') 
开发者ID:jschneier,项目名称:django-storages,代码行数:9,代码来源:test_s3boto3.py

示例9: test_override_settings

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def test_override_settings(self):
        with override_settings(AWS_LOCATION='foo1'):
            storage = s3boto3.S3Boto3Storage()
            self.assertEqual(storage.location, 'foo1')
        with override_settings(AWS_LOCATION='foo2'):
            storage = s3boto3.S3Boto3Storage()
            self.assertEqual(storage.location, 'foo2') 
开发者ID:jschneier,项目名称:django-storages,代码行数:9,代码来源:test_s3boto3.py

示例10: test_override_class_variable

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def test_override_class_variable(self):
        class MyStorage1(s3boto3.S3Boto3Storage):
            location = 'foo1'

        storage = MyStorage1()
        self.assertEqual(storage.location, 'foo1')

        class MyStorage2(s3boto3.S3Boto3Storage):
            location = 'foo2'

        storage = MyStorage2()
        self.assertEqual(storage.location, 'foo2') 
开发者ID:jschneier,项目名称:django-storages,代码行数:14,代码来源:test_s3boto3.py

示例11: test_override_init_argument

# 需要导入模块: from storages.backends import s3boto3 [as 别名]
# 或者: from storages.backends.s3boto3 import S3Boto3Storage [as 别名]
def test_override_init_argument(self):
        storage = s3boto3.S3Boto3Storage(location='foo1')
        self.assertEqual(storage.location, 'foo1')
        storage = s3boto3.S3Boto3Storage(location='foo2')
        self.assertEqual(storage.location, 'foo2') 
开发者ID:jschneier,项目名称:django-storages,代码行数:7,代码来源:test_s3boto3.py


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