本文整理汇总了Python中flatland.List.of方法的典型用法代码示例。如果您正苦于以下问题:Python List.of方法的具体用法?Python List.of怎么用?Python List.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flatland.List
的用法示例。
在下文中一共展示了List.of方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_set():
schema = List.of(Integer)
el = schema()
assert list(el) == []
el = schema()
assert not el.set(1)
assert el.value == []
el = schema()
assert not el.set(None)
assert el.value == []
el = schema()
assert el.set(range(3))
assert el.value == [0, 1, 2]
el = schema()
assert el.set(xrange(3))
assert el.value == [0, 1, 2]
el = schema([0, 1, 2])
assert el.value == [0, 1, 2]
el = schema()
el.extend([1, 2, 3])
assert el.value == [1, 2, 3]
el.set([4, 5, 6])
assert el.value == [4, 5, 6]
assert el.set([])
assert el.value == []
示例2: test_set_flat_doubly_anonymous_dict
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_set_flat_doubly_anonymous_dict():
pairs = ((u'0_x', u'x0'), (u'0_y', u'y0'),
(u'1_x', u'x1'), (u'1_y', u'y1'),
(u'2_x', u'x2'), )
schema = List.of(String.named(u'x'), String.named(u'y'))
el = schema.from_flat(pairs)
eq_(len(el), 3)
eq_(el[0].value, dict((k[-1], v) for k, v in pairs[0:2]))
eq_(el[1].value, dict((k[-1], v) for k, v in pairs[2:4]))
eq_(el[2].value, {u'x': u'x2', u'y': None})
示例3: test_corrupt_all_children
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_corrupt_all_children():
# Ensure all_children won't spin out if the graph becomes cyclic.
schema = List.of(String)
el = schema()
el.append(String(u'x'))
el.append(String(u'y'))
dupe = String(u'z')
el.append(dupe)
el.append(dupe)
assert list(_.value for _ in el.children) == list(u'xyzz')
assert list(_.value for _ in el.all_children) == list(u'xyz')
示例4: test_raw
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_raw():
schema = List.of(Integer)
el = schema()
assert el.raw is Unset
el = schema(u'foo')
assert el.raw == u'foo'
el = schema([1, 2, 3])
assert el.raw == [1, 2, 3]
el = schema((1, 2, 3))
assert el.raw == (1, 2, 3)
el = schema({u'x': u'bar'})
assert el.raw == {u'x': u'bar'}
示例5: utctimestamp
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
# XXX forces circular dependency when it is in the head import block
from MoinMoin.themes import utctimestamp
# TODO: Add support for timezones
dt = utctimestamp(dt)
return dt
DateTime = (DateTimeUNIX.with_properties(widget=WIDGET_DATETIME,
placeholder=_("YYYY-MM-DD HH:MM:SS (example: 2013-12-31 23:59:59)"))
.validated_by(Converted(incorrect=L_("Please use the following format: YYYY-MM-DD HH:MM:SS"))))
File = FileStorage.with_properties(widget=WIDGET_FILE)
Hidden = String.using(optional=True).with_properties(widget=WIDGET_HIDDEN)
# optional=True is needed to get rid of the "required field" indicator on the UI (usually an asterisk)
ReadonlyStringList = List.of(String).using(optional=True).with_properties(widget=WIDGET_READONLY_STRING_LIST)
ReadonlyItemLinkList = ReadonlyStringList.with_properties(widget=WIDGET_READONLY_ITEM_LINK_LIST)
# XXX When some user chooses a Reference candidate that is removed before the
# user POSTs, the validator fails. This can be confusing.
class ValidReference(Validator):
"""
Validator for Reference
"""
invalid_reference_msg = L_('Invalid Reference.')
def validate(self, element, state):
if element.value not in element.valid_values:
return self.note_error(element, state, 'invalid_reference_msg')
示例6: Bundle
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
class Bundle(Import):
def adapt(self, value):
return Import.adapt(self,
'glashammer.bundles.%s.setup_%s' % (value, value))
Url = Dict.of(
String.named('url'),
String.named('endpoint'),
Import.named('view').using(optional=True),
)
Urls = List.of(Url)
Config = Dict.named('config').of(Dict)
Settings = Dict.of(Element)
TemplateSearchPaths = List.of(String)
TemplateFilter = Dict.of(
Import.named('filter'),
String.named('name'),
)
TemplateFilters = List.of(TemplateFilter)
SharedPath = Dict.of(
示例7: test_set_flat_anon_list_named_child
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_set_flat_anon_list_named_child():
schema = List.of(String.named(u's'))
pairs = [(u'0_s', u'abc'), (u'1_s', u'def')]
bogus = [(u's', u'xxx'), (u'0', u'yyy')]
_assert_set_flat(schema, pairs, bogus)
示例8: test_value
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_value():
schema = List.of(String)
el = schema([u'x', u'x'])
eq_(el.value, [u'x', u'x'])
示例9: test_u
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_u():
schema = List.of(String)
el = schema([u'x', u'x'])
eq_(el.u, u"[u'x', u'x']")
示例10: test_set_flat_fully_anonymous
# 需要导入模块: from flatland import List [as 别名]
# 或者: from flatland.List import of [as 别名]
def test_set_flat_fully_anonymous():
schema = List.of(String)
pairs = [(u'0', u'abc'), (u'1', u'def')]
bogus = [(u'x', u'xxx')]
_assert_set_flat(schema, pairs, bogus)