當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。