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


Python request.path方法代码示例

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


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

示例1: ip_whitelist_add

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def ip_whitelist_add(ip_to_allow, info_record_dict=None):
    """添加ip到白名单, 并写入文件"""
    if ip_to_allow in single_ip_allowed_set:
        return
    dbgprint('ip white added', ip_to_allow, 'info:', info_record_dict)
    single_ip_allowed_set.add(ip_to_allow)
    is_ip_not_in_allow_range.cache_clear()
    append_ip_whitelist_file(ip_to_allow)
    # dbgprint(single_ip_allowed_set)
    try:
        with open(zmirror_root(human_ip_verification_whitelist_log), 'a', encoding='utf-8') as fp:
            fp.write(datetime.now().strftime('%Y-%m-%d %H:%M:%S') + " " + ip_to_allow
                     + " " + str(request.user_agent)
                     + " " + repr(info_record_dict) + "\n")
    except:  # coverage: exclude
        errprint('Unable to write log file', os.path.abspath(human_ip_verification_whitelist_log))
        traceback.print_exc() 
开发者ID:aploium,项目名称:zmirror,代码行数:19,代码来源:zmirror.py

示例2: api_users_login

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def api_users_login():
    # Should just return a binary blob rather than build a "proper" response...
    response = login_response_pb2.LoginResponse()
    response.session_state = 'abc'
    response.info.relay_url = "https://us-or-rly101.zwift.com/relay"
    response.info.apis.todaysplan_url = "https://whats.todaysplan.com.au"
    response.info.apis.trainingpeaks_url = "https://api.trainingpeaks.com"
    response.info.time = int(time.time())
    udp_node = response.info.nodes.node.add()
    if os.path.exists(SERVER_IP_FILE):
        with open(SERVER_IP_FILE, 'r') as f:
            udp_node.ip = f.read().rstrip('\r\n')
    else:
        udp_node.ip = "127.0.0.1"  # TCP telemetry server
    udp_node.port = 3023
    return response.SerializeToString(), 200 
开发者ID:zoffline,项目名称:zwift-offline,代码行数:18,代码来源:zwift_offline.py

示例3: api_profiles_activities_id

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def api_profiles_activities_id(player_id, activity_id):
    if not request.stream:
        return '', 400
    activity_id = int(activity_id) & 0xffffffffffffffff
    activity = activity_pb2.Activity()
    activity.ParseFromString(request.stream.read())
    update_protobuf_in_db('activity', activity, activity_id)

    response = '{"id":%s}' % activity_id
    if request.args.get('upload-to-strava') != 'true':
        return response, 200
    if os.path.exists(ENABLEGHOSTS_FILE):
        urllib2.urlopen("http://cdn.zwift.com/saveghost?%s" % activity.name)
    # Unconditionally *try* and upload to strava and garmin since profile may
    # not be properly linked to strava/garmin (i.e. no 'upload-to-strava' call
    # will occur with these profiles).
    strava_upload(player_id, activity)
    garmin_upload(player_id, activity)
    return response, 200 
开发者ID:zoffline,项目名称:zwift-offline,代码行数:21,代码来源:zwift_offline.py

示例4: list_profiles

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def list_profiles():
    global profiles
    global selected_profile
    del profiles[:]
    for (root, dirs, files) in os.walk(STORAGE_DIR):
        dirs.sort()
        for profile_id in dirs:
            profile = profile_pb2.Profile()
            profile_file = '%s/%s/profile.bin' % (STORAGE_DIR, profile_id)
            if os.path.isfile(profile_file):
                with open(profile_file, 'rb') as fd:
                    profile.ParseFromString(fd.read())
                    # ensure profile.id = directory (in case directory is renamed)
                    profile.id = int(profile_id)
                    profiles.append(profile)
    profile = profile_pb2.Profile()
    if profiles:
        profile.id = profiles[-1].id + 1
        # select first profile for auto launch
        selected_profile = profiles[0].id
    else:
        profile.id = 1000
    profile.first_name = 'New profile'
    profiles.append(profile) 
开发者ID:zoffline,项目名称:zwift-offline,代码行数:26,代码来源:zwift_offline.py

