• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python api_resources.File类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

 def __init__(self, cdn_url_or_file_id):
     matches = cdn_url_or_file_id.startswith('links/')
     if matches:
         self.s3_path = cdn_url_or_file_id
         self.uuid = None
     else:
         self.s3_path = None
         File.__init__(self, cdn_url_or_file_id)
开发者ID:michaelmior,项目名称:pylinks,代码行数:8,代码来源:utils.py


示例2: test_value_error_when_uuid_is_bad

    def test_value_error_when_uuid_is_bad(self):
        file_serialized_invalid = "blah"
        self.assertRaises(InvalidParamError, File, file_serialized_invalid)

        file_serialized_valid = "3addab78-6368-4c55-ac08-22412b6a2a4c"
        file_ = File(file_serialized_valid)

        self.assertRaises(InvalidParamError, setattr, file_, "uuid", file_serialized_invalid)
        self.assertRaises(InvalidParamError, setattr, file_, "uuid", file_serialized_valid + file_serialized_invalid)

        file_.uuid = file_serialized_valid
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:11,代码来源:test_api_resources.py


示例3: _wait_if_needed

def _wait_if_needed(arg_namespace, check_func, error_msg):
    if not arg_namespace.wait:
        return

    for path in arg_namespace.paths:
        file_ = File(path)
        timeout = arg_namespace.timeout
        time_started = time.time()
        while not check_func(file_):
            if time.time() - time_started > timeout:
                raise TimeoutError(error_msg)
            file_.update_info()
            time.sleep(0.1)
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:13,代码来源:__init__.py


示例4: upload_from_url

def upload_from_url(arg_namespace):
    if not _check_upload_args(arg_namespace):
        return
    file_from_url = File.upload_from_url(arg_namespace.url)
    pprint(file_from_url)

    if arg_namespace.wait or arg_namespace.store:
        timeout = arg_namespace.timeout
        time_started = time.time()
        while time.time() - time_started < timeout:
            status = file_from_url.update_info()['status']
            if status == 'success':
                break
            if status in ('failed', 'error'):
                raise UploadError(
                    'could not upload file from url: {0}'.format(
                        file_from_url.info())
                )
            time.sleep(1)
        else:
            raise TimeoutError('timed out during upload')

    if arg_namespace.store or arg_namespace.info:
        file_ = file_from_url.get_file()
        if file_ is None:
            pprint('Cannot store or get info.')
            return

        _handle_uploaded_file(file_, arg_namespace)
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:29,代码来源:__init__.py


示例5: setUpClass

    def setUpClass(cls):
        conf.pub_key = 'demopublickey'
        conf.secret = 'demoprivatekey'

        # create file to copy from
        file_from_url = File.upload_from_url(
            'https://github.com/images/error/angry_unicorn.png'
        )

        timeout = 30
        time_started = time.time()

        while time.time() - time_started < timeout:
            status = file_from_url.update_info()['status']
            if status in ('success', 'failed', 'error'):
                break
            time.sleep(1)

        cls.f = file_from_url.get_file()
        time_started = time.time()
        while time.time() - time_started < timeout:
            if cls.f.is_ready():
                break
            time.sleep(1)
            cls.f.update_info()
开发者ID:un33k,项目名称:pyuploadcare,代码行数:25,代码来源:test_api_resources.py


示例6: test_create_local_copy

    def test_create_local_copy(self):
        response = self.f.create_local_copy()
        self.assertEqual('file', response['type'])

        response = self.f.create_local_copy(effects='resize/50x/')
        self.assertEqual('file', response['type'])

        response = self.f.create_local_copy(effects='resize/50x/', store=True)
        file = File(response['result']['uuid'])
        time.sleep(2)
        self.assertEqual(file.is_stored(), True)

        response = self.f.create_local_copy(store=False)
        file = File(response['result']['uuid'])
        time.sleep(2)
        self.assertEqual(file.is_stored(), False)
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:16,代码来源:test_api_resources.py


示例7: test_successful_upload_from_url_sync_with_filename

 def test_successful_upload_from_url_sync_with_filename(self):
     file = File.upload_from_url_sync(
         'https://github.com/images/error/angry_unicorn.png',
         filename='meh.png',
         interval=1
     )
     self.assertIsInstance(file, File)
     self.assertEqual(file.filename(), 'meh.png')
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:8,代码来源:test_api_resources.py


