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


Python request.host方法代码示例

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


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

示例1: protect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def protect(self):
        if request.method not in self._app.config['WTF_CSRF_METHODS']:
            return

        if not validate_csrf(self._get_csrf_token()):
            reason = 'CSRF token missing or incorrect.'
            return self._error_response(reason)

        if request.is_secure and self._app.config['WTF_CSRF_SSL_STRICT']:
            if not request.referrer:
                reason = 'Referrer checking failed - no Referrer.'
                return self._error_response(reason)

            good_referrer = 'https://%s/' % request.host
            if not same_origin(request.referrer, good_referrer):
                reason = 'Referrer checking failed - origin does not match.'
                return self._error_response(reason)

        request.csrf_valid = True  # mark this request is csrf valid 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:csrf.py

示例2: protect

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def protect(self):
        if request.method not in current_app.config['WTF_CSRF_METHODS']:
            return

        try:
            validate_csrf(self._get_csrf_token())
        except ValidationError as e:
            logger.info(e.args[0])
            self._error_response(e.args[0])

        if request.is_secure and current_app.config['WTF_CSRF_SSL_STRICT']:
            if not request.referrer:
                self._error_response('The referrer header is missing.')

            good_referrer = 'https://{0}/'.format(request.host)

            if not same_origin(request.referrer, good_referrer):
                self._error_response('The referrer does not match the host.')

        g.csrf_valid = True  # mark this request as CSRF valid 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:22,代码来源:csrf.py

示例3: get_config

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def get_config(self, host):
        if self._config_path:
            assert Path(self._config_path).is_file()

            with open(self._config_path, 'rb') as config_file:
                config = self._load_config(config_file.read())

        elif self._config_url:
            with urllib.request.urlopen(self._config_url) as config_file:
                config = self._load_config(config_file.read())

        if StrictVersion(config.get('openapi', '2.0.0')) >= StrictVersion('3.0.0'):
            for server in config['servers']:
                server['url'] = re.sub(r'//[a-z0-9\-\.:]+/?', '//{}/'.format(host), server['url'])
        elif 'host' not in config:
            config['host'] = host
        return config 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:19,代码来源:core.py

示例4: _aiohttp_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _aiohttp_handler(self):
        from aiohttp import web

        async def swagger_doc_handler(request):
            return web.Response(text=self.doc_html, content_type='text/html')

        async def swagger_editor_handler(request):
            return web.Response(text=self.editor_html, content_type='text/html')

        async def swagger_config_handler(request):
            return web.json_response(self.get_config(request.host))

        self._app.router.add_get(self._uri(), swagger_doc_handler)
        self._app.router.add_get(self._uri('/'), swagger_doc_handler)

        if self._editor:
            self._app.router.add_get(self._uri('/editor'), swagger_editor_handler)

        self._app.router.add_get(self._uri('/swagger.json'), swagger_config_handler)
        self._app.router.add_static(self._uri('/'), path='{}/'.format(self.static_dir)) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:22,代码来源:core.py

示例5: _sanic_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _sanic_handler(self):
        from sanic import response
        from sanic.blueprints import Blueprint

        swagger_blueprint = Blueprint('swagger_blueprint', url_prefix=self._url_prefix)

        @swagger_blueprint.get('/')
        async def swagger_blueprint_doc_handler(request):
            return response.html(self.doc_html)

        if self._editor:
            @swagger_blueprint.get('/editor')
            async def swagger_blueprint_editor_handler(request):
                return response.html(self.editor_html)

        @swagger_blueprint.get('/swagger.json')
        async def swagger_blueprint_config_handler(request):
            return response.json(self.get_config(request.host))

        swagger_blueprint.static('/', str(self.static_dir))
        self._app.blueprint(swagger_blueprint) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:23,代码来源:core.py

