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


Python Schema.items方法代码示例

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


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

示例1: run

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import items [as 别名]
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,代码行数:27,代码来源:vcfcat_main.py

示例2: validate

# 需要导入模块: from schema import Schema [as 别名]
# 或者: from schema.Schema import items [as 别名]
 def validate(self, data):
     s = self._schema
     e = self._error
     if type(s) in (list, tuple, set, frozenset):
         data = Schema(type(s), error=e).validate(data)
         return type(s)(Or(*s, error=e).validate(d) for d in data)
     if type(s) is dict:
         data = Schema(dict, error=e).validate(data)
         new = type(data)()  # new - is a dict of the validated values
         x = None
         coverage = set()  # non-optional schema keys that were matched
         # for each key and value find a schema entry matching them, if any
         sorted_skeys = list(sorted(s, key=priority))
         for key, value in data.items():
             valid = False
             skey = None
             for skey in sorted_skeys:
                 svalue = s[skey]
                 try:
                     nkey = Schema(skey, error=e).validate(key)
                 except SchemaError:
                     pass
                 else:
                     try:
                         nvalue = Schema(svalue, error=e).validate(value)
                     except SchemaError as _x:
                         x = _x
                         raise
                     else:
                         coverage.add(skey)
                         valid = True
                         break
             if valid:
                 new[nkey] = nvalue
             elif skey is not None:
                 if x is not None:
                     raise SchemaError(["invalid value for key %r" % key] + x.autos, [e] + x.errors)
         coverage = set(k for k in coverage if type(k) is not Optional)
         required = set(k for k in s if type(k) is not Optional)
         if coverage != required:
             raise SchemaError("missed keys %r" % (required - coverage), e)
         if len(new) != len(data):
             wrong_keys = set(data.keys()) - set(new.keys())
             s_wrong_keys = ", ".join("%r" % k for k in sorted(wrong_keys))
             raise SchemaError("wrong keys %s in %r" % (s_wrong_keys, data), e)
         return new
     if hasattr(s, "validate"):
         try:
             return s.validate(data)
         except SchemaError as x:
             raise SchemaError([None] + x.autos, [e] + x.errors)
         except BaseException as x:
             raise SchemaError("%r.validate(%r) raised %r" % (s, data, x), self._error)
     if issubclass(type(s), type):
         if isinstance(data, s):
             return data
         else:
             raise SchemaError("%r should be instance of %r" % (data, s), e)
     if callable(s):
         f = s.__name__
         try:
             if s(data):
                 return data
         except SchemaError as x:
             raise SchemaError([None] + x.autos, [e] + x.errors)
         except BaseException as x:
             raise SchemaError("%s(%r) raised %r" % (f, data, x), self._error)
         raise SchemaError("%s(%r) should evaluate to True" % (f, data), e)
     if s == data:
         return data
     else:
         raise SchemaError("%r does not match %r" % (s, data), e)
开发者ID:Mondego,项目名称:pyreco,代码行数:74,代码来源:allPythonContent.py


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