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


Python schema.And方法代码示例

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


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

示例1: mobile_b2c

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def mobile_b2c(self, product_name, consumers, callback=None):

        reasons = PaymentService.REASON.values()
        schema = Schema([
            {
                'name': And(str, len),
                'phoneNumber': And(str, lambda s: validate_phone(s)),
                'currencyCode': And(str, lambda s: len(s) == 3),
                'amount': And(lambda f: float(f) > 0),
                Optional('providerChannel'): And(str, len),
                Optional('reason'): And(str, lambda s: s in reasons),
                Optional('metadata'): And(dict)
            }
        ])
        consumers = schema.validate(consumers)
        url = self._make_url('/mobile/b2c/request')
        headers = dict(self._headers)
        headers['Content-Type'] = 'application/json'
        data = json.dumps({
            'username': self._username,
            'productName': product_name,
            'recipients': consumers
        })
        return self._make_request(url, 'POST', headers=headers, params=None, data=data, callback=callback) 
开发者ID:AfricasTalkingLtd,项目名称:africastalking-python,代码行数:26,代码来源:Payment.py

示例2: mobile_b2b

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def mobile_b2b(self, product_name, business, callback=None):

        providers = PaymentService.PROVIDER.values()
        types = PaymentService.TRANSFER_TYPE.values()
        schema = Schema({
            'provider': And(str, lambda s: s in providers),
            'transferType': And(str, lambda s: s in types),
            'currencyCode': And(str, lambda s: len(s) == 3),
            'amount': And(lambda f: float(f) > 0),
            'destinationChannel': And(str, len),
            'destinationAccount': And(str, len),
            Optional('metadata'): And(dict)
        })
        business = schema.validate(business)
        url = self._make_url('/mobile/b2b/request')
        headers = dict(self._headers)
        headers['Content-Type'] = 'application/json'
        data = business.copy()
        data.update({
            'username': self._username,
            'productName': product_name,
        })
        data = json.dumps(data)
        return self._make_request(url, 'POST', headers=headers, params=None, data=data, callback=callback) 
开发者ID:AfricasTalkingLtd,项目名称:africastalking-python,代码行数:26,代码来源:Payment.py

示例3: mobile_data

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def mobile_data(self, product_name, recipients, callback=None):

        schema = Schema([{
            'phoneNumber': And(str, lambda s: validate_phone(s)),
            'quantity': And(lambda f: float(f) > 0),
            'unit': And(str, lambda s: validate_data_units(s)),
            'validity': And(str, lambda s: validate_data_validity(s)),
            Optional('metadata'): And(dict)
        }])
        recipients = schema.validate(recipients)
        url = self._make_url('/mobile/data/request')
        headers = dict(self._headers)
        headers['Content-Type'] = 'application/json'
        data = {
            'username': self._username,
            'productName': product_name,
            'recipients': recipients,
        }
        data = json.dumps(data)
        return self._make_request(url, 'POST', headers=headers, params=None, data=data, callback=callback) 
开发者ID:AfricasTalkingLtd,项目名称:africastalking-python,代码行数:22,代码来源:Payment.py

示例4: bank_transfer

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def bank_transfer(self, product_name, recipients, callback=None):

        bank_account_schema = Schema({
            'accountNumber': And(str, len),
            'bankCode': And(int, lambda i: i in PaymentService.BANK.values()),
            Optional('accountName'): And(str, len),
        })
        schema = Schema([{
            'bankAccount': And(dict, lambda s: bank_account_schema.validate(s)),
            'currencyCode': And(str, lambda s: len(s) == 3),
            'amount': And(lambda f: float(f) > 0),
            'narration': And(str, len),
            Optional('metadata'): And(dict)
        }])
        recipients = schema.validate(recipients)
        url = self._make_url('/bank/transfer')
        headers = dict(self._headers)
        headers['Content-Type'] = 'application/json'
        data = {
            'username': self._username,
            'productName': product_name,
            'recipients': recipients,
        }
        data = json.dumps(data)
        return self._make_request(url, 'POST', headers=headers, params=None, data=data, callback=callback) 
开发者ID:AfricasTalkingLtd,项目名称:africastalking-python,代码行数:27,代码来源:Payment.py

