Python flask.request.url_rule() Examples
The following are 8
code examples of flask.request.url_rule().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.request
, or try the search function
.
Example #1
Source File: flask_profiler.py From flask-profiler with MIT License | 7 votes |
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
Example #2
Source File: __init__.py From apm-agent-python with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #3
Source File: flask.py From dodotable with MIT License | 5 votes |
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]
Example #4
Source File: user_oauth.py From gitmostwanted.com with MIT License | 5 votes |
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
Example #5
Source File: main.py From PyRecognizer with MIT License | 5 votes |
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)
Example #6
Source File: __init__.py From ok with Apache License 2.0 | 5 votes |
def __init__(self): self.endpoint = request.url_rule and request.url_rule.endpoint self.lines = []
Example #7
Source File: webapi.py From WebWhatsapp-Wrapper with MIT License | 4 votes |
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)
Example #8
Source File: casbin_enforcer.py From flask-authz with Apache License 2.0 | 4 votes |
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