本文整理汇总了Python中models.PageOperationMixin.parse_data方法的典型用法代码示例。如果您正苦于以下问题:Python PageOperationMixin.parse_data方法的具体用法?Python PageOperationMixin.parse_data怎么用?Python PageOperationMixin.parse_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.PageOperationMixin
的用法示例。
在下文中一共展示了PageOperationMixin.parse_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_new_content
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_data [as 别名]
def validate_new_content(self, base_revision, new_body, user):
# check metadata
new_md = PageOperationMixin.parse_metadata(new_body)
## prevent self-revoke
acl_r = new_md.get('read', '')
acl_r = acl_r.split(',') if acl_r else []
acl_w = new_md.get('write', '')
acl_w = acl_w.split(',') if acl_w else []
if not self.can_read(user, acl_r=acl_r, acl_w=acl_w):
raise ValueError('Cannot restrict your permission')
if not self.can_write(user, acl_r=acl_r, acl_w=acl_w):
raise ValueError('Cannot restrict your permission')
## prevent circular-redirection
try:
WikiPage._follow_redirect(self, new_md.get(u'redirect'))
except ValueError as e:
raise e
# check data
new_data = PageOperationMixin.parse_data(self.title, new_body, new_md['schema'])
if any(type(value) == schema.InvalidProperty for value in new_data.values()):
raise ValueError('Invalid schema data')
# check revision
if self.revision < base_revision:
raise ValueError('Invalid revision number: %d' % base_revision)
# check headings
if not TocGenerator(md.convert(new_body)).validate():
raise ValueError("Duplicate paths not allowed")
return new_data, new_md
示例2: test_multiple_authors
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_data [as 别名]
def test_multiple_authors(self):
data = PageOperationMixin.parse_data(u'Hello', u'[[author::AK]] and [[author::TK]]', u'Book')
self.assertEqual([u'AK', u'TK'], [v.pvalue for v in data['author']])
示例3: test_author_and_isbn
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_data [as 别名]
def test_author_and_isbn(self):
data = PageOperationMixin.parse_data(u'Hello', u'[[author::AK]]\n{{isbn::1234567890}}', u'Book')
self.assertEqual(u'AK', data['author'].pvalue)
self.assertEqual(u'1234567890', data['isbn'].pvalue)
示例4: test_no_data
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_data [as 别名]
def test_no_data(self):
data = PageOperationMixin.parse_data(u'Hello', u'Hello')
self.assertEqual(['articleBody', 'name', 'schema'], data.keys())
self.assertEqual(u'Hello', data['name'].pvalue)
self.assertEqual(u'Thing/CreativeWork/Article/', data['schema'].pvalue)
self.assertEqual(u'Hello', data['articleBody'].pvalue)