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


Python colander.SchemaNode方法代码示例

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


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

示例1: test_required

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_required(self):
        class Mapping(colander.MappingSchema):
            foo = colander.SchemaNode(colander.String())

        node = Mapping()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
            'properties': {
                'foo': {
                    'title': 'Foo',
                    'type': 'string'
                }
            },
            'required': ['foo']
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:18,代码来源:test_schema.py

示例2: test_not_required

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_not_required(self):
        class Mapping(colander.MappingSchema):
            foo = colander.SchemaNode(colander.String(),
                                      missing=colander.drop)

        node = Mapping()
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'object',
            'properties': {
                'foo': {
                    'title': 'Foo',
                    'type': 'string'
                }
            },
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:18,代码来源:test_schema.py

示例3: from_path

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def from_path(self, path):
        """
        Create a list of Swagger path params from a cornice service path.

        :type path: string
        :rtype: list
        """
        path_components = path.split('/')
        param_names = [comp[1:-1] for comp in path_components
                       if comp.startswith('{') and comp.endswith('}')]

        params = []
        for name in param_names:
            param_schema = colander.SchemaNode(colander.String(), name=name)
            param = self.parameter_converter('path', param_schema)
            if self.ref:
                param = self._ref(param)
            params.append(param)

        return params 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:22,代码来源:swagger.py

示例4: create

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def create():
    require.dataset.create()
    dataset = request_data()
    data = validate_dataset(dataset)
    if Dataset.by_name(data['name']) is not None:
        raise Invalid(SchemaNode(String(), name='name'),
                      _("A dataset with this identifer already exists!"))
    dataset = Dataset({'dataset': data, 'model': {}})
    dataset.managers.append(current_user)
    db.session.add(dataset)
    db.session.commit()
    return view(dataset.name) 
开发者ID:openspending,项目名称:spendb,代码行数:14,代码来源:dataset.py

示例5: define_date_node

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def define_date_node(schema):
    schema['vote'] = colander.SchemaNode(
            colander.DateTime(),
            widget=deform.widget.DateTimeInputWidget(),
            validator=colander.Range(min=datetime.datetime.now(tz=pytz.UTC),
                min_err=_('${val} is earlier than earliest datetime ${min}')),
            title=_('Date')
            ) 
开发者ID:ecreall,项目名称:nova-ideo,代码行数:10,代码来源:vote.py

示例6: test_path

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_path(self):
        node = colander.SchemaNode(colander.String(), name='foo')
        ret = convert_parameter('path', node)
        self.assertDictEqual(ret, {
            'in': 'path',
            'name': 'foo',
            'type': 'string',
            'required': True,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:11,代码来源:test_parameters.py

示例7: test_query

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_query(self):
        node = colander.SchemaNode(colander.String(), name='bar')
        ret = convert_parameter('querystring', node)
        self.assertDictEqual(ret, {
            'in': 'query',
            'name': 'bar',
            'type': 'string',
            'required': True,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:11,代码来源:test_parameters.py

示例8: test_query_array

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_query_array(self):

        class MyArray(colander.SequenceSchema):
            values = colander.SchemaNode(colander.String())

        node = MyArray(name='bar')
        ret = convert_parameter('querystring', node)
        self.assertDictEqual(ret, {
            'in': 'query',
            'name': 'bar',
            'type': 'array',
            'items': {'type': 'string'},
            'required': True,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:16,代码来源:test_parameters.py

示例9: test_header

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_header(self):
        node = colander.SchemaNode(colander.String(), name='meh')
        ret = convert_parameter('headers', node)
        self.assertDictEqual(ret, {
            'in': 'header',
            'name': 'meh',
            'type': 'string',
            'required': True,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:11,代码来源:test_parameters.py

示例10: test_body_array

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_body_array(self):

        class MyArray(colander.SequenceSchema):
            values = colander.SchemaNode(colander.String())

        node = MyArray(name='bla')
        ret = convert_parameter('body', node)
        self.assertDictEqual(ret, {
            'in': 'body',
            'name': 'bla',
            'required': True,
            'schema': convert_schema(MyArray(title='MyArray')),
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:15,代码来源:test_parameters.py

示例11: test_supports_description

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_supports_description(self):
        node = colander.SchemaNode(colander.String(), name='bar', description='tyred')
        ret = convert_parameter('querystring', node)
        self.assertDictEqual(ret, {
            'in': 'query',
            'name': 'bar',
            'type': 'string',
            'required': True,
            'description': 'tyred',
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:12,代码来源:test_parameters.py

示例12: test_raise_no_such_converter_on_invalid_location

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_raise_no_such_converter_on_invalid_location(self):
        node = colander.SchemaNode(colander.String(), name='foo')
        self.assertRaises(NoSuchConverter, convert_parameter, 'aaa', node) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:5,代码来源:test_parameters.py

示例13: test_validate_all

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_validate_all(self):
        node = colander.SchemaNode(colander.String(),
                                   validator=colander.All(
                                       colander.Length(12, 42),
                                       colander.Regex(r'foo*bar')
                                   ))
        ret = convert(node)
        self.assertDictEqual(ret, {
            'type': 'string',
            'pattern': 'foo*bar',
            'maxLength': 42,
            'minLength': 12,
        }) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:15,代码来源:test_schema.py

示例14: test_support_custom_converters

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_support_custom_converters(self):
        node = colander.SchemaNode(AnyType())
        custom_converters = {AnyType: AnyTypeConverter}
        converter = TypeConversionDispatcher(custom_converters)
        ret = converter(node)
        self.assertEquals(ret, {}) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:8,代码来源:test_schema.py

示例15: test_support_default_converter

# 需要导入模块: import colander [as 别名]
# 或者: from colander import SchemaNode [as 别名]
def test_support_default_converter(self):
        node = colander.SchemaNode(AnyType())
        converter = TypeConversionDispatcher(default_converter=AnyTypeConverter)
        ret = converter(node)
        self.assertEquals(ret, {}) 
开发者ID:Cornices,项目名称:cornice.ext.swagger,代码行数:7,代码来源:test_schema.py


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