# Path: talon/utils.py
# def safe_format(format_string, *args, **kwargs):
# def to_unicode(str_or_unicode, precise=False):
# def detect_encoding(string):
# def quick_detect_encoding(string):
# def to_utf8(str_or_unicode):
# def random_token(length=7):
# def get_delimiter(msg_body):
# def html_tree_to_text(tree):
# def html_to_text(string):
# def html_fromstring(s):
# def html_document_fromstring(s):
# def cssselect(expr, tree):
# def _contains_charset_spec(s):
# def _prepend_utf8_declaration(s):
# def _rm_excessive_newlines(s):
# def _encode_utf8(s):
# def _html5lib_parser():
# _UTF8_DECLARATION = (b'<meta http-equiv="Content-Type" content="text/html;'
#                      b'charset=utf-8">')
# _BLOCKTAGS = ['div', 'p', 'ul', 'li', 'h1', 'h2', 'h3']
# _HARDBREAKS = ['br', 'hr', 'tr']
# _RE_EXCESSIVE_NEWLINES = re.compile("\n{2,10}")


import cchardet
import six
from talon import utils as u
from . import *

<style type="text/css">

h1 {

font: 13px 'Lucida Grande', Arial, sans-serif;

}
</style>"""
    eq_(b'Hi', u.html_to_text(html))

    html = """<div>
<!-- COMMENT 1 -->
<span>TEXT 1</span>
<p>TEXT 2 <!-- COMMENT 2 --></p>
</div>"""
    eq_(b'TEXT 1 \nTEXT 2', u.html_to_text(html))


def test_comment_no_parent():
    s = b'<!-- COMMENT 1 --> no comment'
    d = u.html_document_fromstring(s)
    eq_(b"no comment", u.html_tree_to_text(d))


@patch.object(u.html5parser, 'fromstring', Mock(side_effect=Exception()))
def test_html_fromstring_exception():
    eq_(None, u.html_fromstring("<html></html>"))



# Path: talon/utils.py
# def safe_format(format_string, *args, **kwargs):
# def to_unicode(str_or_unicode, precise=False):
# def detect_encoding(string):
# def quick_detect_encoding(string):
# def to_utf8(str_or_unicode):
# def random_token(length=7):
# def get_delimiter(msg_body):
# def html_tree_to_text(tree):
# def html_to_text(string):
# def html_fromstring(s):
# def html_document_fromstring(s):
# def cssselect(expr, tree):
# def _contains_charset_spec(s):
# def _prepend_utf8_declaration(s):
# def _rm_excessive_newlines(s):
# def _encode_utf8(s):
# def _html5lib_parser():
# _UTF8_DECLARATION = (b'<meta http-equiv="Content-Type" content="text/html;'
#                      b'charset=utf-8">')
# _BLOCKTAGS = ['div', 'p', 'ul', 'li', 'h1', 'h2', 'h3']
# _HARDBREAKS = ['br', 'hr', 'tr']
# _RE_EXCESSIVE_NEWLINES = re.compile("\n{2,10}")


# Path: tests/utils_test.py
import cchardet
import six
from talon import utils as u
from . import *


<style type="text/css">

h1 {

font: 13px 'Lucida Grande', Arial, sans-serif;

}
</style>"""
    eq_(b'Hi', u.html_to_text(html))

    html = """<div>
<!-- COMMENT 1 -->
<span>TEXT 1</span>
<p>TEXT 2 <!-- COMMENT 2 --></p>
</div>"""
    eq_(b'TEXT 1 \nTEXT 2', u.html_to_text(html))


def test_comment_no_parent():
    s = b'<!-- COMMENT 1 --> no comment'
    d = u.html_document_fromstring(s)
    eq_(b"no comment", u.html_tree_to_text(d))


@patch.object(u.html5parser, 'fromstring', Mock(side_effect=Exception()))
def test_html_fromstring_exception():
    eq_(None, u.html_fromstring("<html></html>"))



@patch.object(u.html5parser, 'document_fromstring')