• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python schema.Schema类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: validate_args

def validate_args(args):
    """ Validate arguments.
        Checks:
            that the specified file exists and is readable
            that LEVEL is between 1 and 7
    """

    schema = Schema({
        "FILE": Use(open,
                    error="FILE doesn't exist or isn't readable!"),

        "--level": Or(None,
                        And(Use(int), lambda n: 1 <= n <= 7),
                        error="LEVEL should be between 1 and 7"),

        Optional("--help"): Or(True, False),
        })

    try:
        # Don't return the validated args here, just make sure they are valid.
        # Schema will return an object containing an open file object,
        # when we just wanted to make sure the file was readable.
        schema.validate(args)
        return args

    except SchemaError as e:
        exit(e)
开发者ID:haesken,项目名称:mkpng,代码行数:27,代码来源:mkpng.py


示例2: __init__

    def __init__(self):
        self.status_ok_schema = Schema({'status' :And(str)})
        
        self.error = {"login_syntax" : '{"type":"login", "nick":"4 <= len(str) <= 10", "passwd":"str"}',
                      "register_syntax" : '{"type":"register", "nick":"4 <= len(str) <= 10", "passwd":"str", "email":"str"}',
                      "pub_public_msg_syntax" : '{"type":"public", "nick":"4 <= len(str) <= 10", "token_id":"str", "msg":"str"}',
                      "pub_public_msg_syntax" : '{"type":"public", "nick":"4 <= len(str) <= 10", "token_id":"str", "msg":"str"}'}

        self.user_join_left_schema = Schema({'user_join_left' :And(str), 'user_list': And(list), 'user' :And(str)})
        
        self.login_ok_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'login'),
                                       'nick': And(str, Use(str.lower), lambda n: 4 <= len(n) <= 10),
                                       'token_id':And(str), 'user_list': And(list)})
        self.login_nok_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'err_login'),
                                       'msg': And(str)})
        
        
        self.register_ok_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'register'),
                                       'succ':And(str)})
        self.msg_ok_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'public'),
                                       'from_': And(str, Use(str.lower), lambda n: 4 <= len(n) <= 10),
                                       'msg':And(str)})
        self.prv_msg_ok_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'private'),
                                       'to_':And(str), 'from_': And(str, Use(str.lower), lambda n: 4 <= len(n) <= 10),
                                       'msg':And(str)})
        
        self.access_folder_schema = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'folder'),
                                       'to_':And(str), 'from_': And(str)})
        
        self.status_ = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'status'),
                                       'status':And(str), 'nick': And(str)})

        self.access_folder_valid = Schema({'type' : And(str, Use(str.lower), lambda n: n == 'access_folder_valid'),
                                       'from_': And(str, Use(str.lower), lambda n: 4 <= len(n) <= 10),
                                       'to_':And(str), 'passwd':And(str)})
开发者ID:glyph,项目名称:barnamy,代码行数:35,代码来源:streaming_schema.py


示例3: test_generate_signature_schema

def test_generate_signature_schema():
    """Test generate_signature_schema() function."""
    def f(a, b, camelCase=True, none=None, quantity=3.0*unit.angstroms):
        pass

    f_schema = generate_signature_schema(f)
    assert len(f_schema) == 3
    for k in f_schema.keys():
        assert isinstance(k, Optional)

    # Remove Optional() marker for comparison
    stripped_schema = {k._schema: v for k, v in f_schema.items() if k._schema != 'quantity'}
    assert {'camel_case': bool, 'none': object} == stripped_schema

    # Check conversion
    f_schema = Schema(f_schema)
    assert f_schema.validate({'quantity': '5*angstrom'}) == {'quantity': 5*unit.angstrom}

    # Check update
    optional_instance = Optional('camel_case')
    updated_schema = generate_signature_schema(f, update_keys={'none': float, optional_instance: int},
                                               exclude_keys={'quantity'})
    assert len(updated_schema) == 2
    assert updated_schema['none'] == float
    assert updated_schema[optional_instance] == int
