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


Python g.get方法代码示例

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


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

示例1: check_token

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def check_token(self, token, allowed_roles, resource, method):
        """
        This function is called when a token is sent throught the access_token
        parameter or the Authorization header as specified in the oAuth 2 specification.

        The provided token is validated with the JWT_SECRET defined in the Eve configuration.
        The token issuer (iss claim) must be the one specified by JWT_ISSUER and the audience
        (aud claim) must be one of the value(s) defined by the either the "audiences" resource
        parameter or the global JWT_AUDIENCES configuration.

        If JWT_ROLES_CLAIM is defined and a claim by that name is present in the token, roles
        are checked using this claim.

        If a JWT_SCOPE_CLAIM is defined and a claim by that name is present in the token, the
        claim value is check, and if "viewer" is present, only GET and HEAD methods will be
        allowed. The scope name is then added to the list of roles with the scope: prefix.

        If the validation succeed, the claims are stored and accessible thru the
        get_authen_claims() method.
        """
        resource_conf = config.DOMAIN[resource]
        audiences = resource_conf.get('audiences', config.JWT_AUDIENCES)
        return self._perform_verification(token, audiences, allowed_roles) 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:25,代码来源:auth.py

示例2: getlanguage

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def getlanguage():
    """Get the user language."""
    gval = g.get('language', None)
    if gval:
        return gval

    for lang in [
        request.form.get('uselang'),
        request.args.get('uselang'),
        session.get('language'),
        request.accept_languages.best,
    ]:
        if lang and _islang(lang):
            break
    else:
        lang = 'en'

    g.language = lang

    return lang 
开发者ID:toolforge,项目名称:video2commons,代码行数:22,代码来源:i18n.py

示例3: post

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def post(self, user_id):

        post_data = request.get_json()
        organisation = g.get('active_organisation')
        if organisation is None:
            return make_response(jsonify({'message': 'Organisation must be set'})), 400

        response_object, response_code = UserUtils.proccess_create_or_modify_user_request(
            post_data,
            organisation=organisation
        )

        if response_code == 200:
            db.session.commit()

        return make_response(jsonify(response_object)), response_code 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:18,代码来源:user_api.py

示例4: _get_config

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def _get_config(
    value, config_name, default=None,
    required=True, message='CSRF is not configured.'
):
    """Find config value based on provided value, Flask config, and default
    value.

    :param value: already provided config value
    :param config_name: Flask ``config`` key
    :param default: default value if not provided or configured
    :param required: whether the value must not be ``None``
    :param message: error message if required config is not found
    :raises KeyError: if required config is not found
    """

    if value is None:
        value = current_app.config.get(config_name, default)

    if required and value is None:
        raise KeyError(message)

    return value 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:24,代码来源:csrf.py

示例5: _get_csrf_token

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def _get_csrf_token(self):
        # find the ``csrf_token`` field in the subitted form
        # if the form had a prefix, the name will be
        # ``{prefix}-csrf_token``
        field_name = current_app.config['WTF_CSRF_FIELD_NAME']

        for key in request.form:
            if key.endswith(field_name):
                csrf_token = request.form[key]

                if csrf_token:
                    return csrf_token

        for header_name in current_app.config['WTF_CSRF_HEADERS']:
            csrf_token = request.headers.get(header_name)

            if csrf_token:
                return csrf_token

        return None 
开发者ID:liantian-cn,项目名称:RSSNewsGAE,代码行数:22,代码来源:csrf.py

示例6: update_from_nominatim

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def update_from_nominatim(self, hit):
        if self.place_id != int(hit['place_id']):
            print((self.place_id, hit['place_id']))
            self.place_id = hit['place_id']

        keys = ('lat', 'lon', 'display_name', 'place_rank', 'category', 'type',
                'icon', 'extratags', 'namedetails')
        assert all(hit[n] is not None for n in ('lat', 'lon'))
        for n in keys:
            setattr(self, n, hit.get(n))
        bbox = hit['boundingbox']
        assert all(i is not None for i in bbox)
        (self.south, self.north, self.west, self.east) = bbox
        self.address = [dict(name=n, type=t) for t, n in hit['address'].items()]
        self.wikidata = hit['extratags'].get('wikidata')
        self.geom = hit['geotext'] 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:18,代码来源:place.py

