How to use MarkupSafe - 10 common examples

To help you get started, we’ve selected a few MarkupSafe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libfirm / libfirm / scripts / markupsafe / tests.py View on Github external
def test_splitting(self):
        self.assertEqual(Markup('a b').split(), [
            Markup('a'),
            Markup('b')
        ])
        self.assertEqual(Markup('a b').rsplit(), [
            Markup('a'),
            Markup('b')
        ])
        self.assertEqual(Markup('a\nb').splitlines(), [
            Markup('a'),
            Markup('b')
        ])
github rethinkdb / rethinkdb / test / common / http_support / markupsafe / tests.py View on Github external
def test_splitting(self):
        self.assertEqual(Markup('a b').split(), [
            Markup('a'),
            Markup('b')
        ])
        self.assertEqual(Markup('a b').rsplit(), [
            Markup('a'),
            Markup('b')
        ])
        self.assertEqual(Markup('a\nb').splitlines(), [
            Markup('a'),
            Markup('b')
        ])
github rethinkdb / rethinkdb / test / common / http_support / markupsafe / __init__.py View on Github external
def rsplit(self, *args, **kwargs):
        return list(map(self.__class__, text_type.rsplit(self, *args, **kwargs)))
    rsplit.__doc__ = text_type.rsplit.__doc__
github splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / markupsafe / __init__.py View on Github external
def split(self, *args, **kwargs):
        return list(map(self.__class__, text_type.split(self, *args, **kwargs)))
    split.__doc__ = text_type.split.__doc__
github rethinkdb / rethinkdb / test / common / http_support / markupsafe / __init__.py View on Github external
def join(self, seq):
        return self.__class__(text_type.join(self, map(self.escape, seq)))
    join.__doc__ = text_type.join.__doc__

    def split(self, *args, **kwargs):
        return list(map(self.__class__, text_type.split(self, *args, **kwargs)))
    split.__doc__ = text_type.split.__doc__

    def rsplit(self, *args, **kwargs):
        return list(map(self.__class__, text_type.rsplit(self, *args, **kwargs)))
    rsplit.__doc__ = text_type.rsplit.__doc__

    def splitlines(self, *args, **kwargs):
        return list(map(self.__class__, text_type.splitlines(
            self, *args, **kwargs)))
    splitlines.__doc__ = text_type.splitlines.__doc__

    def unescape(self):
        r"""Unescape markup again into an text_type string.  This also resolves
        known HTML4 and XHTML entities:

        &gt;&gt;&gt; Markup("Main » <em>About</em>").unescape()
        u'Main \xbb <em>About</em>'
        """
        from markupsafe._constants import HTML_ENTITIES
        def handle_match(m):
            name = m.group(1)
            if name in HTML_ENTITIES:
                return unichr(HTML_ENTITIES[name])
            try:
                if name[:2] in ('#x', '#X'):
                    return unichr(int(name[2:], 16))
github libfirm / libfirm / scripts / markupsafe / tests.py View on Github external
def test_formatting(self):
        for actual, expected in (
            (Markup('%i') % 3.14, '3'),
            (Markup('%.2f') % 3.14159, '3.14'),
            (Markup('%s %s %s') % ('&lt;', 123, '&gt;'), '&lt; 123 &gt;'),
            (Markup('<em>{awesome}</em>').format(awesome=''),
             '<em>&lt;awesome&gt;</em>'),
            (Markup('{0[1][bar]}').format([0, {'bar': ''}]),
             '&lt;bar/&gt;'),
            (Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
             '')):
            assert actual == expected, "%r should be %r!" % (actual, expected)
github NetEase / airtest / airtest / log2html.py View on Github external
# Read log line by line
    from . import proto
    records = []
    for line in open(logfile):
        v = json.loads(line)
        r = {'time': time.strftime(TIME_FORMAT, time.localtime(v.get('timestamp')))}
        d = v.get('data', {})
        tag = v.get('tag')

        # Process Function, Snapshot, Memory, CPU ...
        if tag == proto.TAG_FUNCTION:
            tag = markupsafe.Markup('function')    
            args = map(json.dumps, d.get('args'))
            kwargs = [ '%s=%s' %(k, json.dumps(_v)) for k, _v in d.get('kwargs', {}).items() ]
            message = '<code style="color:green">%s(%s)</code>' %(d.get('name'), ', '.join(args+kwargs))
            message = markupsafe.Markup(message)
        elif tag == proto.TAG_SNAPSHOT:
            message = markupsafe.Markup("<img src="%s" width="100%%">" % d.get('filename'))
        elif tag == proto.TAG_CPU:
            message = '%d%%' %(d)
            cpus.append([r, d])
        elif tag == proto.TAG_MEMORY:
            mems.append([r, d['PSS']])
            message = json.dumps(d)
        else:
            message = None
        
        if message:
            r['tag'] = tag
            r['message'] = message
            records.append(r)
github splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / markupsafe / tests.py View on Github external
def test_formatting(self):
        for actual, expected in (
            (Markup('%i') % 3.14, '3'),
            (Markup('%.2f') % 3.14159, '3.14'),
            (Markup('%s %s %s') % ('&lt;', 123, '&gt;'), '&lt; 123 &gt;'),
            (Markup('<em>{awesome}</em>').format(awesome=''),
             '<em>&lt;awesome&gt;</em>'),
            (Markup('{0[1][bar]}').format([0, {'bar': ''}]),
             '&lt;bar/&gt;'),
            (Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
             '')):
            assert actual == expected, "%r should be %r!" % (actual, expected)
github libfirm / libfirm / scripts / markupsafe / tests.py View on Github external
def test_formatting(self):
        for actual, expected in (
            (Markup('%i') % 3.14, '3'),
            (Markup('%.2f') % 3.14159, '3.14'),
            (Markup('%s %s %s') % ('&lt;', 123, '&gt;'), '&lt; 123 &gt;'),
            (Markup('<em>{awesome}</em>').format(awesome=''),
             '<em>&lt;awesome&gt;</em>'),
            (Markup('{0[1][bar]}').format([0, {'bar': ''}]),
             '&lt;bar/&gt;'),
            (Markup('{0[1][bar]}').format([0, {'bar': Markup('')}]),
             '')):
            assert actual == expected, "%r should be %r!" % (actual, expected)