Ejemplo n.º 1
0
def html_escape(text, formatting=False, replace_whitespace=True):
    if not formatting and not replace_whitespace:
        return _html_escape_no_formatting_no_whitespace_replace(text)
    text = unic(text)
    formatter = _HtmlStringFormatter(formatting, replace_whitespace)
    for line in text.splitlines():
        formatter.add(line)
    return formatter.result()
    def write_data(self, data, encoding=None, port_locator=None):
        """
        Writes data into the port.

        If data is a Python's byte string object, it will be written
        to the port intact. If data is unicode string, it will be
        encoded with given encoding before writing. Otherwise,
        data is converted to unicode and processed same as unicode string.
        """
        if not isinstance(data, unicode_):
            data = unic(data)
        if isinstance(data, unicode_):
            data = self._encode(data, encoding)
        self._port(port_locator).write(data)
    def write_data(self, data, encoding=None, port_locator=None):
        """
        Writes data into the port.

        If data is a Python's byte string object, it will be written
        to the port intact. If data is unicode string, it will be
        encoded with given encoding before writing. Otherwise,
        data is converted to unicode and processed same as unicode string.
        """
        if not isinstance(data, unicode_):
            data = unic(data)
        if isinstance(data, unicode_):
            data = self._encode(data, encoding)
        self._port(port_locator).write(data)
Ejemplo n.º 4
0
def _html_escape_no_formatting_no_whitespace_replace(text):
    text = unic(text)
    for name, value in [('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;')]:
        text = text.replace(name, value)
    return _url_re.sub(lambda res: _repl_url(res, False), text)