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


Python flask.abort方法代码示例

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


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

示例1: get_attack

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def get_attack(pid, aid):
    """
    Get list of all the hosts possibly vulnerable to the attack.
    """
    project = get_project_db(pid)
    db = database.ScanDatabase(project['dbfile'])

    if flask.request.method == 'POST':
        note = flask.request.form['note']
        db.attackdb.update_attack_note(aid, note)

    attack = db.attackdb.get_attack(aid)

    if attack is None:
        flask.abort(404)

    items = [i.split(':') for i in attack['items'].split(',')]

    return flask.render_template('attack.html', pid=pid, attack=attack,
                items=items, name=project['name']) 
开发者ID:averagesecurityguy,项目名称:ptnotes,代码行数:22,代码来源:webserver.py

示例2: submit_story

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def submit_story():
    if request.method == "POST":
        params = request.get_json()
        title, url = params['title'].strip(), params['url'].strip()
        text = params.get('text', "").strip()
        if not title:
            return abort(400, "You have to provide a 'title'")

        if url:
            link = Link(title=title, url=url, owner_id=current_user.id)
            db.session.add(link)
            db.session.commit()
            return link_schema.dump(link)
        elif text:
            topic = Topic(title=title, text=text, owner_id=current_user.id)
            db.session.add(topic)
            db.session.commit()
            return topic_schema.dump(topic)

        return abort(400, "You have to provide either 'url' or 'text', too")

    # Just render it
    return {} 
开发者ID:beavyHQ,项目名称:beavy,代码行数:25,代码来源:views.py

示例3: api_only

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def api_only(fn):
    @wraps(fn)
    def wrapped(*args, **kwargs):
        accepted = set(request.accept_mimetypes.values())
        explicit = not(not request.args.get("json", False))
        if not (accepted & API_MIMETYPES) and not explicit:
            return abort(415, "Unsupported Media Type")

        resp = fn(*args, **kwargs)
        if not isinstance(resp, ResponseBase):
            data, code, headers = unpack(resp)
            # we've found one, return json
            if isinstance(data, MarshalResult):
                data = data.data
            resp = make_response(json.dumps(data,
                                            indent=explicit and 4 or 0),
                                 code)

            if headers:
                resp.headers.update(headers)
            resp.headers["Content-Type"] = 'application/json'
        return resp
    return wrapped 
开发者ID:beavyHQ,项目名称:beavy,代码行数:25,代码来源:__init__.py

示例4: hcard

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def hcard(guid):
    if guid != app.config.get("RELAY_GUID"):
        return abort(404)
    hcard = generate_hcard(
        "diaspora",
        hostname=app.config.get("SERVER_HOST"),
        fullname=app.config.get("RELAY_NAME"),
        firstname=app.config.get("RELAY_NAME"),
        lastname="",
        photo300="",
        photo100="",
        photo50="",
        searchable="false",
        guid=app.config.get("RELAY_GUID"),
        public_key=app.config.get("RELAY_PUBLIC_KEY"),
        username=app.config.get("RELAY_USERNAME"),
    )
    return Response(hcard, status=200) 
开发者ID:jaywink,项目名称:social-relay,代码行数:20,代码来源:views.py

示例5: receive_public

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def receive_public():
    if not request.data:
        return abort(404)

    # Queue to rq for processing
    public_queue.enqueue("workers.receive.process", request.data, timeout=app.config.get("RELAY_WORKER_TIMEOUT"))

    # Log statistics
    log_receive_statistics(request.remote_addr)

    # return 200 whatever
    data = {
        'result': 'ok',
    }
    js = json.dumps(data)
    return Response(js, status=200, mimetype='application/json') 
开发者ID:jaywink,项目名称:social-relay,代码行数:18,代码来源:views.py

示例6: create_app

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def create_app(config):
    """
    创建app
    """
    # 添加配置
    app.config.from_object(config)
    # 解决跨域
    app.after_request(_access_control)
    # 自定义abort 400 响应数据格式
    flask_restful.abort = _custom_abort
    # 数据库初始化
    db.init_app(app)
    # 注册蓝图
    from routes import api_v1
    app.register_blueprint(api_v1, url_prefix='/api/v1')
    # 使用flask原生异常处理程序
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception
    return app 
开发者ID:lalala223,项目名称:flask-restful-example,代码行数:21,代码来源:app.py

示例7: get

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def get(id):
        id = hash_ids.decode(id)
        if not id: abort(404)

        try:
            profile = ProfilesModel.query.get(id[0])
            if not profile: abort(404)
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            db.session.rollback()
            return pretty_result(code.DB_ERROR, '数据库错误!')
        else:
            item = {
                'id': hash_ids.encode(profile.id),
                'nickname': profile.nickname,
                'signature': profile.signature
            }
            return pretty_result(code.OK, data=item) 
开发者ID:lalala223,项目名称:flask-restful-example,代码行数:20,代码来源:profiles.py

