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

Python toolkit.response函数代码示例

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

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



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

示例1: put_image_layer

def put_image_layer(image_id):
    try:
        json_data = store.get_content(store.image_json_path(image_id))
    except IOError:
        return api_error('Image not found', 404)
    layer_path = store.image_layer_path(image_id)
    mark_path = store.image_mark_path(image_id)
    if store.exists(layer_path) and not store.exists(mark_path):
        return api_error('Image already exists', 409)
    input_stream = request.stream
    if request.headers.get('transfer-encoding') == 'chunked':
        # Careful, might work only with WSGI servers supporting chunked
        # encoding (Gunicorn)
        input_stream = request.environ['wsgi.input']
    store.stream_write(layer_path, input_stream)
    # FIXME(sam): Compute the checksum while uploading the image to save time
    try:
        checksum = store.get_content(store.image_checksum_path(image_id))
    except IOError:
        # We don't have a checksum stored yet, that's fine skipping the check.
        # Not removing the mark though, image is not downloadable yet.
        return response()
    if check_image_checksum(image_id, checksum, json_data) is False:
        logger.debug('put_image_layer: Wrong checksum')
        return api_error('Checksum mismatch, ignoring the layer')
    # Checksum is ok, we remove the marker
    store.remove(mark_path)
    return response()
开发者ID:xdissent,项目名称:docker-registry,代码行数:28,代码来源:images.py


示例2: get_post_users

def get_post_users():
    if flask.request.method == "GET":
        return toolkit.response("OK", 200)
    try:
        json.loads(flask.request.data)
    except json.JSONDecodeError:
        return toolkit.api_error("Error Decoding JSON", 400)
    return toolkit.response("User Created", 201)
开发者ID:proppy,项目名称:docker-registry,代码行数:8,代码来源:index.py


示例3: put_image_layer

def put_image_layer(image_id):
    try:
        json_data = store.get_content(store.image_json_path(image_id))
    except IOError:
        return toolkit.api_error('Image not found', 404)
    layer_path = store.image_layer_path(image_id)
    mark_path = store.image_mark_path(image_id)
    if store.exists(layer_path) and not store.exists(mark_path):
        return toolkit.api_error('Image already exists', 409)
    input_stream = flask.request.stream
    if flask.request.headers.get('transfer-encoding') == 'chunked':
        # Careful, might work only with WSGI servers supporting chunked
        # encoding (Gunicorn)
        input_stream = flask.request.environ['wsgi.input']
    # compute checksums
    csums = []
    sr = toolkit.SocketReader(input_stream)
    tmp, store_hndlr = storage.temp_store_handler()
    sr.add_handler(store_hndlr)
    h, sum_hndlr = checksums.simple_checksum_handler(json_data)
    sr.add_handler(sum_hndlr)
    store.stream_write(layer_path, sr)

    # read layer files and cache them
    try:
        files_json = json.dumps(layers.get_image_files_from_fobj(tmp))
        layers.set_image_files_cache(image_id, files_json)
    except Exception as e:
        logger.debug('put_image_layer: Error when caching layer file-tree:'
                     '{0}'.format(e))

    csums.append('sha256:{0}'.format(h.hexdigest()))
    try:
        tmp.seek(0)
        csums.append(checksums.compute_tarsum(tmp, json_data))
    except (IOError, checksums.TarError) as e:
        logger.debug('put_image_layer: Error when computing tarsum '
                     '{0}'.format(e))
    try:
        checksum = store.get_content(store.image_checksum_path(image_id))
    except IOError:
        # We don't have a checksum stored yet, that's fine skipping the check.
        # Not removing the mark though, image is not downloadable yet.
        flask.session['checksum'] = csums
        return toolkit.response()
    # We check if the checksums provided matches one the one we computed
    if checksum not in csums:
        logger.debug('put_image_layer: Wrong checksum')
        return toolkit.api_error('Checksum mismatch, ignoring the layer')

    tmp.close()

    # Checksum is ok, we remove the marker
    store.remove(mark_path)
    return toolkit.response()