开发者ID:andrrizzi,项目名称:yank,代码行数:25,代码来源:test_utils.py


示例4: validate_args

def validate_args(args):
    """
    Validates command line arguments
    """
    schema = Schema({
        '--user': And(str, len, Use(str.lower), error="missing or invalid user"),
        '--repo': And(str, len, Use(str.lower), error="missing or invalid repo"),
        '--type': And(str, len, Use(str.lower), lambda s: s in ('deb', 'rpm'), error="type must be one of deb or rpm"),
        '--distro': And(str, len, Use(str.lower), error="missing or invalid distro"),
        '--distro_version': And(str, len, Use(str.lower), error="missing or invalid distro_version"),
        '--arch': And(str, len, Use(str.lower), error="missing or invalid arch"),
        '--pkg_name': And(str, len, Use(str.lower), error="missing or invalid pkg_name"),
        '--filename': And(str, len, Use(str.lower), error="missing or invalid filename"),
        '--timeout': And(Use(float), lambda f: f > 0, lambda f, i=float(args['--poll_interval']): f > i,
                         error="timeout must be a number greater than 1, and greater than poll_interval (default 30)"),
        '--poll_interval': And(Use(float), lambda f: f > 0, error="poll_interval must be a number greater than 0"),
        '--page_interval': And(Use(float), lambda f: f > 0, error="page_interval must be a number greater than 0"),
        '--help': bool,
        '--version': bool,
        '--log-level': And(str, len, Use(str.upper),
                           lambda s: s in ('DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'),
                           error="invalid log level specified")
    })

    try:
        return schema.validate(args)
    except SchemaError as ex:
        utils.abort("Invalid argument: {}. ".format(ex.message))
开发者ID:pwyliu,项目名称:packagecloud-poll,代码行数:28,代码来源:config.py


示例5: _validate_neighbor

    def _validate_neighbor(self):
        """Validate neighbor against Schema."""

        neighbor_schema = Schema({
            'remote_ip': basestring,
            'remote_as': And(basestring, lambda n: 0 <= int(n) <= 4294967295),
            Optional('password'): basestring,
            Optional('maximum_hops'): And(basestring,
                                          lambda n: 1 <= int(n) <= 255),
            Optional('timer_keepalive'): And(basestring,
                                             lambda n: 1 <= int(n) <= 65535),
            Optional('timer_timeout'): And(basestring,
                                           lambda n: 3 <= int(n) <= 65536),
            Optional('description'): basestring,
            Optional('soft_reconfiguration'): bool,
            Optional('community'): bool,
            Optional('remove_private_as'): bool,
            Optional('next_hop_self'): bool
        })

        try:
            neighbor_schema.validate(self.neighbor)
        except SchemaWrongKeyError:
            # It doesn't matter if neighbor dict has other keys besides these.
            pass
        except SchemaError as e:
            raise InvalidNeighborException(e.code)
开发者ID:globocom,项目名称:GloboNetworkAPI,代码行数:27,代码来源:Generic.py


示例6: test_json_schema_object_or_array_of_object

def test_json_schema_object_or_array_of_object():
    # Complex test where "test" accepts either an object or an array of that object
    o = {"param1": "test1", Optional("param2"): "test2"}
    s = Schema({"test": Or(o, [o])})
    assert s.json_schema("my-id") == {
        "$schema": "http://json-schema.org/draft-07/schema#",
        "id": "my-id",
        "properties": {
            "test": {
                "anyOf": [
                    {
                        "additionalProperties": False,
                        "properties": {"param1": {}, "param2": {}},
                        "required": ["param1"],
                        "type": "object",
                    },
                    {
                        "type": "array",
                        "items": {
                            "additionalProperties": False,
                            "properties": {"param1": {}, "param2": {}},
                            "required": ["param1"],
                            "type": "object",
                        },
                    },
                ]
            }
        },
        "required": ["test"],
        "additionalProperties": False,
        "type": "object",
    }
