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