开发者ID:adduc,项目名称:docker-registry,代码行数:55,代码来源:images.py


示例4: delete_repository

def delete_repository(namespace, repository):
    """Remove a repository from storage

    This endpoint exists in both the registry API [1] and the indexer
    API [2], but has the same semantics in each instance.  It's in the
    tags module (instead of the index module which handles most
    repository tasks) because it should be available regardless of
    whether the rest of the index-module endpoints are enabled via the
    'standalone' config setting.

    [1]: http://docs.docker.io/en/latest/reference/api/registry_api/#delete--v1-repositories-%28namespace%29-%28repository%29- # nopep8
    [2]: http://docs.docker.io/en/latest/reference/api/index_api/#delete--v1-repositories-%28namespace%29-%28repo_name%29- # nopep8
    """
    logger.debug("[delete_repository] namespace={0}; repository={1}".format(
                 namespace, repository))
    try:
        for tag_name, tag_content in get_tags(
                namespace=namespace, repository=repository):
            delete_tag(
                namespace=namespace, repository=repository, tag=tag_name)
        # TODO(wking): remove images, but may need refcounting
        store.remove(store.repository_path(
            namespace=namespace, repository=repository))
    except OSError:
        return toolkit.api_error('Repository not found', 404)
    else:
        sender = flask.current_app._get_current_object()
        signals.repository_deleted.send(
            sender, namespace=namespace, repository=repository)
    return toolkit.response()
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:30,代码来源:tags.py


示例5: put_image_json

def put_image_json(image_id):
    try:
        data = json.loads(request.data)
    except json.JSONDecodeError:
        pass
    if not data or not isinstance(data, dict):
        return api_error('Invalid JSON')
    for key in ['id']:
        if key not in data:
            return api_error('Missing key `{0}\' in JSON'.format(key))
    # Read the checksum
    checksum = request.headers.get('x-docker-checksum', '')
    if checksum:
        # Storing the checksum is optional at this stage
        err = store_checksum(image_id, checksum)
        if err:
            return api_error(err)
    if image_id != data['id']:
        return api_error('JSON data contains invalid id')
    if check_images_list(image_id) is False:
        return api_error('This image does not belong to the repository')
    parent_id = data.get('parent')
    if parent_id and not store.exists(store.image_json_path(data['parent'])):
        return api_error('Image depends on a non existing parent')
    json_path = store.image_json_path(image_id)
    mark_path = store.image_mark_path(image_id)
    if store.exists(json_path) and not store.exists(mark_path):
        return api_error('Image already exists', 409)
    # If we reach that point, it means that this is a new image or a retry
    # on a failed push
    store.put_content(mark_path, 'true')
    store.put_content(json_path, request.data)
    generate_ancestry(image_id, parent_id)
    return response()
开发者ID:xdissent,项目名称:docker-registry,代码行数:34,代码来源:images.py


示例6: get_repositories

def get_repositories():
    tags = []
    for namespace_path in store.list_directory(store.images):
        for repos_path in store.list_directory(namespace_path):
            for tag in store.list_directory(repos_path):
                tags.append(tag)
    return toolkit.response(tags, 200)
开发者ID:geku,项目名称:docker-registry,代码行数:7,代码来源:index.py


示例7: get_properties

def get_properties(namespace, repo):
    logger.debug("[get_access] namespace={0}; repository={1}".format(namespace,
                 repo))
    is_private = store.is_private(namespace, repo)
    return toolkit.response({
        'access': 'private' if is_private else 'public'
    })
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:7,代码来源:tags.py


示例8: put_image_checksum