开发者ID:BillWang139967,项目名称:MyPythonLib,代码行数:32,代码来源:test_schema.py


示例7: is_valid

    def is_valid(self):
        """Checks if the input dictionary contains all valid types

        Checks the __dict__ attribute and ensure it follows the correct
        schema

        Args:
            None

        Returns:
            A Boolean if dictionary follows schema
        """

        schema = Schema({
            'region': unicode,
            'subnet': unicode,
            'purchase_type': And(unicode, lambda x: x in ["on_demand", "spot"]),
            'image': unicode,
            'price': unicode,
            'num_instances': int,
            'key_name': unicode,
            'security_group_ids': list,
            'instance_type': unicode,
            'tag_name': unicode,
            'vol_size': int,
            'bdm': dict})

        try:
            schema.validate(self.__dict__)
            return True
        except Exception as exc:
            print exc
            print "Invalid instance template"
            return False
开发者ID:danielblazevski,项目名称:pegasus,代码行数:34,代码来源:boto_util.py


示例8: run

def run(raw_args):
    '''
    Validates the arguments by converting the VCF files into lists of VCFRecords, converting
    threshold to int, and calling validate_value on <VALUE>.
    returns the command string for dispatching; the new args dictionary after validating, and the first
    filename so that that file can later be used for a vcf.VCFWriter object.
    :param dict raw_args: the result of docopt(__doc__)
    :return str, dict, str: the command string, the new args dict, and the first filename.
    '''
    commands = ['vcall', 'filter', 'diff', 'stat', 'statdiff', 'exists', 'ambiguous']
    schema_dict=    {
            '<FILE1>' : Use(validate_vcf_file),
            Optional('<FILE2>') : Use(validate_vcf_file),
            Optional('<VALUE>') : Use(validate_value),
            '--count' : bool,
            '--threshold' : Use(int, error='Threshold must be integer'),
            Optional('--tag') : lambda t: True,
            '--csv' : bool
             #tags.__contains__ #    error='Tag was not valid, should be one of {0}'.format(' '.join(tags)))
        }
    schema_dict.update( dict( (arg, bool) for arg in commands + ops))
    _args = Schema(schema_dict).validate(raw_args)
    cmd_str = [k for (k, arg) in _args.items() if k in commands and arg][0]
    filename = raw_args['<FILE1>']
    return cmd_str, _args, filename
开发者ID:demis001,项目名称:bio_pieces,代码行数:25,代码来源:vcfcat_main.py


示例9: test_optional_key_convert_failed_randomly_while_with_another_optional_object

def test_optional_key_convert_failed_randomly_while_with_another_optional_object():
    """
    In this test, created_at string "2015-10-10 00:00:00" is expected to be converted
    to a datetime instance.
        - it works when the schema is

            s = Schema({
                    'created_at': _datetime_validator,
                    Optional(basestring): object,
                })

        - but when wrapping the key 'created_at' with Optional, it fails randomly
    :return:
    """
    import datetime
    fmt = '%Y-%m-%d %H:%M:%S'
    _datetime_validator = Or(None, Use(lambda i: datetime.datetime.strptime(i, fmt)))
    # FIXME given tests enough
    for i in range(1024):
        s = Schema({
            Optional('created_at'): _datetime_validator,
            Optional('updated_at'): _datetime_validator,
            Optional('birth'): _datetime_validator,
            Optional(basestring): object,
        })
        data = {
            'created_at': '2015-10-10 00:00:00'
        }
        validated_data = s.validate(data)
        # is expected to be converted to a datetime instance, but fails randomly
        # (most of the time)
        assert isinstance(validated_data['created_at'], datetime.datetime)
开发者ID:Manmohan-Sing,项目名称:schema,代码行数:32,代码来源:test_schema.py


示例10: main

