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


Python safestring.SafeString方法代码示例

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


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

示例1: test_hasnt_changed

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_hasnt_changed(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
            ])),
        )

        self.assertTrue(comparison.is_field)
        self.assertFalse(comparison.is_child_relation)
        self.assertEqual(comparison.field_label(), "Body")
        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertFalse(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:test_compare.py

示例2: test_has_changed

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_has_changed(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Original content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Modified content", '1'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object"><span class="deletion">Original</span><span class="addition">Modified</span> content</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_compare.py

示例3: test_delete_block

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_delete_block(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
                ('text', "Content Foo", '2'),
                ('text', "Content Bar", '3'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
                ('text', "Content Bar", '3'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>\n<div class="comparison__child-object deletion">Content Foo</div>\n<div class="comparison__child-object">Content Bar</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:test_compare.py

示例4: test_edit_block

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_edit_block(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
                ('text', "Content Foo", '2'),
                ('text', "Content Bar", '3'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Content", '1'),
                ('text', "Content Baz", '2'),
                ('text', "Content Bar", '3'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Content</div>\n<div class="comparison__child-object">Content <span class="deletion">Foo</span><span class="addition">Baz</span></div>\n<div class="comparison__child-object">Content Bar</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:test_compare.py

示例5: test_has_changed_richtext

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_has_changed_richtext(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "<b>Original</b> content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "Modified <i>content</i>", '1'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object"><span class="deletion">Original</span><span class="addition">Modified</span> content</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_compare.py

示例6: test_htmldiff_escapes_value_on_addition

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_escapes_value_on_addition(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Original <em>and unchanged</em> content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "Original <em>and unchanged</em> content", '1'),
                ('text', '<script type="text/javascript">doSomethingBad();</script>', '2'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original &lt;em&gt;and unchanged&lt;/em&gt; content</div>\n<div class="comparison__child-object addition">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_compare.py

示例7: test_htmldiff_richtext_strips_tags_on_addition

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_richtext_strips_tags_on_addition(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "Original <em>and unchanged</em> content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "Original <em>and unchanged</em> content", '1'),
                ('rich_text', 'I <b>really</b> like evil code &gt;_&lt; <script type="text/javascript">doSomethingBad();</script>', '2'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original and unchanged content</div>\n<div class="comparison__child-object addition">I really like evil code &gt;_&lt; doSomethingBad();</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_compare.py

示例8: test_htmldiff_richtext_strips_tags_on_deletion

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_richtext_strips_tags_on_deletion(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "Original <em>and unchanged</em> content", '1'),
                ('rich_text', 'I <b>really</b> like evil code &gt;_&lt; <script type="text/javascript">doSomethingBad();</script>', '2'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "Original <em>and unchanged</em> content", '1'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">Original and unchanged content</div>\n<div class="comparison__child-object deletion">I really like evil code &gt;_&lt; doSomethingBad();</div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_compare.py

示例9: test_compare_structblock

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_compare_structblock(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('product', {'name': 'a packet of rolos', 'price': '75p'}, '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('product', {'name': 'a packet of rolos', 'price': '85p'}, '1'),
            ])),
        )

        expected = """
            <div class="comparison__child-object"><dl>
                <dt>Name</dt>
                <dd>a packet of rolos</dd>
                <dt>Price</dt>
                <dd><span class="deletion">75p</span><span class="addition">85p</span></dd>
            </dl></div>
        """
        self.assertHTMLEqual(comparison.htmldiff(), expected)
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_compare.py

示例10: _cursor

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def _cursor(self):
    if not self._valid_connection():
      kwargs = {'conv': base.django_conversions, 'dsn': None}
      settings_dict = self.settings_dict
      settings_dict.update(settings_dict.get('OPTIONS', {}))
      for settings_key, kwarg, required in _SETTINGS_CONNECT_ARGS:
        value = settings_dict.get(settings_key)
        if value:
          kwargs[kwarg] = value
        elif required:
          raise exceptions.ImproperlyConfigured(
              "You must specify a '%s' for database '%s'" %
              (settings_key, self.alias))
      self.connection = Connect(**kwargs)
      encoders = {safestring.SafeUnicode: self.connection.encoders[unicode],
                  safestring.SafeString: self.connection.encoders[str]}
      self.connection.encoders.update(encoders)
      signals.connection_created.send(sender=self.__class__, connection=self)
    cursor = base.CursorWrapper(self.connection.cursor())
    return cursor 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:22,代码来源:base.py

示例11: test_htmldiff_escapes_value

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_escapes_value(self):
        comparison = self.comparison_class(
            SimplePage._meta.get_field('content'),
            SimplePage(content='Original content'),
            SimplePage(content='<script type="text/javascript">doSomethingBad();</script>'),
        )

        self.assertEqual(comparison.htmldiff(), '<span class="deletion">Original content</span><span class="addition">&lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</span>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:11,代码来源:test_compare.py

示例12: test_from_none_to_value_only_shows_addition

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_from_none_to_value_only_shows_addition(self):
        comparison = self.comparison_class(
            SimplePage._meta.get_field('content'),
            SimplePage(content=None),
            SimplePage(content="Added content")
        )

        self.assertEqual(comparison.htmldiff(), '<span class="addition">Added content</span>')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_compare.py

示例13: test_has_changed_html

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_has_changed_html(self):
        comparison = self.comparison_class(
            SimplePage._meta.get_field('content'),
            SimplePage(content="<b>Original</b> content"),
            SimplePage(content="Modified <i>content</i>"),
        )

        self.assertEqual(comparison.htmldiff(), '<span class="deletion">Original</span><span class="addition">Modified</span> content')
        self.assertIsInstance(comparison.htmldiff(), SafeString)
        self.assertTrue(comparison.has_changed()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_compare.py

示例14: test_htmldiff_escapes_value_on_change

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_escapes_value_on_change(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', "I <b>really</b> like original<i>ish</i> content", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('text', 'I <b>really</b> like evil code <script type="text/javascript">doSomethingBad();</script>', '1'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">I &lt;b&gt;really&lt;/b&gt; like <span class="deletion">original&lt;i&gt;ish&lt;/i&gt; content</span><span class="addition">evil code &lt;script type=&quot;text/javascript&quot;&gt;doSomethingBad();&lt;/script&gt;</span></div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:test_compare.py

示例15: test_htmldiff_richtext_strips_tags_on_change

# 需要导入模块: from django.utils import safestring [as 别名]
# 或者: from django.utils.safestring import SafeString [as 别名]
def test_htmldiff_richtext_strips_tags_on_change(self):
        field = StreamPage._meta.get_field('body')

        comparison = self.comparison_class(
            field,
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', "I <b>really</b> like Wagtail &lt;3", '1'),
            ])),
            StreamPage(body=StreamValue(field.stream_block, [
                ('rich_text', 'I <b>really</b> like evil code &gt;_&lt; <script type="text/javascript">doSomethingBad();</script>', '1'),
            ])),
        )

        self.assertEqual(comparison.htmldiff(), '<div class="comparison__child-object">I really like <span class="deletion">Wagtail &lt;3</span><span class="addition">evil code &gt;_&lt; doSomethingBad();</span></div>')
        self.assertIsInstance(comparison.htmldiff(), SafeString) 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:test_compare.py


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