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


Python trafaret.Int方法代码示例

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


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

示例1: test_add_kwargs_ignore

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_add_kwargs_ignore(self):
        first = t.Dict(
            t.Key('bar', trafaret=t.Int()), ignore_extra=['eggs']
        )
        second = t.Dict(
            t.Key('bar1', trafaret=t.Int())
        )
        third = first + second
        third.check({'bar': 4, 'bar1': 41})
        third.check({'bar': 4, 'bar1': 41, 'eggs': 'blabla'})

        first = t.Dict(
            t.Key('bar', trafaret=t.Int()),
        )
        second = t.Dict(
            t.Key('bar1', trafaret=t.Int()), ignore_extra=['eggs']
        )
        third = first + second
        third.check({'bar': 4, 'bar1': 41})
        third.check({'bar': 4, 'bar1': 41, 'eggs': 'blabla'}) 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:22,代码来源:test_base.py

示例2: test_add_kwargs_extra

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_add_kwargs_extra(self):
        first = t.Dict(
            t.Key('bar', trafaret=t.Int()), allow_extra=['eggs']
        )
        second = t.Dict(t.Key('bar1', trafaret=t.Int()))
        third = first + second
        third.check({"bar": 1, "bar1": 41, "eggs": None})
        third.check({"bar": 1, "bar1": 41})
        with pytest.raises(t.DataError):
            third.check({"bar": 2, "bar1": 1, "marmalade": 5})

        first = t.Dict(t.Key('bar', trafaret=t.Int()))
        second = t.Dict(t.Key('bar1', trafaret=t.Int()), allow_extra=['eggs'])
        third = first + second
        third.check({"bar": 1, "bar1": 41, "eggs": None})
        third.check({"bar": 1, "bar1": 41})
        with pytest.raises(t.DataError):
            third.check({"bar": 2, "bar1": 1, "marmalade": 5}) 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:20,代码来源:test_base.py

示例3: test_async_check

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_async_check():
    trafaret = t.Int & int
    res = await trafaret.async_check('5')
    assert res == 5 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:6,代码来源:test_async.py

示例4: test_key_shadowed

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_key_shadowed(self):
        trafaret = t.Dict(t.Key('a', to_name='b', trafaret=t.Int))
        res = extract_error(trafaret, {'a': 5, 'b': 7})
        assert res == {'b': 'b key was shadowed'} 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:6,代码来源:test_base.py

示例5: test_add_kwargs_ignore_any

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_add_kwargs_ignore_any(self):
        first = t.Dict(
            t.Key('bip', trafaret=t.String()), ignore_extra='*'
        )
        second = t.Dict(
            t.Key('bop', trafaret=t.Int())
        )

        third = first + second
        third.check({'bip': u'bam', 'bop': 17, 'matter': False})
        assert third.ignore_any 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:13,代码来源:test_base.py

示例6: test_forward

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_forward(self):
        node = t.Forward()
        res = extract_error(node, 'something')
        assert res == 'trafaret not set yet'
        node << t.Dict(name=t.String, children=t.List[node])
        assert node.check({"name": u"foo", "children": []}) == {'children': [], 'name': u'foo'}
        res = extract_error(node, {"name": u"foo", "children": [1]})
        assert res == {'children': {0: 'value is not a dict'}}
        res = node.check({"name": u"foo", "children": [{"name": u"bar", "children": []}]})
        assert res == {'children': [{'children': [], 'name': u'bar'}], 'name': u'foo'}

        with pytest.raises(RuntimeError):  # __rshift__ is not overridden
            node << t.Int() 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:15,代码来源:test_base.py

示例7: test_repr

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_repr(self):
        res = t.Iterable(t.ToInt)
        assert repr(res) == '<List(<ToInt>)>'
        res = t.Iterable(t.Int, min_length=0, max_length=10)
        assert repr(res) == '<List(max_length=10 | <Int>)>'
        res = t.Iterable(t.Int, min_length=1, max_length=10)
        assert repr(res) == '<List(min_length=1, max_length=10 | <Int>)>' 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:9,代码来源:test_base.py

示例8: test_key_return_original_name_on_error

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_key_return_original_name_on_error(self):
        res = list(t.Key(name='test', to_name='tost', trafaret=t.Int())({'test': 'a'}))[0]
        assert res[0] == 'test'  # must be original key name
        assert isinstance(res[1], DataError) 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:6,代码来源:test_keys.py