def main(args=None):
    # The console script created by setuptools takes the cwd off the path.
    sys.path.insert(0, os.getcwd())

    scheme = Schema({'--debug': bool,
                     '--delim': str,
                     '--demo': bool,
                     '--help': bool,
                     '--float': Or(None, str),
                     '--from': Or(None, Use(lambda x: list(map(int, x.split(','))))),
                     '--nan': Or(None, str),
                     '--next': Or(None, str),
                     '--no-index-label': bool,
                     '--not-finished': bool,
                     '-o': Or(None, str),
                     '--skip': Or(None, Use(lambda x: x.split(','))),
                     '--skip-parents': bool,
                     '--version': bool,
                     '<data-file>': Or(None, str),
                     '<exp-file>': Or(lambda x: x is None, os.path.exists, error='Invalid <exp-file>'),
                     '<level>': [str],
                     '<n>': [And(Use(int), lambda n: n > 0)],
                     'export': bool,
                     'resume': bool,
                     'run': bool,
                     })

    options = scheme.validate(docopt(__doc__, argv=args, version=__version__))

    if options['--debug']:
        logging.basicConfig(level=logging.DEBUG)

    if options['run'] or options['resume']:
        exp = Experiment.load(options['<exp-file>'])
        kwargs = {'demo': options['--demo'],
                  'parent_callbacks': not options['--skip-parents'],
                  'resume': options['resume'],
                  'session_options': options['-o'],
                  'from_section': options['--from'],
                  }

        if options['--next']:
            kwargs.update(section_obj=exp.find_first_not_run(
                options['--next'], by_started=not options['--not-finished']))

        elif options['resume'] and not options['<n>']:
            kwargs.update(section_obj=exp.find_first_partially_run(options['<level>'][0]))

        else:
            kwargs.update(zip(options['<level>'], options['<n>']))

        run_experiment_section(exp, **kwargs)

    elif options['export']:
        export_experiment_data(options['<exp-file>'], options['<data-file>'],
                               float_format=options['--float'],
                               skip_columns=options['--skip'],
                               index_label=False if options['--no-index-label'] else None,
                               na_rep=options['--nan'],
                               sep=options['--delim'])
开发者ID:hsharrison,项目名称:experimentator,代码行数:60,代码来源:__main__.py


示例11: main

def main():
    args = docopt(__doc__)

    schema = Schema({
        '--help': bool,
        '--headless': bool,
        '--width': Use(int),
        '--height': Use(int),
        '<save_path>': str,
    })

    try:
        args = schema.validate(args)
    except SchemaError as e:
        exit(e)

    model_path = 'models'

    loadPrcFileData('', 'window-title Babble')
    loadPrcFileData('', 'win-size %d %d' % (args['--width'], args['--height']))
    loadPrcFileData('', 'audio-library-name null') # suppress warning
    loadPrcFileData('', 'model-path %s' % model_path)
    loadPrcFileData('', 'bullet-filter-algorithm groups-mask')

    if args['--headless']:
        loadPrcFileData('', 'window-type none')

    app = App(args)
    app.run()
开发者ID:BarkingMouseStudio,项目名称:python-experiments,代码行数:29,代码来源:main.py


示例12: parse_args

def parse_args():
    opts = docopt(__doc__, version='.'.join(VERSION))
    schema = Schema({
        Optional('PACK_TYPE'):
        Or(None, lambda s: s.lower() in PACKS_TYPE,
           error="PACK_TYPE should be either %s" % (', '.join(PACKS_TYPE))),
        Optional('--config'):
        Or(None, Use(open),
           error="--config must be a readable file"),
        Optional('--attempts'):
        And(Use(int), lambda n: n > 0,
            error='--attempts must be a strictly positive integer'),
        Optional('--score'):
        And(Use(int),
            error='--score must be an integer'),
        Optional('--threshold'):
        And(Use(int), lambda n: n >= 0,
            error='--threshold must be a positive integer'),
        Optional('--low-threshold'):
        And(Use(int), lambda n: n > 0,
            error='--low-threshold must be a strictly positive integer'),
        Optional('--wait'):
        And(Use(int), lambda n: n >= 0,
            error='--wait must be a positive integer'),
        object: object,
    })
    opts = schema.validate(opts)
    opts['PACK_TYPE'] = opts['PACK_TYPE'].lower() if opts['PACK_TYPE'] else "wild"
    if opts['--config']:
        config = simplejson.loads(opts['--config'].read())
        opts.update(config)
    return opts
