當前位置: 首頁>>代碼示例>>Python>>正文


Python request.url_rule方法代碼示例

本文整理匯總了Python中flask.request.url_rule方法的典型用法代碼示例。如果您正苦於以下問題:Python request.url_rule方法的具體用法?Python request.url_rule怎麽用?Python request.url_rule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.request的用法示例。


在下文中一共展示了request.url_rule方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: wrapHttpEndpoint

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def wrapHttpEndpoint(f):
    @functools.wraps(f)
    def wrapper(*args, **kwargs):
        context = {
            "url": request.base_url,
            "args": dict(request.args.items()),
            "form": dict(request.form.items()),
            "body": request.data.decode("utf-8", "strict"),
            "headers": dict(request.headers.items()),
            "func": request.endpoint,
            "ip": request.remote_addr
        }
        endpoint_name = str(request.url_rule)
        wrapped = measure(f, endpoint_name, request.method, context)
        return wrapped(*args, **kwargs)

    return wrapper 
開發者ID:muatik,項目名稱:flask-profiler,代碼行數:19,代碼來源:flask_profiler.py

示例2: request_started

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def request_started(self, app):
        if not self.app.debug or self.client.config.debug:
            trace_parent = TraceParent.from_headers(request.headers)
            self.client.begin_transaction("request", trace_parent=trace_parent)
            elasticapm.set_context(
                lambda: get_data_from_request(request, self.client.config, constants.TRANSACTION), "request"
            )
            rule = request.url_rule.rule if request.url_rule is not None else ""
            rule = build_name_with_http_method_prefix(rule, request)
            elasticapm.set_transaction_name(rule, override=False) 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:12,代碼來源:__init__.py

示例3: build_url

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def build_url(self, **kwargs):
        arg = request.args.copy()
        view_args = request.view_args
        arg.update(view_args)
        for attr in kwargs.keys():
            if attr in arg:
                arg.pop(attr)
        arg.update(kwargs.items())
        rule = request.url_rule
        result = rule.build({k: v for k, v in arg.items()})
        return result[1] 
開發者ID:spoqa,項目名稱:dodotable,代碼行數:13,代碼來源:flask.py

示例4: load_user_from_session

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def load_user_from_session():
    if str(request.url_rule) in ['/logout']:
        return None
    g.user = User.query.get(session['user_id']) if 'user_id' in session else None


# @todo #2:15min move after_request method to a general place or a middleware 
開發者ID:kkamkou,項目名稱:gitmostwanted.com,代碼行數:9,代碼來源:user_oauth.py

示例5: csrf_protect

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def csrf_protect():
    """
    Validate csrf token against the one in session
    :return:
    """
    if ENABLE_CSRF:
        if "dashboard" not in str(request.url_rule):
            if request.method == "POST":
                token = session.pop('_csrf_token', None)
                if not token or token != request.form.get('_csrf_token'):
                    abort(403) 
開發者ID:alessiosavi,項目名稱:PyRecognizer,代碼行數:13,代碼來源:main.py

示例6: __init__

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def __init__(self):
        self.endpoint = request.url_rule and request.url_rule.endpoint
        self.lines = [] 
開發者ID:okpy,項目名稱:ok,代碼行數:5,代碼來源:__init__.py

示例7: before_request

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def before_request():
    """This runs before every API request. The function take cares of creating
    driver object is not already created. Also it checks for few prerequisits
    parameters and set global variables for other functions to use
    
    Required paramters for an API hit are:
    auth-key: key string to identify valid request
    client_id: to identify for which client the request is to be run
    """
    global logger

    if not request.url_rule:
        abort(404)

    if logger == None:
        create_logger()
    logger.info("API call " + request.method + " " + request.url)

    auth_key = request.headers.get("auth-key")
    g.client_id = request.headers.get("client_id")
    rule_parent = request.url_rule.rule.split("/")[1]

    if API_KEY and auth_key != API_KEY:
        abort(401, "you must send valid auth-key")
        raise Exception()

    if not g.client_id and rule_parent != "admin":
        abort(400, "client ID is mandatory")

    acquire_semaphore(g.client_id)

    # Create a driver object if not exist for client requests.
    if rule_parent != "admin":
        if g.client_id not in drivers:
            drivers[g.client_id] = init_client(g.client_id)

        g.driver = drivers[g.client_id]
        g.driver_status = WhatsAPIDriverStatus.Unknown

        if g.driver is not None:
            g.driver_status = g.driver.get_status()

        # If driver status is unkown, means driver has closed somehow, reopen it
        if (
            g.driver_status != WhatsAPIDriverStatus.NotLoggedIn
            and g.driver_status != WhatsAPIDriverStatus.LoggedIn
        ):
            drivers[g.client_id] = init_client(g.client_id)
            g.driver_status = g.driver.get_status()

        init_timer(g.client_id) 
開發者ID:mukulhase,項目名稱:WebWhatsapp-Wrapper,代碼行數:53,代碼來源:webapi.py

示例8: enforcer

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import url_rule [as 別名]
def enforcer(self, func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            if self.e.watcher and self.e.watcher.should_reload():
                self.e.watcher.update_callback()
            # Check sub, obj act against Casbin polices
            self.app.logger.debug(
                "Enforce Headers Config: %s\nRequest Headers: %s"
                % (self.app.config.get("CASBIN_OWNER_HEADERS"), request.headers)
            )
            for header in self.app.config.get("CASBIN_OWNER_HEADERS"):
                if header in request.headers:
                    # Make Authorization Header Parser standard
                    if header == "Authorization":
                        # Get Auth Value then decode and parse for owner
                        try:
                            owner = authorization_decoder(request.headers.get(header))
                        except UnSupportedAuthType:
                            # Continue if catch unsupported type in the event of
                            # Other headers needing to be checked
                            self.app.logger.info(
                                "Authorization header type requested for "
                                "decoding is unsupported by flask-casbin at this time"
                            )
                            continue
                        if self.e.enforce(owner, str(request.url_rule), request.method):
                            return func(*args, **kwargs)
                    else:
                        # Split header by ',' in case of groups when groups are
                        # sent "group1,group2,group3,..." in the header
                        for owner in self.sanitize_group_headers(
                            request.headers.get(header)
                        ):
                            self.app.logger.debug(
                                "Enforce against owner: %s header: %s"
                                % (owner.strip('"'), header)
                            )
                            if self.e.enforce(
                                owner.strip('"'), str(request.url_rule), request.method
                            ):
                                return func(*args, **kwargs)
            else:
                return (jsonify({"message": "Unauthorized"}), 401)

        return wrapper 
開發者ID:pycasbin,項目名稱:flask-authz,代碼行數:47,代碼來源:casbin_enforcer.py


注:本文中的flask.request.url_rule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。