示例6: work_sql_execute_details

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def work_sql_execute_details(work_number=None):
    publish_info = defaultdict()
    try:
        db_sso = db_op.user_sso
        db_sql_execute = db_op.sql_execute
        if work_number:
            infos = db_sso.query.with_entities(db_sso.dingunionid, db_sso.realName, db_sso.department).all()
            users = {info[0]: info[1:] for info in infos}
            sql_execute= db_sql_execute.query.with_entities(db_sql_execute.date,
                                                            db_sql_execute.time,
                                                            db_sql_execute.host,
                                                             db_sql_execute.port,
                                                             db_sql_execute.database,
                                                             db_sql_execute.sql_url,
                                                             db_sql_execute.sql_md5,
                                                             db_sql_execute.describe,
                                                            db_sql_execute.dingid).filter(db_sql_execute.work_number==int(work_number)).all()
            if sql_execute:
                publish_info['sql_execute'] = sql_execute[0]
                publish_info['user_info'] = users[sql_execute[0][-1]]
    except Exception as e:
        logging.error(e)
    return render_template('sql_execute_details.html', publish_info=publish_info) 
开发者ID:wylok,项目名称:sparrow,代码行数:25,代码来源:work_order.py

示例7: _prepare_flask_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _prepare_flask_request():
        # If server is behind proxys or balancers use the HTTP_X_FORWARDED fields
        url_data = urlparse(request.url)
        port = url_data.port or (443 if request.scheme == 'https' else 80)

        return {
            'https': 'on' if request.scheme == 'https' else 'off',
            'http_host': request.host,
            'server_port': port,
            'script_name': request.path,
            'get_data': request.args.copy(),
            'post_data': request.form.copy()
        } 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:15,代码来源:__init__.py