示例5: get

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def get(self):
        wrok = Work.query.all()
        projects = Project.query.filter_by(status=False).all()
        if current_user.is_sper == True:
            pagination = (User.query.order_by('-id').all())
        else:
            pagination = []
            id = []
            for projec in current_user.quanxians:
                if (projec.user.all() in id) is False:
                    pagination.append(projec.user.all())
                    id.append(projec.user.all())
            pagination = (hebinglist(pagination))
        pager_obj = Pagination(request.args.get("page", 1), len(pagination), request.path, request.args,
                               per_page_count=PageShow)
        index_list = pagination[pager_obj.start:pager_obj.end]
        html = pager_obj.page_html()
        return render_template('home/useradmin.html', users=index_list, html=html, wroks=wrok, projects=projects) 
开发者ID:liwanlei,项目名称:FXTest,代码行数:20,代码来源:views.py

示例6: default_unauthz_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def default_unauthz_handler(func, params):
    unauthz_message, unauthz_message_type = get_message("UNAUTHORIZED")
    if _security._want_json(request):
        payload = json_error_response(errors=unauthz_message)
        return _security._render_json(payload, 403, None, None)
    view = config_value("UNAUTHORIZED_VIEW")
    if view:
        if callable(view):
            view = view()
        else:
            try:
                view = get_url(view)
            except BuildError:
                view = None
        do_flash(unauthz_message, unauthz_message_type)
        redirect_to = "/"
        if request.referrer and not request.referrer.split("?")[0].endswith(
            request.path
        ):
            redirect_to = request.referrer

        return redirect(view or redirect_to)
    abort(403) 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:25,代码来源:decorators.py

示例7: generate_http_response

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def generate_http_response(req, conf):
	""" Generate HTTP response """

	args = ["{}={}".format(key, value) for key, value in request.args.items()]
	path = req.path
	con_type = None
	body_path = None
	if path in conf['traps']:
		# Check if the token is defined and has a custom http response
		for token in args:
			if (token in conf['traps'][path]) and ("token-response" in conf['traps'][path][token]):
				con_type = conf['traps'][path][token]['token-response']['content-type']
				body_path = conf['traps'][path][token]['token-response']['body']
		# if the 'body_path' is still empty, use the trap/uri response (if there's any)
		if ("trap-response" in conf['traps'][path]) and body_path is None:
			con_type = conf['traps'][path]['trap-response']['content-type']
			body_path = conf['traps'][path]['trap-response']['body']
	# Load the default HTTP response if the 'body_path' is None
	if body_path is None:
		con_type = conf['default-http-response']['content-type']
		body_path = conf['default-http-response']['body']

	return con_type, body_path 
开发者ID:0x4D31,项目名称:honeyku,代码行数:25,代码来源:honeyku.py

示例8: security

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def security(role=None):
    def decorator(f):
        @wraps(f)
        def _decorator(*args, **kw):
            me = g.user
            if me.is_guest() and request.path != 'admin/login':
                return redirect(url_for('admin.login'))
            access = False
            if me.is_root():
                access = True
            elif me.inactive():
                access = False
            elif me.role == role:
                access = True
            elif me.is_admin and role in (User.EDITOR, None):
                access = True

            if access:
                return f(*args, **kw)
            else:
                return render_template('admin/403.html')
        return _decorator
    return decorator 
开发者ID:whiteclover,项目名称:white,代码行数:25,代码来源:security.py