示例9: test_int

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def test_int(self):
        assert construct(int).check(5) == 5
        assert isinstance(construct(int), t.Int) 
开发者ID:Deepwalker,项目名称:trafaret,代码行数:5,代码来源:test_constructor.py

示例10: __init__

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def __init__(self, allow_extra):
        self.schema = t.Dict({
            'id': t.Int(),
            'client_name': t.String(max_length=255),
            'sort_index': t.Float,
            # t.Key('client_email', optional=True): t.Or(t.Null | t.Email()),
            t.Key('client_phone', optional=True): t.Or(t.Null | t.String(max_length=255)),

            t.Key('location', optional=True): t.Or(t.Null | t.Dict({
                'latitude': t.Or(t.Float | t.Null),
                'longitude': t.Or(t.Float | t.Null),
            })),

            t.Key('contractor', optional=True): t.Or(t.Null | t.Int(gt=0)),
            t.Key('upstream_http_referrer', optional=True): t.Or(t.Null | t.String(max_length=1023)),
            t.Key('grecaptcha_response'): t.String(min_length=20, max_length=1000),

            t.Key('last_updated', optional=True): t.Or(t.Null | t.String >> parse),

            t.Key('skills', default=[]): t.List(t.Dict({
                'subject': t.String,
                'subject_id': t.Int,
                'category': t.String,
                'qual_level': t.String,
                'qual_level_id': t.Int,
                t.Key('qual_level_ranking', default=0): t.Float,
            })),
        })
        if allow_extra:
            self.schema.allow_extra('*') 
开发者ID:samuelcolvin,项目名称:pydantic,代码行数:32,代码来源:test_trafaret.py

示例11: download_with_token

# 需要导入模块: import trafaret [as 别名]
# 或者: from trafaret import Int [as 别名]
def download_with_token(request) -> web.StreamResponse:
    try:
        secret = request.app['config']['manager']['secret']
        token = request.query.get('token', '')
        params = jwt.decode(token, secret, algorithms=['HS256'])
    except jwt.PyJWTError:
        log.exception('jwt error while parsing "{}"', token)
        raise InvalidAPIParameters('Could not validate the download token.')

    iv = t.Dict({
        t.Key('file'): t.String,
        t.Key('host'): t.String,
        t.Key('id'): t.String,
        t.Key('exp'): t.Int,
        t.Key('archive', default=False): t.Bool | t.Null,
    })
    params = iv.check(params)
    fn = params['file']
    log.info('VFOLDER.DOWNLOAD_WITH_TOKEN (token:{}, path:{})', token, fn)
    dbpool = request.app['dbpool']
    async with dbpool.acquire() as conn:
        query = (sa.select([vfolders.c.unmanaged_path])
                   .select_from(vfolders)
                   .where(vfolders.c.id == params['id'])
                   .limit(1))
        unmanaged_path = await conn.scalar(query)
        if unmanaged_path:
            folder_path = Path(unmanaged_path)
        else:
            folder_path = (request.app['VFOLDER_MOUNT'] / params['host'] /
                           request.app['VFOLDER_FSPREFIX'] / params['id'])
    try:
        file_path = (folder_path / fn).resolve()
        file_path.relative_to(folder_path)
        if not file_path.exists():
            raise FileNotFoundError
    except (ValueError, FileNotFoundError):
        raise InvalidAPIParameters('The file is not found.')
    if not file_path.is_file():
        if params['archive']:
            # Download directory as an archive when archive param is set.
            return await download_directory_as_archive(request, file_path)
        else:
            raise InvalidAPIParameters('The file is not a regular file.')
    if request.method == 'HEAD':
        return web.Response(status=200, headers={
            hdrs.ACCEPT_RANGES: 'bytes',
            hdrs.CONTENT_LENGTH: str(file_path.stat().st_size),
        })
    ascii_filename = file_path.name.encode('ascii', errors='ignore').decode('ascii').replace('"', r'\"')
    encoded_filename = urllib.parse.quote(file_path.name, encoding='utf-8')
    return web.FileResponse(file_path, headers={
        hdrs.CONTENT_TYPE: "application/octet-stream",
        hdrs.CONTENT_DISPOSITION: " ".join([
            "attachment;"
            f"filename=\"{ascii_filename}\";",       # RFC-2616 sec2.2
            f"filename*=UTF-8''{encoded_filename}",  # RFC-5987
        ])
    }) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:61,代码来源:vfolder.py


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