當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。