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


Python api_resources.File类代码示例

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


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


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