开发者ID:Arzaroth,项目名称:HearthPacks,代码行数:32,代码来源:HearthPacks.py


示例13: main

def main():
    """
    Main function
    """
    try:
        name = indexfile.__name__
        version = indexfile.__version__
        log = indexfile.getLogger(__name__)

        # local variables
        index = None

        # load commands
        commands = load_commands()
        helpstr = __doc__ % (name, name) + get_commands_help(commands)

        # create validation schema
        sch = Schema({
            'index': Or(None,
                        And(Or('-', 'stdin'),
                            Use(lambda x: sys.stdin)),
                        open),
            Optional('format'): open,
            Optional('loglevel'): And(str,
                                      Use(str.lower),
                                      Or('error',
                                         'warn',
                                         'info',
                                         'debug')),
            '<command>': Command(commands=commands),
            str: object
        })

        # parse args and remove dashes
        args = docopt(helpstr, version="%s v%s" % (name, version), options_first=True)
        args = dict([(k.replace('-', ''), v) for k, v in args.iteritems()])

        # validate args
        args = sch.validate(args)

        # deal with 'help' command
        if args.get('<command>') == 'help':
            docopt(helpstr, version="%s v%s" % (name, version), argv=['--help'])

        # load the index and delegate command
        config = load_config(os.getcwd(), args)

        indexfile.setLogLevel(config.get('loglevel'))
        index = open_index(config)

        command_ = get_command(args.get('<command>'), commands)
        argv = [name, command_] + args['<args>']
        sys.argv = argv
        module_ = "indexfile.cli.indexfile_%s" % command_
        runpy.run_module(module_,
                         run_name="__main__",
                         init_globals={'index': index, 'command': '{0} {1}'.format(name, command_)})

    except KeyboardInterrupt, e:
        sys.exit(1)
开发者ID:emi80,项目名称:idxtools,代码行数:60,代码来源:indexfile_main.py


示例14: _fit_first

    def _fit_first(self, first):
        # Check for a tuples of numbers, strings or "sequences".
        schema = Schema((int, float, basestring, SequenceValidator()))
        schema.validate(first)
        if not first:
            raise ValueError("Cannot fit with no empty features")

        # Build validation schema using the first data point
        self.indexes = {}  # Tuple index to matrix column mapping
        self.reverse = []  # Matrix column to tuple index mapping
        self.schema = [None] * len(first)
        self.str_tuple_indexes = []
        for i, data in enumerate(first):
            if isinstance(data, (int, float)):
                type_ = Use(float)  # ints and floats are all mapped to float
                self._add_column(i, None)
            elif isinstance(data, basestring):
                type_ = basestring  # One-hot encoded indexes are added last
                self.str_tuple_indexes.append(i)
            else:
                type_ = SequenceValidator(data)
                for j in xrange(type_.size):
                    self._add_column(i, j)
            self.schema[i] = type_
        assert None not in self.schema
        self.schema = tuple(self.schema)
        self.validator = TupleValidator(self.schema)
开发者ID:wavelets,项目名称:featureforge,代码行数:27,代码来源:flattener.py


示例15: optparser