示例5: get_options

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def get_options(cls):
        return {
            "suites": schema.Use(iterable_suites),
            config.ConfigOption("thread_pool_size", default=0): int,
            config.ConfigOption("max_thread_pool_size", default=10): int,
            config.ConfigOption("stop_on_error", default=True): bool,
            config.ConfigOption("part", default=None): schema.Or(
                None,
                schema.And(
                    (int,),
                    lambda tp: len(tp) == 2
                    and 0 <= tp[0] < tp[1]
                    and tp[1] > 1,
                ),
            ),
            config.ConfigOption(
                "result", default=result.Result
            ): validation.is_subclass(result.Result),
            config.ConfigOption("fix_spec_path", default=None): schema.Or(
                None, schema.And(str, os.path.exists)
            ),
        } 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:24,代码来源:base.py

示例6: get_options

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def get_options(cls):
        start_stop_signature = Or(
            None, validate_func("env"), validate_func("env", "result")
        )

        return {
            # 'name': And(str, lambda s: s.count(' ') == 0),
            "name": str,
            ConfigOption("description", default=None): Or(str, None),
            ConfigOption("environment", default=[]): [Resource],
            ConfigOption("before_start", default=None): start_stop_signature,
            ConfigOption("after_start", default=None): start_stop_signature,
            ConfigOption("before_stop", default=None): start_stop_signature,
            ConfigOption("after_stop", default=None): start_stop_signature,
            ConfigOption("test_filter"): filtering.BaseFilter,
            ConfigOption("test_sorter"): ordering.BaseSorter,
            ConfigOption("stdout_style"): test_styles.Style,
            ConfigOption("tags", default=None): Or(
                None, Use(tagging.validate_tag_value)
            ),
        } 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:23,代码来源:base.py

示例7: get_options

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def get_options(cls):
        """
        Schema for options validation and assignment of default values.
        """
        return {
            "name": str,
            ConfigOption("size", default=4): And(int, lambda x: x > 0),
            ConfigOption("worker_type", default=Worker): object,
            ConfigOption("worker_heartbeat", default=None): Or(
                int, float, None
            ),
            ConfigOption("heartbeats_miss_limit", default=3): int,
            ConfigOption("restart_count", default=3): int,
            ConfigOption("max_active_loop_sleep", default=5): numbers.Number,
            ConfigOption("should_rerun", default=default_check_rerun): Use(
                validate_custom_func
            ),
        } 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:20,代码来源:base.py

示例8: validate_ebs_volume_parameters

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def validate_ebs_volume_parameters(params: dict):
    from spotty.providers.aws.deployment.project_resources.ebs_volume import EbsVolume

    schema = Schema({
        Optional('volumeName', default=''): And(str, Regex(r'^[\w-]{1,255}$')),
        Optional('mountDir', default=''): str,  # all the checks happened in the base configuration
        Optional('size', default=0): And(int, lambda x: x > 0),
        # TODO: add the "iops" parameter to support the "io1" EBS volume type
        Optional('type', default='gp2'): lambda x: x in ['gp2', 'sc1', 'st1', 'standard'],
        Optional('deletionPolicy', default=EbsVolume.DP_CREATE_SNAPSHOT): And(
            str,
            lambda x: x in [EbsVolume.DP_CREATE_SNAPSHOT,
                            EbsVolume.DP_UPDATE_SNAPSHOT,
                            EbsVolume.DP_RETAIN,
                            EbsVolume.DP_DELETE], error='Incorrect value for "deletionPolicy".'
        ),
    })

    return validate_config(schema, params) 
开发者ID:apls777,项目名称:spotty,代码行数:21,代码来源:validation.py

示例9: validate_disk_volume_parameters

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def validate_disk_volume_parameters(params: dict):
    from spotty.providers.gcp.deployment.project_resources.disk_volume import DiskVolume

    schema = Schema({
        Optional('diskName', default=''): And(str, Regex(r'^[\w-]{1,255}$')),
        Optional('mountDir', default=''): str,  # all the checks happened in the base configuration
        Optional('size', default=0): And(int, lambda x: x > 0),
        Optional('deletionPolicy', default=DiskVolume.DP_CREATE_SNAPSHOT): And(
            str,
            lambda x: x in [DiskVolume.DP_CREATE_SNAPSHOT,
                            DiskVolume.DP_UPDATE_SNAPSHOT,
                            DiskVolume.DP_RETAIN,
                            DiskVolume.DP_DELETE], error='Incorrect value for "deletionPolicy".'
        ),
    })

    return validate_config(schema, params) 
开发者ID:apls777,项目名称:spotty,代码行数:19,代码来源:validation.py