def put_image_checksum(image_id):
    if toolkit.DockerVersion() < '0.10':
        checksum = flask.request.headers.get('X-Docker-Checksum')
    else:
        checksum = flask.request.headers.get('X-Docker-Checksum-Payload')
    if not checksum:
        return toolkit.api_error('Missing Image\'s checksum')
    if not flask.session.get('checksum'):
        return toolkit.api_error('Checksum not found in Cookie')
    if not store.exists(store.image_json_path(image_id)):
        return toolkit.api_error('Image not found', 404)
    mark_path = store.image_mark_path(image_id)
    if not store.exists(mark_path):
        return toolkit.api_error('Cannot set this image checksum', 409)
    err = store_checksum(image_id, checksum)
    if err:
        return toolkit.api_error(err)
    if checksum not in flask.session.get('checksum', []):
        logger.debug('put_image_checksum: Wrong checksum. '
                     'Provided: {0}; Expected: {1}'.format(
                         checksum, flask.session.get('checksum')))
        return toolkit.api_error('Checksum mismatch')
    # Checksum is ok, we remove the marker
    store.remove(mark_path)
    # We trigger a task on the diff worker if it's running
    if cache.redis_conn:
        layers.diff_queue.push(image_id)
    return toolkit.response()
开发者ID:jonasfj,项目名称:docker-registry,代码行数:28,代码来源:images.py


示例9: get_tag

def get_tag(namespace, repository, tag):
    data = None
    try:
        data = store.get_content(store.tag_path(namespace, repository, tag))
    except IOError:
        return api_error('Tag not found', 404)
    return response(data)
开发者ID:ehazlett,项目名称:docker-registry,代码行数:7,代码来源:tags.py


示例10: get_image_ancestry

def get_image_ancestry(image_id, headers):
    ancestry_path = store.image_ancestry_path(image_id)
    try:
        data = store.get_content(ancestry_path)
    except IOError:
        return toolkit.api_error('Image not found', 404)
    return toolkit.response(json.loads(data), headers=headers)
开发者ID:jonasfj,项目名称:docker-registry,代码行数:7,代码来源:images.py


示例11: delete_repository

def delete_repository(namespace, repository):
    logger.debug("[delete_repository] namespace={0}; repository={1}".format(namespace, repository))
    try:
        store.remove(store.tag_path(namespace, repository))
    except OSError:
        return api_error("Repository not found", 404)
    return response()
开发者ID:hardiku,项目名称:docker-registry,代码行数:7,代码来源:tags.py


示例12: delete_tag

def delete_tag(namespace, repository, tag):
    logger.debug("[delete_tag] namespace={0}; repository={1}; tag={2}".format(namespace, repository, tag))
    try:
        store.remove(store.tag_path(namespace, repository, tag))
    except OSError:
        return api_error("Tag not found", 404)
    return response()
开发者ID:hardiku,项目名称:docker-registry,代码行数:7,代码来源:tags.py


示例13: put_tag

def put_tag(namespace, repository, tag):
    logger.debug("[put_tag] namespace={0}; repository={1}; tag={2}".format(
                 namespace, repository, tag))
    data = None
    try:
        data = json.loads(flask.request.data)
    except json.JSONDecodeError:
        pass
    if not data or not isinstance(data, basestring):
        return toolkit.api_error('Invalid data')
    if not store.exists(store.image_json_path(data)):
        return toolkit.api_error('Image not found', 404)
    store.put_content(store.tag_path(namespace, repository, tag), data)
    sender = flask.current_app._get_current_object()
    signals.tag_created.send(sender, namespace=namespace,
                             repository=repository, tag=tag, value=data)
    # Write some meta-data about the repos
    ua = flask.request.headers.get('user-agent', '')
    data = create_tag_json(user_agent=ua)
    json_path = store.repository_tag_json_path(namespace, repository, tag)
    store.put_content(json_path, data)
    if tag == "latest":  # TODO(dustinlacewell) : deprecate this for v2
        json_path = store.repository_json_path(namespace, repository)
        store.put_content(json_path, data)
    return toolkit.response()
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:25,代码来源:tags.py


示例14: put_image_layer