示例7: name_for_changeset

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def name_for_changeset(self):
        address = self.address
        n = self.name
        if not address:
            return self.name
        if isinstance(address, list):
            d = {a['type']: a['name'] for a in address}
        elif isinstance(address, dict):
            d = address

        if d.get('country_code') == 'us':
            state = d.get('state')
            if state and n != state:
                return n + ', ' + state

        country = d.get('country')
        if country and self.name != country:
            return '{} ({})'.format(self.name, country)

        return self.name 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:22,代码来源:place.py

示例8: name

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def name(self):
        if self.override_name:
            return self.override_name

        name = self.namedetails.get('name:en') or self.namedetails.get('name')
        display = self.display_name
        if not name:
            return display

        for short in ('City', '1st district'):
            start = len(short) + 2
            if name == short and display.startswith(short + ', ') and ', ' in display[start:]:
                name = display[:display.find(', ', start)]
                break

        return name 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:18,代码来源:place.py

示例9: suggest_larger_areas

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def suggest_larger_areas(self):
        ret = []
        for e in reversed(self.is_in() or []):
            osm_type, osm_id, bounds = e['type'], e['id'], e['bounds']
            if osm_type == self.osm_type and osm_id == self.osm_id:
                continue

            box = func.ST_MakeEnvelope(bounds['minlon'], bounds['minlat'],
                                       bounds['maxlon'], bounds['maxlat'], 4326)

            q = func.ST_Area(box.cast(Geography))
            bbox_area = session.query(q).scalar()
            area_in_sq_km = bbox_area / (1000 * 1000)

            if area_in_sq_km < 10 or area_in_sq_km > 40_000:
                continue
            place = Place.from_osm(osm_type, osm_id)
            if not place:
                continue
            place.admin_level = e['tags'].get('admin_level') or None if 'tags' in e else None
            ret.append(place)

        ret.sort(key=lambda place: place.area_in_sq_km)
        return ret 
开发者ID:EdwardBetts,项目名称:osm-wikidata,代码行数:26,代码来源:place.py

示例10: track_user_qps

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def track_user_qps(response):
    if not request.endpoint:
        return response

    if g.get('auth'):
        name = g.auth.username
        kind = 'app' if g.auth.is_application else 'user'
    else:
        name = 'anonymous'
        kind = 'anonymous'
    tags = dict(kind=kind, name=name)
    if kind == 'app':
        tags.update(appid=name)
    monitor_client.increment('qps.all', tags=tags)
    monitor_client.increment('qps.url', tags=dict(
        endpoint=request.endpoint, method=request.method, **tags))

    return response 
开发者ID:huskar-org,项目名称:huskar,代码行数:20,代码来源:auth.py

示例11: get_authen_claims

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def get_authen_claims(self):
        return g.get(AUTHEN_CLAIMS, {}) 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:4,代码来源:auth.py

示例12: get_authen_roles

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def get_authen_roles(self):
        return g.get(AUTHEN_ROLES, []) 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:4,代码来源:auth.py

示例13: authorized

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def authorized(self, allowed_roles, resource, method):
        authorized = False

        if request.authorization:
            auth = request.authorization
            authorized = self.check_auth(auth.username, auth.password,
                                         allowed_roles, resource, method)
        else:
            try:
                access_token = request.args['access_token']
            except KeyError:
                access_token = request.headers.get('Authorization', '').partition(' ')[2]
            authorized = self.check_token(access_token, allowed_roles, resource, method)

        return authorized 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:17,代码来源:auth.py

示例14: authenticate

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def authenticate(self):
        """
        Indicate to the client that it needs to authenticate via a 401.
        """
        if request.headers.get('Authorization') or request.args.get('access_token'):
            realm = 'Bearer realm="%s", error="invalid_token"' % __package__
        else:
            realm = 'Bearer realm="%s"' % __package__
        resp = Response(None, 401, {'WWW-Authenticate': realm})
        abort(401, description='Please provide proper credentials', response=resp) 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:12,代码来源:auth.py

示例15: get_request_auth_value

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import get [as 别名]
def get_request_auth_value():
    """
    Get the authentication value

    Returns:
        str: auth value string
    """
    return g.get(AUTH_VALUE) 
开发者ID:rs,项目名称:eve-auth-jwt,代码行数:10,代码来源:auth.py


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