本文整理汇总了Python中models.PageOperationMixin.parse_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python PageOperationMixin.parse_metadata方法的具体用法?Python PageOperationMixin.parse_metadata怎么用?Python PageOperationMixin.parse_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.PageOperationMixin
的用法示例。
在下文中一共展示了PageOperationMixin.parse_metadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_new_content
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_metadata [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_normal
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_metadata [as 别名]
def test_normal(self):
expected = {
u'hello': u'a b c',
u'x': None,
u'z': u'what?',
}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'.hello a b c\n.x\n.z what?\nblahblah')
self.assertEqual(expected, actual)
示例3: test_no_metadata
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_metadata [as 别名]
def test_no_metadata(self):
expected = {}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'Hello\nThere')
self.assertEqual(expected, actual)
示例4: test_empty_string
# 需要导入模块: from models import PageOperationMixin [as 别名]
# 或者: from models.PageOperationMixin import parse_metadata [as 别名]
def test_empty_string(self):
expected = {}
expected.update(self.default_md)
actual = PageOperationMixin.parse_metadata(u'')
self.assertEqual(expected, actual)