def optparser(argv=sys.argv[1:]):
    __usage__ = """
Bayesian analysis of ITC data. Uses MicroCal .itc files, or custom format .yml files for analysing experiments.

Usage:
  ITC.py <datafiles>... [-w <workdir> | --workdir=<workdir>] [-n <name> | --name=<name>] [-q <file> | --heats=<file>] [-i <ins> | --instrument=<ins> ] [-v | -vv | -vvv] [-r <file> | --report=<file>] [ -l <logfile> | --log=<logfile>]
  ITC.py mcmc <datafiles>...  (-m <model> | --model=<model>) [-w <workdir> | --workdir=<workdir>] [ -r <receptor> | --receptor=<receptor>] [-n <name> | --name=<name>] [-q <file> | --heats=<file>] [-i <ins> | --instrument=<ins> ] [ -l <logfile> | --log=<logfile>] [-v | -vv | -vvv] [--report=<file>] [options]
  ITC.py (-h | --help)
  ITC.py --license
  ITC.py --version

Options:
  -h, --help                            Show this screen
  --version                              Show version
  --license                              Show license
  -l <logfile>, --log=<logfile>          File to write logs to. Will be placed in workdir.
  -v,                                    Verbose output level. Multiple flags increase verbosity.
  <datafiles>                            Datafile(s) to perform the analysis on, .itc, .yml
  -w <workdir>, --workdir=<workdir>      Directory for output files                      [default: ./]
  -r <receptor> | --receptor=<receptor>  The name of the receptor for a Competitive Binding model.
  -n <name>, --name=<name>               Name for the experiment. Will be used for output files. Defaults to inputfile name.
  -i <ins>, --instrument=<ins>           The name of the instrument used for the experiment. Overrides .itc file instrument.
  -q <file>, --heats=<file>              Origin format integrated heats file. (From NITPIC use .dat file)
  -m <model>, --model=<model>            Model to use for mcmc sampling                  [default: TwoComponent]
  --nfit=<n>                             No. of iteration for maximum a posteriori fit   [default: 20000]
  --niters=<n>                           No. of iterations for mcmc sampling             [default: 2000000]
  --nburn=<n>                            No. of Burn-in iterations for mcmc sampling     [default: 500000]
  --nthin=<n>                            Thinning period for mcmc sampling               [default: 250]
  --report=<file>                        Output file with summary in markdown
"""
    arguments = docopt(__usage__, argv=argv, version='ITC.py, pre-alpha')
    schema = Schema({'--heats': Or(None, And(str, os.path.isfile, Use(os.path.abspath))),  # str, verify that it exists
                     '--help': bool,  # True or False are accepted
                     '--license': bool,  # True or False are accepted
                     '-v': And(int, lambda n: 0 <= n <= 3),  # integer between 0 and 3
                     '--model': And(str, lambda m: m in known_models),  # str and found in this dict
                     '--nfit':And(Use(int), lambda n: n > 0),
                     # Convert str to int, make sure that it is larger than 0
                     '--nburn': And(Use(int), lambda n: n > 0),
                     # Convert str to int, make sure that it is larger than 0
                     '--niters': And(Use(int), lambda n: n > 0),
                     # Convert str to int, make sure that it is larger than 0
                     '--nthin': And(Use(int), lambda n: n > 0),
                     # Convert str to int, make sure that it is larger than 0
                     '--name': Or(None, And(str, len)),  # Not an empty string
                     '--instrument': Or(None, And(str, lambda m: m in known_instruments)),
                     # None, or str and found in this dict
                     '--version': bool,  # True or False are accepted
                     '--receptor': str,  # str
                     '--workdir': str,  # str
                     # list and ensure it contains existing files
                     '<datafiles>': And(list, lambda inpfiles : [os.path.isfile(inpfile) for inpfile in inpfiles], Use(lambda inpfiles: [os.path.abspath(inpfile) for inpfile in inpfiles])),
                     'mcmc': bool,  # True or False are accepted
                     '--report': Or(None, Use(lambda f: open(f, 'w'))),
                     # Don't use, or open file with writing permissions
                     '--log': Or(None, str),  # Don't use, or str
                    })

    return schema.validate(arguments)
开发者ID:kyleburke1989,项目名称:bayesian-itc,代码行数:59,代码来源:parser.py


