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


Python request.user_agent方法代碼示例

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


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

示例1: is_from_browser

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def is_from_browser(user_agent):
    return user_agent.browser in [
        "camino",
        "chrome",
        "firefox",
        "galeon",
        "kmeleon",
        "konqueror",
        "links",
        "lynx",
        "msie",
        "msn",
        "netscape",
        "opera",
        "safari",
        "seamonkey",
        "webkit",
    ] 
開發者ID:cgwire,項目名稱:zou,代碼行數:20,代碼來源:resources.py

示例2: ip_whitelist_add

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [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

示例3: get

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def get(self):
        try:
            logout()
            identity_changed.send(
                current_app._get_current_object(), identity=AnonymousIdentity()
            )
        except KeyError:
            return {"Access token not found."}, 500

        logout_data = {"logout": True}

        if is_from_browser(request.user_agent):
            response = jsonify(logout_data)
            unset_jwt_cookies(response)
            return response
        else:
            return logout_data 
開發者ID:cgwire,項目名稱:zou,代碼行數:19,代碼來源:resources.py

示例4: _is_msie8or9

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def _is_msie8or9():
    """Returns ``True`` if and only if the user agent of the client making the
    request indicates that it is Microsoft Internet Explorer 8 or 9.

    .. note::

       We have no way of knowing if the user agent is lying, so we just make
       our best guess based on the information provided.

    """
    # request.user_agent.version comes as a string, so we have to parse it
    version = lambda ua: tuple(int(d) for d in ua.version.split('.'))
    return (request.user_agent is not None
            and request.user_agent.version is not None
            and request.user_agent.browser == 'msie'
            and (8, 0) <= version(request.user_agent) < (10, 0)) 
開發者ID:yfauser,項目名稱:planespotter,代碼行數:18,代碼來源:views.py

示例5: filter_client_request

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def filter_client_request():
    """過濾用戶請求, 視情況拒絕用戶的訪問
    :rtype: Union[Response, None]
    """
    dbgprint('Client Request Url: ', request.url)

    # crossdomain.xml
    if os.path.basename(request.path) == 'crossdomain.xml':
        dbgprint('crossdomain.xml hit from', request.url)
        return crossdomain_xml()

    # Global whitelist ua
    if check_global_ua_pass(str(request.user_agent)):
        return None

    if is_deny_spiders_by_403 and is_denied_because_of_spider(str(request.user_agent)):
        return generate_simple_resp_page(b'Spiders Are Not Allowed To This Site', 403)

    if human_ip_verification_enabled and (
                ((human_ip_verification_whitelist_from_cookies or enable_custom_access_cookie_generate_and_verify)
                 and must_verify_cookies)
            or is_ip_not_in_allow_range(request.remote_addr)
    ):
        dbgprint('ip', request.remote_addr, 'is verifying cookies')
        if 'zmirror_verify' in request.cookies and \
                ((human_ip_verification_whitelist_from_cookies and verify_ip_hash_cookie(request.cookies.get('zmirror_verify')))
                 or (enable_custom_access_cookie_generate_and_verify and custom_verify_access_cookie(
                        request.cookies.get('zmirror_verify'), request))):
            ip_whitelist_add(request.remote_addr, info_record_dict=request.cookies.get('zmirror_verify'))
            dbgprint('add to ip_whitelist because cookies:', request.remote_addr)
        else:
            return redirect(
                "/ip_ban_verify_page?origin=" + base64.urlsafe_b64encode(str(request.url).encode(encoding='utf-8')).decode(
                    encoding='utf-8'),
                code=302)

    return None 
開發者ID:aploium,項目名稱:zmirror,代碼行數:39,代碼來源:zmirror.py

示例6: _request_end

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def _request_end(resp):
    try:
        jsonbody = request.get_json(force=True, silent=True)
    except HTTPException:
        jsonbody = None

    values = request.values.to_dict()

    if jsonbody and not isinstance(jsonbody, dict):
        jsonbody = {"_parsererror": jsonbody}

    if isinstance(values, dict):
        filter_logs(values, FILTERED_VALUES)

    extra = {
        "endpoint": request.endpoint,
        "request_id": request.request_id,
        "remote_addr": request.remote_addr,
        "http_method": request.method,
        "original_url": request.url,
        "path": request.path,
        "parameters": values,
        "json_body": jsonbody,
        "confsha": CONFIG_DIGEST,
    }

    if request.user_agent is not None:
        extra["user-agent"] = request.user_agent.string

    logger.debug("Ending request: %s (%s)", request.request_id, request.path, extra=extra)
    return resp 
開發者ID:quay,項目名稱:quay,代碼行數:33,代碼來源:app.py

示例7: require_xhr_from_browser

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import user_agent [as 別名]
def require_xhr_from_browser(func):
    """
    Requires that API GET calls made from browsers are made via XHR, in order to prevent reflected
    text attacks.
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        if app.config.get("BROWSER_API_CALLS_XHR_ONLY", False):
            if request.method == "GET" and request.user_agent.browser:
                has_xhr_header = request.headers.get("X-Requested-With") == "XMLHttpRequest"
                if not has_xhr_header and not app.config.get("DEBUGGING") == True:
                    logger.warning(
                        "Disallowed possible RTA to URL %s with user agent %s",
                        request.path,
                        request.user_agent,
                    )
                    abort(
                        400,
                        message="API calls must be invoked with an X-Requested-With header "
                        + "if called from a browser",
                    )

        return func(*args, **kwargs)

    return wrapper 
開發者ID:quay,項目名稱:quay,代碼行數:28,代碼來源:decorators.py


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