def put_image_layer(image_id):
    try:
        json_data = store.get_content(store.image_json_path(image_id))
        checksum = store.get_content(store.image_checksum_path(image_id))
    except IOError:
        return api_error('JSON\'s image not found', 404)
    layer_path = store.image_layer_path(image_id)
    mark_path = store.image_mark_path(image_id)
    if store.exists(layer_path) and not store.exists(mark_path):
        return api_error('Image already exists', 409)
    input_stream = request.stream
    if request.headers.get('transfer-encoding') == 'chunked':
        # Careful, might work only with WSGI servers supporting chunked
        # encoding (Gunicorn)
        input_stream = request.environ['wsgi.input']
    store.stream_write(layer_path, input_stream)
    # FIXME(sam): Compute the checksum while uploading the image to save time
    checksum_parts = checksum.split(':')
    computed_checksum = compute_image_checksum(checksum_parts[0], image_id,
            json_data)
    if computed_checksum != checksum_parts[1].lower():
        logger.debug('put_image_layer: Wrong checksum')
        return api_error('Checksum mismatch, ignoring the layer')
    # Checksum is ok, we remove the marker
    store.remove(mark_path)
    return response()
开发者ID:inthecloud247,项目名称:docker-registry,代码行数:26,代码来源:images.py


示例15: get_tag

def get_tag(namespace, repository, tag):
    logger.debug("[get_tag] namespace={0}; repository={1}; tag={2}".format(namespace, repository, tag))
    data = None
    try:
        data = store.get_content(store.tag_path(namespace, repository, tag))
    except IOError:
        return api_error("Tag not found", 404)
    return response(data)
开发者ID:hardiku,项目名称:docker-registry,代码行数:8,代码来源:tags.py


示例16: get_post_users

def get_post_users():
    if flask.request.method == 'GET':
        return toolkit.response('OK', 200)
    try:
        data = json.loads(flask.request.data)
        if Auth.signin(data):
            return toolkit.response('OK', 200)
        else:
            cfg = config.load()
            if not cfg.allow_signup:
                return toolkit.api_error('Signup is not allowed', 400)
            else:
                if Auth.signup(data):
                    return toolkit.response('User Created', 201)
                else:
                    return toolkit.response('User Not Created', 400)
    except json.JSONDecodeError:
        return toolkit.api_error('Error Decoding JSON', 400)
开发者ID:WhackoJacko,项目名称:docker-registry,代码行数:18,代码来源:index.py


示例17: get_repository_images

def get_repository_images(namespace, repository):
    data = None
    try:
        path = store.index_images_path(namespace, repository)
        data = store.get_content(path)
    except IOError:
        return toolkit.api_error('images not found', 404)
    headers = generate_headers(namespace, repository, 'read')
    return toolkit.response(data, 200, headers, True)
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:9,代码来源:index.py


示例18: delete_repository

def delete_repository(namespace, repository):
    logger.debug("[delete_repository] namespace={0}; repository={1}".format(
                 namespace, repository))
    try:
        store.remove(store.tag_path(namespace, repository))
        #TODO(samalba): Trigger tags_deleted signals
    except OSError:
        return toolkit.api_error('Repository not found', 404)
    return toolkit.response()
开发者ID:23critters,项目名称:docker-registry,代码行数:9,代码来源:tags.py


示例19: get_image_json

def get_image_json(image_id):
    try:
        data = store.get_content(store.image_json_path(image_id))
    except IOError:
        return api_error('Image not found', 404)
    checksum_path = store.image_checksum_path(image_id)
    headers = None
    if store.exists(checksum_path):
        headers = {'X-Docker-Checksum': store.get_content(checksum_path)}
    return response(data, headers=headers, raw=True)
开发者ID:rmoorman,项目名称:docker-registry,代码行数:10,代码来源:images.py


示例20: _get_tags

def _get_tags(namespace, repository):
    logger.debug("[get_tags] namespace={0}; repository={1}".format(namespace,
                 repository))
    try:
        data = {tag_name: tag_content
                for tag_name, tag_content
                in get_tags(namespace=namespace, repository=repository)}
    except OSError:
        return toolkit.api_error('Repository not found', 404)
    return toolkit.response(data)
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:10,代码来源:tags.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python toolkit.toolkit函数代码示例发布时间:2022-05-27
下一篇:
Python toolkit.api_error函数代码示例发布时间: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