示例8: anticsrf

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def anticsrf(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        try:
            if request.referrer and request.referrer.replace('http://', '').split('/')[0] == request.host:
                return f(*args, **kwargs)
            else:
                return redirect(url_for('NotFound'))
        except Exception, e:
            print e
            return redirect(url_for('Error')) 
开发者ID:ysrc,项目名称:xunfeng,代码行数:13,代码来源:AntiCSRF.py

示例9: logout

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def logout():
    '''
    Manually override the logout URL to avoid completely signing the user
    out of all Google accounts
    '''
    if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
        return redirect('_ah/logout?continue=https://' + request.host + '/')
    return redirect(users.create_logout_url('/')) 
开发者ID:duo-labs,项目名称:isthislegit,代码行数:10,代码来源:views.py

示例10: prepare_auth_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def prepare_auth_request(request):
    url_data = urlparse(request.url)
    return {
        "https": 'on',
        'http_host': request.host,
        'server_port': url_data.port,
        'script_name': request.path,
        'get_data': request.args.copy(),
        'post_data': request.form.copy(),
        # Uncomment if using ADFS as IdP, https://github.com/onelogin/python-saml/pull/144
        # 'lowercase_urlencoding': True,
        'query_string': request.query_string
    } 
开发者ID:certsocietegenerale,项目名称:fame,代码行数:15,代码来源:views.py

示例11: post_move

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def post_move():
    new_move = request.get_json()
    move = Move.query.get(new_move['id'])

    if move:
        return jsonify(result='success')

    if not move:
        move = Move.deserialize(new_move)

    if not move.valid:
        return jsonify(result='failed',
                       message=f"move {move.id} isn't valid."), 400

    db.session.add(move)
    try:
        db.session.commit()
    except IntegrityError:
        return jsonify(result='failed',
                       message="This node already has this move."), 400
    sent_node = Node()
    if 'sent_node' in new_move:
        sent_node.url = new_move['sent_node']

    move_broadcast.delay(
        move.id,
        sent_node_url=sent_node.url,
        my_node_url=f'{request.scheme}://{request.host}'
    )
    return jsonify(result='success') 
开发者ID:nekoyume,项目名称:nekoyume,代码行数:32,代码来源:api.py

示例12: _tornado_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _tornado_handler(self):
        from tornado.web import RequestHandler, StaticFileHandler

        interface = self

        class DocHandler(RequestHandler):
            def get(self, *args, **kwargs):
                return self.write(interface.doc_html)

        class EditorHandler(RequestHandler):
            def get(self, *args, **kwargs):
                return self.write(interface.editor_html)

        class ConfigHandler(RequestHandler):
            def get(self, *args, **kwargs):
                return self.write(interface.get_config(self.request.host))

        handlers = [
            (self._uri(), DocHandler),
            (self._uri('/'), DocHandler),
            (self._uri('/swagger.json'), ConfigHandler),
            (self._uri('/(.+)'), StaticFileHandler, {'path': self.static_dir}),
        ]

        if self._editor:
            handlers.insert(1, (self._uri('/editor'), EditorHandler))

        self._app.add_handlers('.*', handlers) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:30,代码来源:core.py

示例13: _flask_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _flask_handler(self):
        from flask import request, jsonify
        from flask.blueprints import Blueprint

        swagger_blueprint = Blueprint(
            'swagger_blueprint', __name__, url_prefix=self._url_prefix,
            static_folder=self.static_dir, static_url_path='/'
        )

        @swagger_blueprint.route(r'')
        def swagger_blueprint_doc_handler():
            return self.doc_html

        @swagger_blueprint.route(r'/')
        def swagger_blueprint_doc_v2_handler():
            return self.doc_html

        @swagger_blueprint.route(r'/swagger.json')
        def swagger_blueprint_config_handler():
            return jsonify(self.get_config(request.host))

        if self._editor:
            @swagger_blueprint.route(r'/editor')
            def swagger_blueprint_editor_handler():
                return self.editor_html

        self._app.register_blueprint(swagger_blueprint) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:29,代码来源:core.py

示例14: _falcon_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _falcon_handler(self):
        import json
        interface = self

        class SwaggerDocHandler:
            def on_get(self, req, resp):
                resp.content_type = 'text/html'
                resp.body = interface.doc_html

        class SwaggerEditorHandler:
            def on_get(self, req, resp):
                resp.content_type = 'text/html'
                resp.body = interface.editor_html

        class SwaggerConfigHandler:
            def on_get(self, req, resp):
                resp.content_type = 'application/json'
                resp.body = json.dumps(interface.get_config(f'{req.host}:{req.port}'))

        self._app.add_route(self._uri('/'), SwaggerDocHandler())

        if self._editor:
            self._app.add_route(self._uri('/editor'), SwaggerEditorHandler())

        self._app.add_route(self._uri('/swagger.json'), SwaggerConfigHandler())
        self._app.add_static_route(prefix=self._uri(
            '/'), directory='{}/'.format(self.static_dir), downloadable=True) 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:29,代码来源:core.py

示例15: _starlette_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import host [as 别名]
def _starlette_handler(self):
        from starlette.responses import HTMLResponse, JSONResponse
        from starlette.staticfiles import StaticFiles

        async def swagger_doc_handler(request):
            return HTMLResponse(content=self.doc_html, media_type='text/html')

        async def swagger_editor_handler(request):
            return JSONResponse(content=self.editor_html, media_type='text/html')

        async def swagger_config_handler(request):
            host = '{}:{}'.format(request.url.hostname, request.url.port)
            return JSONResponse(self.get_config(host))

        self._app.router.add_route(self._uri(''), swagger_doc_handler, ['get'], 'swagger-ui')
        self._app.router.add_route(self._uri('/'), swagger_doc_handler, ['get'], 'swagger-ui')

        if self._editor:
            self._app.router.add_route(
                self._uri('/editor'), swagger_editor_handler, ['get'], 'swagger-editor')

        self._app.router.add_route(self._uri('/swagger.json'),
                                   swagger_config_handler, ['get'], 'swagger-config')
        self._app.router.mount(self._uri('/'),
                               app=StaticFiles(directory='{}/'.format(self.static_dir)),
                               name='swagger-static-files') 
开发者ID:PWZER,项目名称:swagger-ui-py,代码行数:28,代码来源:core.py


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