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


Python Validator.callback方法代码示例

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


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

示例1: api

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import callback [as 别名]
def api(method_name):
    db = Connection(MONGODB_SERVERS).riverid
    api = API(db)
    method = getattr(api, method_name, False)

    if method == False:
        abort(404)

    method_parameters = getargspec(method).args
    method_parameters.remove('self')

    if request.method == 'POST':
        request_parameters = request.form.to_dict()
    else:
        request_parameters = request.args.to_dict()

    if 'callback' in request_parameters:
        callback = request_parameters['callback']
        Validator.callback(callback)
    else:
        callback = False
    
    if 'lang' in request_parameters:
        if request_parameters['lang'] in languages:
            languages[request_parameters['lang']].install()
        else:
            languages['en_ZA'].install()
    else:
        languages['en_ZA'].install()
    
    if 'cookies' in method_parameters:
        request_parameters['cookies'] = request.cookies

    for key in method_parameters:
        if key not in request_parameters:
            abort(400)
    
    unused_parameters = []
    for key in request_parameters:
        if key not in method_parameters:
            unused_parameters.append(key)
    for key in unused_parameters:
        del request_parameters[key]

    result = dict(method=method_name, request=request_parameters)

    try:
        result['response'] = method(**request_parameters)
        result['success'] = True
    except RiverException as (error,):
开发者ID:d8agroup,项目名称:riverid,代码行数:52,代码来源:riverid.py

示例2: api

# 需要导入模块: from validator import Validator [as 别名]
# 或者: from validator.Validator import callback [as 别名]
def api(method_name):
    db = Connection(MONGODB_SERVERS).riverid
    api = API(db)

    # Get a reference to the actual method in the API object to call
    method = getattr(api, method_name, False)

    # If the method could not be returned, it does not exist in the API
    if method == False:
        abort(404)

    # Use reflection to retrieve the list of defined parameters of the method
    method_parameters = getargspec(method).args
    method_parameters.remove('self')

    # Read the given parameters out of the post body if available, otherwise use the querystring
    # Use to_dict because every parameter key can only have one associated value
    if request.method == 'POST':
        request_parameters = request.form.to_dict()
    else:
        request_parameters = request.args.to_dict()

    # Special treatment for the callback parameter as that is used for JSONP
    if 'callback' in request_parameters:
        callback = request_parameters['callback']
        Validator.callback(callback)
    else:
        callback = False

    # Special treatment for the lang parameter as that is used for GNU Gettext
    if 'lang' in request_parameters:
        if request_parameters['lang'] in languages:
            languages[request_parameters['lang']].install()
        else:
            languages['en_ZA'].install()
    else:
        languages['en_ZA'].install()

    # Pass the cookies object to the method if the method has a parameter called "cookies"
    if 'cookies' in method_parameters:
        request_parameters['cookies'] = request.cookies

    # Check if there are any missing parameters
    for key in method_parameters:
        if key not in request_parameters:
            if key is not "mailfrom" and key is not "mailsubject":
                abort(400)

    # Remove extra parameters in the request that are not needed by the method
    unused_parameters = []
    for key in request_parameters:
        if key not in method_parameters:
            unused_parameters.append(key)
    for key in unused_parameters:
        del request_parameters[key]

    # Start building the object to be serialised and returned to the client
    result = dict(method=method_name, request=request_parameters)

    # Attempt to execute the API method with the given parameters
    try:
        result['response'] = method(**request_parameters)
        result['success'] = True
    except RiverException as (error,):
开发者ID:evansims,项目名称:riverid-python,代码行数:66,代码来源:riverid.py


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