示例8: put

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def put(self, id):
        self.parser.add_argument("nickname", type=str, location="json", required=True)
        self.parser.add_argument("signature", type=str, location="json", required=True)
        args = self.parser.parse_args()

        id = hash_ids.decode(id)
        if not id: abort(404)

        try:
            profile = ProfilesModel.query.get(id[0])
            if not profile: abort(404)

            profile.nickname = args.nickname
            profile.signature = args.signature

            db.session.add(profile)
            db.session.commit()
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            db.session.rollback()
            return pretty_result(code.DB_ERROR, '数据库错误!')
        else:
            return pretty_result(code.OK) 
开发者ID:lalala223,项目名称:flask-restful-example,代码行数:25,代码来源:profiles.py

示例9: delete

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def delete(id):
        id = hash_ids.decode(id)
        if not id: abort(404)

        try:
            profile = ProfilesModel.query.get(id[0])
            if not profile: abort(404)

            db.session.delete(profile)
            db.session.commit()
        except SQLAlchemyError as e:
            current_app.logger.error(e)
            db.session.rollback()
            return pretty_result(code.DB_ERROR, '数据库错误!')
        else:
            return pretty_result(code.OK) 
开发者ID:lalala223,项目名称:flask-restful-example,代码行数:18,代码来源:profiles.py

示例10: has_pr_enabled

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def has_pr_enabled(function):
    """
    Decorator that checks if the current pagure project has the
    issue tracker active or has PRs function active
    If not active returns a 404 page
    """

    @wraps(function)
    def check_trackers(*args, **kwargs):
        repo = flask.g.repo
        if not repo.settings.get("pull_requests", True):
            flask.abort(
                404,
                description="Pull Requests are not enabled on this project",
            )

        return function(*args, **kwargs)

    return check_trackers 
开发者ID:Pagure,项目名称:pagure,代码行数:21,代码来源:decorators.py

示例11: is_repo_admin

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def is_repo_admin(function):
    """
    Decorator that checks if the current user is the admin of
    the project.
    If not active returns a 403 page
    """

    @wraps(function)
    def check_repo_admin(*args, **kwargs):
        if not flask.g.repo_admin:
            flask.abort(
                403,
                description="You are not allowed to change the "
                "settings for this project",
            )
        return function(*args, **kwargs)

    return check_repo_admin 
开发者ID:Pagure,项目名称:pagure,代码行数:20,代码来源:decorators.py

示例12: view_user_issues

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def view_user_issues(username):
    """
    Shows the issues created or assigned to the specified user.

    :param username: The username to retrieve the issues for
    :type  username: str
    """

    if not pagure_config.get("ENABLE_TICKETS", True):
        flask.abort(
            404,
            description="Tickets have been disabled on this pagure instance",
        )

    user = _get_user(username=username)
    userprofile_common = get_userprofile_common(user)

    return flask.render_template(
        "userprofile_issues.html",
        username=username,
        user=user,
        repos_length=userprofile_common["repos_length"],
        forks_length=userprofile_common["forks_length"],
        select="issues",
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:27,代码来源:app.py

示例13: view_docs

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def view_docs(repo, username=None, filename=None, namespace=None):
    """ Display the documentation
    """
    repo = flask.g.repo

    if not pagure_config.get("DOC_APP_URL"):
        flask.abort(404, description="This pagure instance has no doc server")

    return flask.render_template(
        "docs.html",
        select="docs",
        repo=repo,
        username=username,
        filename=filename,
        endpoint="view_docs",
    ) 
开发者ID:Pagure,项目名称:pagure,代码行数:18,代码来源:repo.py

示例14: admin_test

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def admin_test(test=None):
  if test and test not in TESTS:
    flask.abort(404)
  form = TestForm()
  if form.validate_on_submit():
    pass

  return flask.render_template(
    'admin/test/test_one.html' if test else 'admin/test/test.html',
    title='Test: %s' % test.title() if test else 'Test',
    html_class='test',
    form=form,
    test=test,
    tests=TESTS,
    versions=versions.get_versions(),
    back_url_for='admin_test' if test else None,
  ) 
开发者ID:lipis,项目名称:github-stats,代码行数:19,代码来源:test.py

示例15: gh_admin_top

# 需要导入模块: import flask [as 别名]
# 或者: from flask import abort [as 别名]
def gh_admin_top():
  stars = util.param('stars', int) or 10000
  page = util.param('page', int) or 1
  per_page = util.param('per_page', int) or 100
  # TODO: fix formatting
  result = urlfetch.fetch('https://api.github.com/search/repositories?q=stars:>=%s&sort=stars&order=asc&page=%d&per_page=%d' % (stars, page, per_page))
  if result.status_code == 200:
    repos = json.loads(result.content)
  else:
    flask.abort(result.status_code)

  for repo in repos['items']:
    account = repo['owner']
    account_db = model.Account.get_or_insert(
      account['login'],
      avatar_url=account['avatar_url'].split('?')[0],
      email=account['email'] if 'email' in account else '',
      name=account['login'],
      followers=account['followers'] if 'followers' in account else 0,
      organization=account['type'] == 'Organization',
      username=account['login'],
    )

  return 'OK %d of %d' % (len(repos['items']), repos['total_count']) 
开发者ID:lipis,项目名称:github-stats,代码行数:26,代码来源:gh.py


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