示例8: test_successful_upload_from_url_sync_store

 def test_successful_upload_from_url_sync_store(self):
     file = File.upload_from_url_sync(
         'https://github.com/images/error/angry_unicorn.png',
         store=True,
         interval=1
     )
     self.assertIsInstance(file, File)
     self.assertIsNotNone(file.datetime_stored())
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:8,代码来源:test_api_resources.py


示例9: upload_tmp_txt_file

def upload_tmp_txt_file(content=''):
    conf.pub_key = 'demopublickey'

    tmp_txt_file = NamedTemporaryFile(mode='wb', delete=False)
    tmp_txt_file.write(content.encode('utf-8'))
    tmp_txt_file.close()

    with open(tmp_txt_file.name, 'rb') as fh:
        file_ = File.upload(fh, store=False)
    return file_
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:10,代码来源:utils.py


示例10: test_successful_upload_from_url

    def test_successful_upload_from_url(self):
        file_from_url = File.upload_from_url(
            'https://github.com/images/error/angry_unicorn.png'
        )

        timeout = 30
        time_started = time.time()

        while time.time() - time_started < timeout:
            status = file_from_url.update_info()['status']
            if status in ('success', 'failed', 'error'):
                break
            time.sleep(1)

        self.assertIsInstance(file_from_url.get_file(), File)
开发者ID:un33k,项目名称:pyuploadcare,代码行数:15,代码来源:test_api_resources.py


示例11: setUpClass

    def setUpClass(cls):
        super(FileCopyTest, cls).setUpClass()

        # create file to copy from
        file_from_url = File.upload_from_url(
            'https://github.com/images/error/angry_unicorn.png'
        )

        timeout = 30
        time_started = time.time()

        while time.time() - time_started < timeout:
            status = file_from_url.update_info()['status']
            if status in ('success', 'failed', 'error'):
                break
            time.sleep(1)

        cls.f = file_from_url.get_file()
        time_started = time.time()
        while time.time() - time_started < timeout:
            if cls.f.is_ready():
                break
            time.sleep(1)
            cls.f.update_info()
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:24,代码来源:test_api_resources.py


示例12: FileDateMethodsTest

class FileDateMethodsTest(unittest.TestCase):

    def setUp(self):
        self.file = File('a771f854-c2cb-408a-8c36-71af77811f3b')

    def test_datetime_stored_is_none(self):
        self.file._info_cache = {'datetime_stored': ''}
        self.assertIsNone(self.file.datetime_stored())

    def test_datetime_stored_is_utc(self):
        self.file._info_cache = {'datetime_stored': '2013-02-05T12:56:12.006Z'}
        expected_datetime = datetime.datetime(
            year=2013, month=2, day=5, hour=12, minute=56, second=12,
            microsecond=6000, tzinfo=tzutc())
        self.assertEqual(self.file.datetime_stored(), expected_datetime)

    def test_datetime_removed_is_none(self):
        self.file._info_cache = {}
        self.assertIsNone(self.file.datetime_removed())

    def test_datetime_removed_is_utc(self):
        self.file._info_cache = {'datetime_removed': '2013-02-05T12:56:12.006Z'}
        expected_datetime = datetime.datetime(
            year=2013, month=2, day=5, hour=12, minute=56, second=12,
            microsecond=6000, tzinfo=tzutc())
        self.assertEqual(self.file.datetime_removed(), expected_datetime)

    def test_datetime_uploaded_is_none(self):
        self.file._info_cache = {'datetime_uploaded': None}
        self.assertIsNone(self.file.datetime_uploaded())

    def test_datetime_uploaded_is_utc(self):
        self.file._info_cache = {'datetime_uploaded': '2013-02-05T12:56:12.006Z'}
        expected_datetime = datetime.datetime(
            year=2013, month=2, day=5, hour=12, minute=56, second=12,
            microsecond=6000, tzinfo=tzutc())
        self.assertEqual(self.file.datetime_uploaded(), expected_datetime)
开发者ID:vishalbandre,项目名称:pyuploadcare,代码行数:37,代码来源:test_api_resources.py


示例13: test_remote_copy_source

    def test_remote_copy_source(self, request):
        request.return_value = {}

        # uuid with no effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b')
        f.copy(target='tgt')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/",
            "target": "tgt"})

        # uuid with effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b')
        f.copy(target='tgt', effects='resize/1x1/')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/1x1/",
            "target": "tgt"})

        # cdn url with no effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/')
        f.copy(target='tgt')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/",
            "target": "tgt"})

        # cdn url with effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/')
        f.copy(target='tgt', effects='flip/')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/-/flip/",
            "target": "tgt"})
