How to use the markupsafe._compat.text_type function in MarkupSafe

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 splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / markupsafe / tests.py View on Github external
def test_adding(self):
        # adding two strings should escape the unsafe one
        unsafe = ''
        safe = Markup('<em>username</em>')
        assert unsafe + safe == text_type(escape(unsafe)) + text_type(safe)
github splunk / splunk-ref-pas-test / pas_simulated_users_addon / user-api / lib / markupsafe / _native.py View on Github external
def escape(s):
    """Convert the characters &amp;, &lt;, &gt;, ' and " in string s to HTML-safe
    sequences.  Use this if you need to display text that might contain
    such characters in HTML.  Marks return value as markup string.
    """
    if hasattr(s, '__html__'):
        return s.__html__()
    return Markup(text_type(s)
        .replace('&amp;', '&amp;')
        .replace('&gt;', '&gt;')
        .replace('&lt;', '&lt;')
        .replace("'", ''')
        .replace('"', '"')
    )
github googlearchive / appengine-flask-skeleton / lib / markupsafe / _native.py View on Github external
def soft_unicode(s):
    """Make a string unicode if it isn't already.  That way a markup
    string is not converted back to unicode.
    """
    if not isinstance(s, text_type):
        s = text_type(s)
    return s
github wwqgtxx / wwqLyParse / wwqLyParse / lib / flask_lib / markupsafe / __init__.py View on Github external
def __new__(cls, base=u'', encoding=None, errors='strict'):
        if hasattr(base, '__html__'):
            base = base.__html__()
        if encoding is None:
            return text_type.__new__(cls, base)
        return text_type.__new__(cls, base, encoding, errors)
github alangpierce / appengine-python3 / lib / markupsafe-0.23 / markupsafe / __init__.py View on Github external
def format_field(self, value, format_spec):
            if hasattr(value, '__html_format__'):
                rv = value.__html_format__(format_spec)
            elif hasattr(value, '__html__'):
                if format_spec:
                    raise ValueError('No format specification allowed '
                                     'when formatting an object with '
                                     'its __html__ method.')
                rv = value.__html__()
            else:
                rv = string.Formatter.format_field(self, value, format_spec)
            return text_type(self.escape(rv))
github libfirm / libfirm / scripts / markupsafe / __init__.py View on Github external
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))
                elif name.startswith('#'):
                    return unichr(int(name[1:]))
            except ValueError:
                pass
            return u''
        return _entity_re.sub(handle_match, text_type(self))
github googlearchive / appengine-flask-skeleton / lib / markupsafe / _native.py View on Github external
def soft_unicode(s):
    """Make a string unicode if it isn't already.  That way a markup
    string is not converted back to unicode.
    """
    if not isinstance(s, text_type):
        s = text_type(s)
    return s
github trailofbits / cb-multios / cqe-challenges / NRFIN_00007 / support / mixcodegen / markupsafe / __init__.py View on Github external
def format_field(self, value, format_spec):
            if hasattr(value, '__html_format__'):
                rv = value.__html_format__(format_spec)
            elif hasattr(value, '__html__'):
                if format_spec:
                    raise ValueError('No format specification allowed '
                                     'when formatting an object with '
                                     'its __html__ method.')
                rv = value.__html__()
            else:
                rv = string.Formatter.format_field(self, value, format_spec)
            return text_type(self.escape(rv))
github libfirm / libfirm / scripts / markupsafe / _native.py View on Github external
def escape(s):
    """Convert the characters &amp;, &lt;, &gt;, ' and " in string s to HTML-safe
    sequences.  Use this if you need to display text that might contain
    such characters in HTML.  Marks return value as markup string.
    """
    if hasattr(s, '__html__'):
        return s.__html__()
    return Markup(text_type(s)
        .replace('&amp;', '&amp;')
        .replace('&gt;', '&gt;')
        .replace('&lt;', '&lt;')
        .replace("'", ''')
        .replace('"', '"')
    )