Python flask.request._get_current_object() Examples
The following are 5
code examples of flask.request._get_current_object().
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_sqlalchemy.py From nplusone with MIT License | 5 votes |
def get_worker(): try: return request._get_current_object() except RuntimeError: return None
Example #2
Source File: middleware.py From aws-xray-sdk-python with Apache License 2.0 | 5 votes |
def _before_request(self): headers = request.headers xray_header = construct_xray_header(headers) req = request._get_current_object() name = calculate_segment_name(req.host, self._recorder) sampling_req = { 'host': req.host, 'method': req.method, 'path': req.path, 'service': name, } sampling_decision = calculate_sampling_decision( trace_header=xray_header, recorder=self._recorder, sampling_req=sampling_req, ) if self.in_lambda_ctx: segment = self._recorder.begin_subsegment(name) else: segment = self._recorder.begin_segment( name=name, traceid=xray_header.root, parent_id=xray_header.parent, sampling=sampling_decision, ) segment.save_origin_trace_header(xray_header) segment.put_http_meta(http.URL, req.base_url) segment.put_http_meta(http.METHOD, req.method) segment.put_http_meta(http.USER_AGENT, headers.get('User-Agent')) client_ip = headers.get('X-Forwarded-For') or headers.get('HTTP_X_FORWARDED_FOR') if client_ip: segment.put_http_meta(http.CLIENT_IP, client_ip) segment.put_http_meta(http.X_FORWARDED_FOR, True) else: segment.put_http_meta(http.CLIENT_IP, req.remote_addr)
Example #3
Source File: nplusone.py From zeus with Apache License 2.0 | 5 votes |
def get_worker(): try: return request._get_current_object() except RuntimeError: return None
Example #4
Source File: flask.py From dodotable with MIT License | 5 votes |
def get_session(self): ctx = request._get_current_object() try: session = ctx._current_session except AttributeError: return None else: return session
Example #5
Source File: __init__.py From build-relengapi with Mozilla Public License 2.0 | 5 votes |
def is_browser(): """Is the current request from a browser?""" # all subrequests are not from browsers if hasattr(request._get_current_object(), 'is_subrequest') and request.is_subrequest: return False best_match = request.accept_mimetypes.best_match(_mime_types) return best_match == 'text/html'