开发者ID:vishalbandre,项目名称:pyuploadcare,代码行数:30,代码来源:test_api_resources.py


示例14: test_successful_upload_from_url_sync

 def test_successful_upload_from_url_sync(self):
     file_from_url = File.upload_from_url(
         'https://github.com/images/error/angry_unicorn.png'
     )
     file = file_from_url.wait(interval=1, until_ready=False)
     self.assertIsInstance(file, File)
开发者ID:un33k,项目名称:pyuploadcare,代码行数:6,代码来源:test_api_resources.py


示例15: test_get_some_token

 def test_get_some_token(self):
     file_from_url = File.upload_from_url(
         'https://github.com/images/error/angry_unicorn.png'
     )
     self.assertTrue(file_from_url.token)
开发者ID:un33k,项目名称:pyuploadcare,代码行数:5,代码来源:test_api_resources.py


示例16: test_successful_upload_when_file_is_opened_in_binary_mode

    def test_successful_upload_when_file_is_opened_in_binary_mode(self):
        with open(self.tmp_txt_file.name, 'rb') as fh:
            file_ = File.upload(fh)

        self.assertIsInstance(file_, File)
开发者ID:un33k,项目名称:pyuploadcare,代码行数:5,代码来源:test_api_resources.py


示例17: upload

def upload(arg_namespace):
    if not _check_upload_args(arg_namespace):
        return
    with open(arg_namespace.filename, 'rb') as fh:
        file_ = File.upload(fh)
        _handle_uploaded_file(file_, arg_namespace)
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:6,代码来源:__init__.py


示例18: test_remote_copy_source

    def test_remote_copy_source(self, request):
        request.return_value = {}

        # uuid with no effects
        f = File("a771f854-c2cb-408a-8c36-71af77811f3b")
        f.copy(target="tgt")
        request.assert_called_with(
            "POST", "files/", data={"source": "a771f854-c2cb-408a-8c36-71af77811f3b/", "target": "tgt"}
        )

        # uuid with effects
        f = File("a771f854-c2cb-408a-8c36-71af77811f3b")
        f.copy(target="tgt", effects="resize/1x1/")
        request.assert_called_with(
            "POST", "files/", data={"source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/1x1/", "target": "tgt"}
        )

        # cdn url with no effects
        f = File("a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/")
        f.copy(target="tgt")
        request.assert_called_with(
            "POST", "files/", data={"source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/", "target": "tgt"}
        )

        # cdn url with effects
        f = File("a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/")
        f.copy(target="tgt", effects="flip/")
        request.assert_called_with(
            "POST",
            "files/",
            data={"source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/-/flip/", "target": "tgt"},
        )
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:32,代码来源:test_api_resources.py


示例19: setUp

 def setUp(self):
     self.file = File('a771f854-c2cb-408a-8c36-71af77811f3b')
开发者ID:vishalbandre,项目名称:pyuploadcare,代码行数:2,代码来源:test_api_resources.py


示例20: test_create_remote_copy

    def test_create_remote_copy(self, request):
        request.return_value = {}

        # uuid with no effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b')
        f.create_remote_copy(target='tgt')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/",
            "target": "tgt"})

        # uuid with effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b')
        f.create_remote_copy(target='tgt', effects='resize/1x1/')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/1x1/",
            "target": "tgt"})

        # cdn url with no effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/')
        f.create_remote_copy(target='tgt')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/2x2/",
            "target": "tgt"})

        # cdn url with effects
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/')
        f.create_remote_copy(target='tgt', effects='flip/')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/-/flip/",
            "target": "tgt"})

        #cdn url with effects, set permissions to public
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/')
        f.create_remote_copy(target='tgt', effects='flip/', make_public=True)
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/-/flip/",
            "target": "tgt",
            "make_public": True})

        #cdn url with effects, naming pattern
        f = File('a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/')
        f.create_remote_copy(target='tgt', effects='flip/', pattern='${uuid}')
        request.assert_called_with('POST', 'files/', data={
            "source": "a771f854-c2cb-408a-8c36-71af77811f3b/-/resize/3x3/-/flip/",
            "target": "tgt",
            "pattern": "${uuid}"})
开发者ID:uploadcare,项目名称:pyuploadcare,代码行数:46,代码来源:test_api_resources.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python api_resources.FileGroup类代码示例发布时间:2022-05-27
下一篇:
Python downloader.FileDownloader类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap