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


Python util.waterbutler_url_for函数代码示例

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


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

示例1: _get_fileobj_child_metadata

 def _get_fileobj_child_metadata(self, filenode, user, cookie=None, version=None):
     kwargs = dict(
         provider=self.config.short_name,
         path=filenode.get('path', ''),
         node=self.owner,
         user=user,
         view_only=True,
     )
     if cookie:
         kwargs['cookie'] = cookie
     if version:
         kwargs['version'] = version
     metadata_url = waterbutler_url_for(
         'metadata',
         **kwargs
     )
     res = requests.get(metadata_url)
     if res.status_code != 200:
         # The Dataverse API returns a 404 if the dataset has no published files
         if res.status_code == http.NOT_FOUND and version == 'latest-published':
             return []
         raise HTTPError(res.status_code, data={
             'error': res.json(),
         })
     # TODO: better throttling?
     sleep(1.0 / 5.0)
     return res.json().get('data', [])
开发者ID:XTech2K,项目名称:osf.io,代码行数:27,代码来源:model.py

示例2: _test__get_file_tree

    def _test__get_file_tree(self, addon_short_name):
        requests_made = []
        def callback(request, uri, headers):
            path = request.querystring['path'][0]
            requests_made.append(path)
            return (200, headers, json.dumps(self.RESP_MAP[path]))

        for path in self.RESP_MAP.keys():
            url = waterbutler_url_for(
                'metadata',
                provider=addon_short_name,
                path=path,
                node=self.src,
                user=self.user,
                view_only=True,
            )
            httpretty.register_uri(httpretty.GET,
                                   url,
                                   body=callback,
                                   content_type='applcation/json')
        addon = self.src.get_or_add_addon(addon_short_name, auth=self.auth)
        root = {
            'path': '/',
            'name': '',
            'kind': 'folder',
        }
        file_tree = addon._get_file_tree(root, self.user)
        assert_equal(FILE_TREE, file_tree)
        assert_equal(requests_made, ['/', '/qwerty'])  # no requests made for files
开发者ID:bdyetton,项目名称:osf.io,代码行数:29,代码来源:test_archiver.py

示例3: _get_fileobj_child_metadata

 def _get_fileobj_child_metadata(self, filenode, user, cookie=None, version=None):
     kwargs = dict(
         provider=self.config.short_name,
         path=filenode.get('path', ''),
         node=self.owner,
         user=user,
         view_only=True,
     )
     if cookie:
         kwargs['cookie'] = cookie
     if version:
         kwargs['version'] = version
     metadata_url = waterbutler_url_for(
         'metadata',
         _internal=True,
         **kwargs
     )
     res = requests.get(metadata_url)
     if res.status_code != 200:
         raise HTTPError(res.status_code, data={
             'error': res.json(),
         })
     # TODO: better throttling?
     sleep(1.0 / 5.0)
     return res.json().get('data', [])
开发者ID:adlius,项目名称:osf.io,代码行数:25,代码来源:mock_addons.py

示例4: test_waterbutler_url_for

    def test_waterbutler_url_for(self):
        with self.app.test_request_context():
            url = waterbutler_url_for('upload', 'provider', 'path', mock.Mock(_id='_id'))

        assert_in('nid=_id', url)
        assert_in('/file?', url)
        assert_in('path=path', url)
        assert_in('provider=provider', url)
开发者ID:XTech2K,项目名称:osf.io,代码行数:8,代码来源:test_utils.py

示例5: test_waterbutler_url_for_implicit_cookie

    def test_waterbutler_url_for_implicit_cookie(self):
        with self.app.test_request_context() as context:
            context.request.cookies = {settings.COOKIE_NAME: 'cookie'}
            url = waterbutler_url_for('upload', 'provider', 'path', mock.Mock(_id='_id'))

        assert_in('nid=_id', url)
        assert_in('/file?', url)
        assert_in('path=path', url)
        assert_in('cookie=cookie', url)
        assert_in('provider=provider', url)
开发者ID:XTech2K,项目名称:osf.io,代码行数:10,代码来源:test_utils.py

示例6: upload_attachment

def upload_attachment(user, node, attachment):
    attachment.seek(0)
    name = '/' + (attachment.filename or settings.MISSING_FILE_NAME)
    content = attachment.read()
    upload_url = util.waterbutler_url_for('upload', 'osfstorage', name, node, user=user, _internal=True)

    requests.put(
        upload_url,
        data=content,
    )
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:utils.py

示例7: send_file

def send_file(app, name, content_type, file_like, node, user):
    """Upload file to OSF."""
    file_like.seek(0)
    with app.test_request_context():
        upload_url = util.waterbutler_url_for('upload', 'osfstorage', name, node, user=user)
    requests.put(
        upload_url,
        data=file_like,
        headers={'Content-Type': content_type},
    )
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:10,代码来源:utils.py

示例8: test_waterbutler_url_for_internal

    def test_waterbutler_url_for_internal(self):
        settings.WATERBUTLER_INTERNAL_URL = 'http://1.2.3.4:7777'
        with self.app.test_request_context():
            url = waterbutler_url_for('upload', 'provider', 'path', mock.Mock(_id='_id'), _internal=True)

        assert_not_in(settings.WATERBUTLER_URL, url)
        assert_in(settings.WATERBUTLER_INTERNAL_URL, url)
        assert_in('nid=_id', url)
        assert_in('/file?', url)
        assert_in('path=path', url)
        assert_in('provider=provider', url)
开发者ID:adlius,项目名称:osf.io,代码行数:11,代码来源:test_utils.py

示例9: _get_fileobj_child_metadata

 def _get_fileobj_child_metadata(self, filenode, user, cookie=None, version=None):
     kwargs = dict(
         provider=self.config.short_name, path=filenode.get("path", ""), node=self.owner, user=user, view_only=True
     )
     if cookie:
         kwargs["cookie"] = cookie
     if version:
         kwargs["version"] = version
     metadata_url = waterbutler_url_for("metadata", **kwargs)
     res = requests.get(metadata_url)
     if res.status_code != 200:
         raise HTTPError(res.status_code, data={"error": res.json()})
     # TODO: better throttling?
     sleep(1.0 / 5.0)
     return res.json().get("data", [])
开发者ID:cslzchen,项目名称:osf.io,代码行数:15,代码来源:__init__.py


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