本文整理汇总了Python中wagtail.wagtailcore.whitelist.attribute_rule函数的典型用法代码示例。如果您正苦于以下问题:Python attribute_rule函数的具体用法?Python attribute_rule怎么用?Python attribute_rule使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了attribute_rule函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whitelister_element_rules
def whitelister_element_rules():
return {
# Commenting out disallowed tags so its easier to remember & revert
'a': attribute_rule({'href': check_url}),
'b': allow_without_attributes,
# 'br': allow_without_attributes,
# 'div': allow_without_attributes,
'em': allow_without_attributes,
'h1': allow_without_attributes,
'h2': allow_without_attributes,
'h3': allow_without_attributes,
'h4': allow_without_attributes,
'h5': allow_without_attributes,
'h6': allow_without_attributes,
'hr': allow_without_attributes,
'i': allow_without_attributes,
'img': attribute_rule({'src': check_url, 'width': True, 'height': True,
'alt': True}),
'li': allow_without_attributes,
'ol': allow_without_attributes,
'p': allow_without_attributes,
'strong': allow_without_attributes,
'sub': allow_without_attributes,
'sup': allow_without_attributes,
'ul': allow_without_attributes,
}
示例2: whitelister_element_rules
def whitelister_element_rules():
return {
'p': attribute_rule({'class': True}),
'a': attribute_rule({'href': check_url, 'id': True, 'class': True}),
'span': attribute_rule({'class': True}),
'i': attribute_rule({'class': True}),
'iframe': attribute_rule({'id': True, 'class': True, 'src': True, 'style': True, 'frameborder': True, 'allowfullscreen': True, 'width': True, 'height': True }),
}
示例3: whitelister_element_rules
def whitelister_element_rules():
return {
'h2': attribute_rule({'style': True}),
'h3': attribute_rule({'style': True}),
'h4': attribute_rule({'style': True}),
'h5': attribute_rule({'style': True}),
'p': attribute_rule({'style': True}),
}
示例4: whitelister_element_rules
def whitelister_element_rules():
return {
'iframe': attribute_rule(ALLTAGS),
'object': attribute_rule(ALLTAGS),
'script': attribute_rule(ALLTAGS),
'style': attribute_rule(ALLTAGS),
'embed': attribute_rule(ALLTAGS),
'src': attribute_rule(ALLTAGS),
'video': attribute_rule(ALLTAGS),
'div': attribute_rule(ALLTAGS),
'noscript': attribute_rule(ALLTAGS),
'param': attribute_rule(ALLTAGS),
}
示例5: whitelister_element_rules
def whitelister_element_rules():
"""
Whitelist custom elements to the hallo.js editor
"""
return {
'blockquote': allow_without_attributes,
'cite': allow_without_attributes,
'a': attribute_rule({'href': check_url, 'class': True}),
'h2': attribute_rule({'id': True}),
'h3': attribute_rule({'id': True}),
'h4': attribute_rule({'id': True}),
'h5': attribute_rule({'id': True}),
}
示例6: allow_iframes
def allow_iframes():
return {
'iframe': attribute_rule(
{
'src': True,
'width': True,
'height': True,
'frameborder': True,
'marginheight': True,
'marginwidth': True
}),
'tito-widget': attribute_rule({'event': True}),
'tito-button': attribute_rule({'event': True}),
}
示例7: whitelister_element_rules
def whitelister_element_rules():
"""
Whitelist custom elements to the hallo.js editor
"""
return {
'a': attribute_rule({'href': check_url, 'class': True}),
}
示例8: whitelister_element_rules
def whitelister_element_rules():
allow_html_class = attribute_rule({'class': True})
allowed_tags = ['aside', 'table', 'tr', 'th', 'td', 'tbody', 'thead',
'tfoot', 'col', 'colgroup']
return {tag: allow_html_class for tag in allowed_tags}
示例9: test_rule_false_for_attr
def test_rule_false_for_attr(self):
"""
Test that attribute_rule() drops atrributes
when the corresponding rule returns False
"""
tag = self.soup.b
fn = attribute_rule({'foo': False})
fn(tag)
self.assertEqual(str(tag), '<b>baz</b>')
示例10: test_rule_true_for_attr
def test_rule_true_for_attr(self):
"""
Test that attribute_rule() does not change atrributes
when the corresponding rule returns True
"""
tag = self.soup.b
fn = attribute_rule({'foo': True})
fn(tag)
self.assertEqual(str(tag), '<b foo="bar">baz</b>')
示例11: test_no_rule_for_attr
def test_no_rule_for_attr(self):
"""
Test that attribute_rule() drops attributes for
which no rule has been defined.
"""
tag = self.soup.b
fn = attribute_rule({'snowman': 'barbecue'})
fn(tag)
self.assertEqual(str(tag), '<b>baz</b>')
示例12: whitelister_element_rules
def whitelister_element_rules():
return {
'blockquote': allow_without_attributes,
'code': allow_without_attributes,
'table': allow_without_attributes,
'tr': allow_without_attributes,
'td': allow_without_attributes,
'pre': attribute_rule({'class': True}),
}
示例13: test_callable_returns_None
def test_callable_returns_None(self):
"""
Test that when the rule returns a callable,
attribute_rule() replaces the attribute with
the result of calling the callable on the attribute.
"""
tag = self.soup.b
fn = attribute_rule({'foo': lambda x: None})
fn(tag)
self.assertEqual(str(tag), '<b>baz</b>')
示例14: test_callable_called_on_attr
def test_callable_called_on_attr(self):
"""
Test that when the rule returns a callable,
attribute_rule() replaces the attribute with
the result of calling the callable on the attribute.
"""
tag = self.soup.b
fn = attribute_rule({'foo': len})
fn(tag)
self.assertEqual(str(tag), '<b foo="3">baz</b>')
示例15: allow_iframes
def allow_iframes():
return {
'iframe': attribute_rule(
{
'src': True,
'width': True,
'height': True,
'frameborder': True,
'marginheight': True,
'marginwidth': True
})
}