示例10: choices

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def choices(self, key, *args):
        """
        Utility method to create a scheme to check whether the `key` is one of the `args`.

        Parameters:
        ----------
        key: str
            key name of the data to be validated
        args: list of str
            list of the choices

        Returns: Schema
        --------
            A scheme to check whether the `key` is one of the `args`.
        """
        return And(lambda n: n in args, error='%s should be in [%s]!' % (key, str(args))) 
开发者ID:microsoft,项目名称:nni,代码行数:18,代码来源:utils.py

示例11: range

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def range(self, key, keyType, start, end):
        """
        Utility method to create a schema to check whether the `key` is in the range of [start, end].

        Parameters:
        ----------
        key: str
            key name of the data to be validated
        keyType: type
            python data type, such as int, float
        start: type is specified by keyType
            start of the range
        end: type is specified by keyType
            end of the range

        Returns: Schema
        --------
            A scheme to check whether the `key` is in the range of [start, end].
        """
        return And(
            And(keyType, error='%s should be %s type!' % (key, keyType.__name__)),
            And(lambda n: start <= n <= end, error='%s should be in range of (%s, %s)!' % (key, start, end))
        ) 
开发者ID:microsoft,项目名称:nni,代码行数:25,代码来源:utils.py

示例12: _modify_schema

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def _modify_schema(self, data_schema, model, logger):
        if not data_schema:
            return data_schema

        for k in data_schema[0]:
            old_schema = data_schema[0][k]
            if k == 'op_types' or (isinstance(k, Schema) and k._schema == 'op_types'):
                new_schema = And(old_schema, lambda n: validate_op_types(model, n, logger))
                data_schema[0][k] = new_schema
            if k == 'op_names' or (isinstance(k, Schema) and k._schema == 'op_names'):
                new_schema = And(old_schema, lambda n: validate_op_names(model, n, logger))
                data_schema[0][k] = new_schema

        data_schema[0] = And(data_schema[0], lambda d: validate_op_types_op_names(d))

        return data_schema 
开发者ID:microsoft,项目名称:nni,代码行数:18,代码来源:config_validation.py

示例13: validate_config

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def validate_config(self, model, config_list):
        """
        Parameters
        ----------
        model : torch.nn.module
            Model to be pruned
        config_list : list
            List on pruning configs
        """

        if self._base_algo == 'level':
            schema = CompressorSchema([{
                'sparsity': And(float, lambda n: 0 < n < 1),
                Optional('op_types'): [str],
                Optional('op_names'): [str],
            }], model, _logger)
        elif self._base_algo in ['l1', 'l2']:
            schema = CompressorSchema([{
                'sparsity': And(float, lambda n: 0 < n < 1),
                'op_types': ['Conv2d'],
                Optional('op_names'): [str]
            }], model, _logger)

        schema.validate(config_list) 
开发者ID:microsoft,项目名称:nni,代码行数:26,代码来源:auto_compress_pruner.py

示例14: validate_config

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def validate_config(self, model, config_list):
        """
        Parameters
        ----------
        model : torch.nn.module
            Model to be pruned
        config_list : list
            Supported keys:
                - prune_iterations : The number of rounds for the iterative pruning.
                - sparsity : The final sparsity when the compression is done.
        """
        schema = CompressorSchema([{
            'sparsity': And(float, lambda n: 0 < n < 1),
            'prune_iterations': And(int, lambda n: n > 0),
            Optional('op_types'): [str],
            Optional('op_names'): [str]
        }], model, logger)

        schema.validate(config_list)
        assert len(set([x['prune_iterations'] for x in config_list])) == 1, 'The values of prune_iterations must be equal in your config' 
开发者ID:microsoft,项目名称:nni,代码行数:22,代码来源:lottery_ticket.py

示例15: validate_config

# 需要导入模块: import schema [as 别名]
# 或者: from schema import And [as 别名]
def validate_config(self, model, config_list):
        """
        Parameters
        ----------
        model : torch.nn.module
            Model to be pruned
        config_list : list
            List on pruning configs
        """
        schema = CompressorSchema([{
            'sparsity': And(float, lambda n: 0 < n < 1),
            Optional('op_types'): [str],
            Optional('op_names'): [str]
        }], model, logger)

        schema.validate(config_list) 
开发者ID:microsoft,项目名称:nni,代码行数:18,代码来源:one_shot.py


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