python类endpoint()的实例源码

utils.py 文件源码 项目:flask_workshop 作者: cursodepythonoficial 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def build_menu_item(endpoint, name):
    is_active = "active" if request.endpoint == endpoint else ""
    return Markup(
        f'<li class="nav-item {is_active}">'
        f'<a class="nav-link" href="{url_for(endpoint)}">{name}</a>'
        f'</li>'
    )
utils.py 文件源码 项目:flask_workshop 作者: cursodepythonoficial 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def build_menu_item_as_filter(endpoint):
    is_active = "active" if request.endpoint == endpoint else ""
    return Markup(
        f'<li class="nav-item {is_active}">'
        f'<a class="nav-link" href="{url_for(endpoint)}">{endpoint.upper()}</a>'
        f'</li>'
    )
pager.py 文件源码 项目:osm-wikidata 作者: EdwardBetts 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def url_for_other_page(page):
    args = request.view_args.copy()
    args.update(request.args)
    args['page'] = page
    return url_for(request.endpoint, **args)
view.py 文件源码 项目:osm-wikidata 作者: EdwardBetts 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def navbar():
    try:
        return dict(navbar_pages=navbar_pages,
                    active=request.endpoint)
    except RuntimeError:
        return {}  # maybe we don't care
view.py 文件源码 项目:osm-wikidata 作者: EdwardBetts 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def sort_link(order):
    args = request.view_args.copy()
    args['sort'] = order
    return url_for(request.endpoint, **args)
shared.py 文件源码 项目:oclubs 作者: SHSIDers 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def url_for_other_page(page):
    args = request.view_args.copy()
    args.update(request.args)
    args['page'] = page
    return url_for(request.endpoint, **args)
views.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
report.py 文件源码 项目:python-ares 作者: pynog 项目源码 文件源码 阅读 43 收藏 0 点赞 0 评论 0
def ask_login():
  if not current_user.is_anonymous:
    return

  if getattr(current_app.view_functions[request.endpoint], 'no_login', False):
    return

  return redirect(url_for('ares.aresLogin', next=request.endpoint))
administration.py 文件源码 项目:python-ares 作者: pynog 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def ask_login():
  if not current_user.is_anonymous:
    return

  if getattr(current_app.view_functions[request.endpoint], 'no_login', False):
    return

  return redirect(url_for('ares.aresLogin', next=request.endpoint))
manage.py 文件源码 项目:Plog 作者: thundernet8 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def app_after_request(response):
    if request.endpoint != 'static':
        return response
    response.cache_control.max_age = 15552000
    return response


# jinja_env
middleware.py 文件源码 项目:dd-trace-py 作者: DataDog 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _finish_span(self, response=None, exception=None):
        """ Close and finish the active span if it exists. """
        span = getattr(g, 'flask_datadog_span', None)
        if span:
            if span.sampled:
                error = 0
                code = response.status_code if response else None
                method = request.method if request else None

                # if we didn't get a response, but we did get an exception, set
                # codes accordingly.
                if not response and exception:
                    code = 500
                    # The 3 next lines might not be strictly required, since `set_traceback`
                    # also get the exception from the sys.exc_info (and fill the error meta).
                    # Since we aren't sure it always work/for insuring no BC break, keep
                    # these lines which get overridden anyway.
                    error = 1
                    span.set_tag(errors.ERROR_TYPE, type(exception))
                    span.set_tag(errors.ERROR_MSG, exception)
                    # The provided `exception` object doesn't have a stack trace attached,
                    # so attach the stack trace with `set_traceback`.
                    span.set_traceback()

                # the endpoint that matched the request is None if an exception
                # happened so we fallback to a common resource
                resource = code if not request.endpoint else request.endpoint
                span.resource = compat.to_unicode(resource).lower()
                span.set_tag(http.URL, compat.to_unicode(request.base_url or ''))
                span.set_tag(http.STATUS_CODE, code)
                span.set_tag(http.METHOD, method)
                span.error = error
            span.finish()
            # Clear our span just in case.
            g.flask_datadog_span = None

    # Request hook methods
auth.py 文件源码 项目:fanclley 作者: guerbai 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def before_request():
    if  current_user.is_authenticated\
        and not current_user.confirmed \
        and request.endpoint[:5] != 'auth.' \
        and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
test_extension.py 文件源码 项目:flask-bitmapist 作者: cuttlesoft 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_index(app, bitmap, client):
    with app.test_request_context('/bitmapist/'):
        assert request.endpoint == 'bitmapist.index'
test_extension.py 文件源码 项目:flask-bitmapist 作者: cuttlesoft 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_cohort(app, bitmap, client):
    with app.test_request_context('/bitmapist/cohort'):
        assert request.endpoint == 'bitmapist.cohort'
__init__.py 文件源码 项目:fallball-connector 作者: ingrammicro 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def allow_public_endpoints_only():
    public_endpoints = (HealthCheck.__name__.lower(),)
    if g.endpoint not in public_endpoints:
        abort(401)
__init__.py 文件源码 项目:fallball-connector 作者: ingrammicro 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def set_name_for_reseller(reseller_id):
    if not reseller_id:
        return None
    if g.endpoint == ApplicationList.__name__.lower():
        return generate_reseller_name()

    return get_reseller_name(reseller_id)
__init__.py 文件源码 项目:fallball-connector 作者: ingrammicro 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_reseller_info():
    reseller_id = request.headers.get('Aps-Instance-Id')
    is_new = g.endpoint == ApplicationList.__name__.lower()
    reseller_name = set_name_for_reseller(reseller_id)
    oauth = get_oauth()
    return ResellerInfo(id=reseller_id, name=reseller_name, is_new=is_new, auth=oauth)
__init__.py 文件源码 项目:fallball-connector 作者: ingrammicro 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def before_request():
    g.log = dict()
    g.log['out'] = list()
    g.log['request'] = log_request(request)

    g.endpoint = request.endpoint
    if request.blueprint:
        g.endpoint = g.endpoint[len(request.blueprint):].lstrip('.')

    reseller_info = get_reseller_info()
    g.reseller_name = reseller_info.name
    g.company_name = 'N/A'

    if not reseller_info.name:
        allow_public_endpoints_only()
        return

    if not check_oauth_signature(request):
        abort(401)

    g.auth = reseller_info.auth

    g.reseller = Reseller(reseller_info.name, reseller_info.id, None)
    g.reseller.refresh()

    if not g.reseller.token and not reseller_info.is_new:
        abort(403)


问题


面经


文章

微信
公众号

扫码关注公众号