本文整理汇总了Python中txaws.server.schema.Schema.extract方法的典型用法代码示例。如果您正苦于以下问题:Python Schema.extract方法的具体用法?Python Schema.extract怎么用?Python Schema.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txaws.server.schema.Schema
的用法示例。
在下文中一共展示了Schema.extract方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_extract_complex
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_complex(self):
"""L{Schema} can cope with complex schemas."""
schema = Schema(
Unicode("GroupName"),
RawStr("IpPermissions.n.IpProtocol"),
Integer("IpPermissions.n.FromPort"),
Integer("IpPermissions.n.ToPort"),
Unicode("IpPermissions.n.Groups.m.UserId", optional=True),
Unicode("IpPermissions.n.Groups.m.GroupName", optional=True))
arguments, _ = schema.extract(
{"GroupName": "Foo",
"IpPermissions.1.IpProtocol": "tcp",
"IpPermissions.1.FromPort": "1234",
"IpPermissions.1.ToPort": "5678",
"IpPermissions.1.Groups.1.GroupName": "Bar",
"IpPermissions.1.Groups.2.GroupName": "Egg"})
self.assertEqual(u"Foo", arguments.GroupName)
self.assertEqual(1, len(arguments.IpPermissions))
self.assertEqual(1234, arguments.IpPermissions[0].FromPort)
self.assertEqual(5678, arguments.IpPermissions[0].ToPort)
self.assertEqual(2, len(arguments.IpPermissions[0].Groups))
self.assertEqual("Bar", arguments.IpPermissions[0].Groups[0].GroupName)
self.assertEqual("Egg", arguments.IpPermissions[0].Groups[1].GroupName)
示例2: test_optional_list
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_optional_list(self):
"""
The default value of an optional L{List} is C{[]}.
"""
schema = Schema(List("names", Unicode(), optional=True))
arguments, _ = schema.extract({})
self.assertEqual([], arguments.names)
示例3: test_add_single_extra_schema_item
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_add_single_extra_schema_item(self):
"""New Parameters can be added to the Schema."""
schema = Schema(Unicode("name"))
schema = schema.extend(Unicode("computer"))
arguments, _ = schema.extract({"name": "value", "computer": "testing"})
self.assertEqual(u"value", arguments.name)
self.assertEqual("testing", arguments.computer)
示例4: test_schema_conversion_optional_list
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_schema_conversion_optional_list(self):
"""
Backwards-compatibility conversions maintains optional-ness of lists.
"""
schema = Schema(Unicode("foos.N", optional=True))
arguments, _ = schema.extract({})
self.assertEqual([], arguments.foos)
示例5: test_extract_with_single_numbered
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_single_numbered(self):
"""
L{Schema.extract} can handle a single parameter with a numbered value.
"""
schema = Schema(Unicode("name.n"))
arguments, _ = schema.extract({"name.0": "Joe"})
self.assertEqual("Joe", arguments.name[0])
示例6: test_extract_structure_with_optional
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_structure_with_optional(self):
"""L{Schema.extract} can handle optional parameters."""
schema = Schema(
Structure(
"struct",
fields={"name": Unicode(optional=True, default="radix")}))
arguments, _ = schema.extract({"struct": {}})
self.assertEqual(u"radix", arguments.struct.name)
示例7: test_extract_with_rest
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_rest(self):
"""
L{Schema.extract} stores unknown parameters in the 'rest' return
dictionary.
"""
schema = Schema()
_, rest = schema.extract({"name": "value"})
self.assertEqual(rest, {"name": "value"})
示例8: test_extract
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract(self):
"""
L{Schema.extract} returns an L{Argument} object whose attributes are
the arguments extracted from the given C{request}, as specified.
"""
schema = Schema(Unicode("name"))
arguments, _ = schema.extract({"name": "value"})
self.assertEqual("value", arguments.name)
示例9: test_extract_with_numbered
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_numbered(self):
"""
L{Schema.extract} can handle parameters with numbered values.
"""
schema = Schema(Unicode("name.n"))
arguments, _ = schema.extract({"name.0": "Joe", "name.1": "Tom"})
self.assertEqual("Joe", arguments.name[0])
self.assertEqual("Tom", arguments.name[1])
示例10: test_extract_with_non_numbered_template
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_non_numbered_template(self):
"""
L{Schema.extract} accepts a single numbered argument even if the
associated template is not numbered.
"""
schema = Schema(Unicode("name"))
arguments, _ = schema.extract({"name.1": "foo"})
self.assertEqual("foo", arguments.name)
示例11: test_extract_with_single_numbered
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_single_numbered(self):
"""
L{Schema.extract} can handle an un-numbered argument passed in to a
numbered parameter.
"""
schema = Schema(Unicode("name.n"))
arguments, _ = schema.extract({"name": "Joe"})
self.assertEqual("Joe", arguments.name[0])
示例12: test_extract_with_mixed
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_extract_with_mixed(self):
"""
L{Schema.extract} stores in the rest result all numbered parameters
given without an index.
"""
schema = Schema(Unicode("name.n"))
_, rest = schema.extract({"name": "foo", "name.1": "bar"})
self.assertEqual(rest, {"name": "foo"})
示例13: test_structure
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_structure(self):
"""
L{Schema}s with L{Structure} parameters can have arguments extracted.
"""
schema = Schema(Structure("foo", {"a": Integer(), "b": Integer()}))
arguments, _ = schema.extract({"foo.a": "1", "foo.b": "2"})
self.assertEqual(1, arguments.foo.a)
self.assertEqual(2, arguments.foo.b)
示例14: test_default_list
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_default_list(self):
"""
The default of a L{List} can be specified as a list.
"""
schema = Schema(List("names", Unicode(), optional=True,
default=[u"foo", u"bar"]))
arguments, _ = schema.extract({})
self.assertEqual([u"foo", u"bar"], arguments.names)
示例15: test_add_extra_schema_items
# 需要导入模块: from txaws.server.schema import Schema [as 别名]
# 或者: from txaws.server.schema.Schema import extract [as 别名]
def test_add_extra_schema_items(self):
"""A list of new Parameters can be added to the Schema."""
schema = Schema(Unicode("name"))
schema = schema.extend(Unicode("computer"), Integer("count"))
arguments, _ = schema.extract({"name": "value", "computer": "testing",
"count": "5"})
self.assertEqual(u"value", arguments.name)
self.assertEqual("testing", arguments.computer)
self.assertEqual(5, arguments.count)