示例9: log_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def log_request(logger):
    '''
    wrapper function for HTTP request logging
    '''
    def real_decorator(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            """ Look at the request, and log the details """
            # logger.info("{}".format(request.url))
            logger.debug("Request received, content-type :"
                         "{}".format(request.content_type))
            if request.content_type == 'application/json':
                sfx = ", parms={}".format(request.get_json())
            else:
                sfx = ''
            logger.info("{} - {} {}{}".format(request.remote_addr,
                                              request.method,
                                              request.path,
                                              sfx))
            return f(*args, **kwargs)
        return wrapper

    return real_decorator 
开发者ID:ansible,项目名称:ansible-runner-service,代码行数:25,代码来源:utils.py

示例10: log_exception

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def log_exception(self, exc_info):
        self.logger.error("""
Path:                 %s
HTTP Method:          %s
Client IP Address:    %s
User Agent:           %s
User Platform:        %s
User Browser:         %s
User Browser Version: %s
GET args:             %s
view args:            %s
URL:                  %s
""" % (
            request.path,
            request.method,
            request.remote_addr,
            request.user_agent.string,
            request.user_agent.platform,
            request.user_agent.browser,
            request.user_agent.version,
            dict(request.args),
            request.view_args,
            request.url
        ), exc_info=exc_info) 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:26,代码来源:__init__.py

示例11: log_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def log_request(code='-'):
    proto = request.environ.get('SERVER_PROTOCOL')
    msg = request.method + ' ' + request.path + ' ' + proto
    code = str(code)

    if code[0] == '1':    # 1xx - Informational
        msg = color(msg, attrs=['bold'])
    if code[0] == '2':    # 2xx - Success
        msg = color(msg, color='white')
    elif code == '304':   # 304 - Resource Not Modified
        msg = color(msg, color='cyan')
    elif code[0] == '3':  # 3xx - Redirection
        msg = color(msg, color='green')
    elif code == '404':   # 404 - Resource Not Found
        msg = color(msg, color='yellow')
    elif code[0] == '4':  # 4xx - Client Error
        msg = color(msg, color='red', attrs=['bold'])
    else:                 # 5xx, or any other response
        msg = color(msg, color='magenta', attrs=['bold'])

    logger.info('%s - - [%s] "%s" %s', request.remote_addr, log_date_time_string(), msg, code) 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:23,代码来源:autoapp.py

示例12: setup_authentication

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def setup_authentication(app):
    oauth = OAuth(app)

    def handle_redirects(remote, token, user_info):
        if 'hd' in user_info:
            if user_info['hd'] == app.config['OAUTH_DOMAIN'] \
                    or (isinstance(app.config['OAUTH_DOMAIN'], List) and user_info['hd'] in app.config['OAUTH_DOMAIN']):

                session['user'] = user_info
                return redirect(session.get('next', '/'))

        return redirect(url_for('page.login'))


    def ensure_user_is_authorized(app):
        if 'user' not in session and request.path not in ['/oauth/login', '/oauth/auth', '/login', '/healthcheck'] and not request.path.startswith('/static/'):
            session['next'] = request.url
            return redirect(url_for('page.login'))

    app.register_blueprint(
        create_flask_blueprint(Google, oauth, handle_redirects),
        url_prefix='/oauth')

    app.before_request(lambda: ensure_user_is_authorized(app)) 
开发者ID:Wikia,项目名称:discreETLy,代码行数:26,代码来源:app.py

示例13: test_terraformize_endpoint_apply_missing_module

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def test_terraformize_endpoint_apply_missing_module(self):
        configuration["terraform_modules_path"] = test_files_location
        configuration["terraform_binary_path"] = test_bin_location
        expected_body = {
            'error': "[Errno 2] No such file or directory: '" +
                     test_files_location + "/fake_test_module'"
        }
        with app.test_request_context('/v1/fake_test_module/test_workspace', method='POST'):
            self.assertEqual(request.path, '/v1/fake_test_module/test_workspace')
            return_body, terraform_return_code = apply_terraform("fake_test_module", "test_workspace")
            self.assertEqual(terraform_return_code, 404)
            self.assertEqual(return_body.json, expected_body) 
开发者ID:naorlivne,项目名称:terraformize,代码行数:14,代码来源:test_terraformize_endpoint.py

示例14: test_terraformize_endpoint_destroy_missing_module

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def test_terraformize_endpoint_destroy_missing_module(self):
        configuration["terraform_modules_path"] = test_files_location
        configuration["terraform_binary_path"] = test_bin_location
        expected_body = {
            'error': "[Errno 2] No such file or directory: '" +
                     test_files_location + "/fake_test_module'"
        }
        with app.test_request_context('/v1/fake_test_module/test_workspace', method='DELETE'):
            self.assertEqual(request.path, '/v1/fake_test_module/test_workspace')
            return_body, terraform_return_code = destroy_terraform("fake_test_module", "test_workspace")
            self.assertEqual(terraform_return_code, 404)
            self.assertEqual(return_body.json, expected_body) 
开发者ID:naorlivne,项目名称:terraformize,代码行数:14,代码来源:test_terraformize_endpoint.py

示例15: test_terraformize_endpoint_apply_run

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import path [as 别名]
def test_terraformize_endpoint_apply_run(self):
        configuration["terraform_modules_path"] = test_files_location
        configuration["terraform_binary_path"] = test_bin_location
        with app.test_request_context('/v1/working_test/test_workspace', method='POST'):
            self.assertEqual(request.path, '/v1/working_test/test_workspace')
            return_body, terraform_return_code = apply_terraform("working_test", "test_workspace")
            self.assertEqual(terraform_return_code, 200) 
开发者ID:naorlivne,项目名称:terraformize,代码行数:9,代码来源:test_terraformize_endpoint.py


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