示例16: __init__

    def __init__(self, input_file=None, output_file=None, dfxml_file=None, report_file=None,
                 commit=False, ignore_patterns=[], key=None, rules=[]):
        #  Validate configuration
        from schema import Schema, Optional, Or, Use, And, SchemaError
        schema = Schema({
            'input_file': Use(lambda f: open(f, 'r'), error='Cannot read the input file'),
            Optional('output_file'):
            Or(None,
               Use(lambda f: open(f, 'w'), error='Cannot write to the output file')),
            Optional('dfxml_file'):
            Or(None,
               Use(lambda f: open(f, 'r'), error='Cannot read DFXML file')),
            Optional('report_file'):
            Or(None,
               lambda f: open(f, 'w'), error='Cannot write to the report file'),
            'commit': Or(True, False),
            'ignore_patterns':
                Use(lambda f: re.compile(convert_fileglob_to_re('|'.join(f))),
                    error='Cannot compile unified ignore regex'),
            'key': Or(None, str),
            'rules': And([(redact_rule, redact_action)], lambda f: len(f) > 0)})
        try:
            kwargs = {
                'input_file': input_file,
                'output_file': output_file,
                'dfxml_file': dfxml_file,
                'report_file': report_file,
                'commit': commit,
                'ignore_patterns': ignore_patterns,
                'key': key,
                'rules': rules
            }
            self.conf = schema.validate(kwargs)
        except SchemaError as e:
            logging.warning('The redact configuration did not validate:')
            exit(e)
        if self.conf['commit'] and 'output_file' not in self.conf.keys():
            logging.error('An output file is required when COMMIT is on.')
            exit(1)
        # TODO Check input and output are not same file

        logging.debug('Configuration:\n%s' % self.conf)

        # Print rules
        logging.debug(json.dumps(map(lambda x, y: (x.line,
                                                   x.__class__.__name__,
                                                   y.__class__.__name__,
                                                   x.lgpattern if hasattr(x, 'lgpattern') else ''),
                                     self.conf['rules']),
                                 indent=4))

        self.input_file = self.conf['input_file']
        from os import path
        self.image_size = path.getsize(self.input_file.name)
        self.output_file = self.conf['output_file']
        self.report_file = self.conf['report_file']
        self.dfxml_file = self.conf['dfxml_file']
        self.commit = self.conf['commit']
        self.configure_report_logger()
开发者ID:gregjan,项目名称:bca-redtools,代码行数:59,代码来源:redact.py


示例17: validate_args

def validate_args(args):
    schema = Schema({
        '--date': Or(None, lambda n: re.match('\d{8}', n) is not None, error='--date should be date_format=yyyymmdd'),
        '--help': bool,
        '--version': bool,
    })

    return schema.validate(args)
开发者ID:ok17,项目名称:mysql,代码行数:8,代码来源:var_log_backup.py


示例18: validate_descriptor

def validate_descriptor(descriptor):
    "return True if the given descriptor is correctly structured."
    try:
        descr_schema = Schema(
            {lambda v: v in ['files', 'tar-gzipped', 'mysql-database', 'postgresql-database']: [str]})
        return descr_schema.validate(descriptor)
    except SchemaError as err:
        raise AssertionError(str(err))
开发者ID:elifesciences,项目名称:ubr,代码行数:8,代码来源:descriptions.py


示例19: validate

    def validate(self, req):
        schema = Schema(
            {
                'code': And(str, len, error='Code is required')
            }
        )

        return schema.validate(req)
开发者ID:drachpy,项目名称:flask-rest,代码行数:8,代码来源:Book.py


示例20: checkSchema

def checkSchema(schemadict, args):
    '''Pythonic的检查schema'''
    schema = Schema(schemadict)
    try:
        args = schema.validate(args)
    except SchemaError as e:
        exit(log(e, error=True))
    return args
开发者ID:HaiquanHe,项目名称:mytools,代码行数:8,代码来源:MarkPygments.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python taskType.parseString函数代码示例发布时间:2022-05-27
下一篇:
Python schema.setup_schema函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap