# Path: tabun_api/utils.py
# def parse_html(data, encoding='utf-8'):
# def parse_html_fragment(data, encoding='utf-8'):
#     def __init__(self, params=None):
#     def format(self, node, with_cutted=True):
#     def format_part(self, node, with_cutted=True):
#     def element_children(self, item, noblock=False):
#     def process_br(self, item, data, depth, with_cutted):
#     def default_process(self, item, data, depth, with_cutted):
#     def format_item_tail(self, item, data, depth, full_queue):
#     def format_text(self, ntext, data=None):
#     def escape(self, ntext):
#     def process_a(self, item, data, depth, with_cutted):
#     def process_span(self, item, data, depth, with_cutted):
#     def process_li(self, item, data, depth, with_cutted):
#     def process_blockquote(self, item, data, depth, with_cutted):
#     def process_hr(self, item, data, depth, with_cutted):
#     def process_s(self, item, data, depth, with_cutted):
# def htmlToString(node, with_cutted=True, fancy=True, vk_links=False, hr_lines=True, disable_links=False):
# def node2string(node, encoding="utf-8"):
# def mon2num(s):
# def is_cut(item):
# def find_images(body, spoiler_title=True, no_other=False):
# def encode_multipart_formdata(fields, files, boundary=None):
# def get_content_type(filename):
# def send_form(url, fields, files, timeout=None, headers=None):
# def find_substring(s, start, end, extend=False, with_start=True, with_end=True):
# def download(url, maxmem=20 * 1024 * 1024, timeout=5, waitout=15, headers=None):
# def find_good_image(urls, maxmem=20 * 1024 * 1024):
# def generate_comments_tree(comms):
# def parse_avatar_url(url):
# def decode_cf_email(data):
# def decode_cf_email_for_link(m):
# def replace_cloudflare_emails(data):
# def normalize_body(body=None, raw_body=None, cls='text'):
# def html_escape(s, single_quote=False):
# def escape_topic_contents(data, may_be_short=False):
# def escape_comment_contents(data):
# def escape_blog_content(data):
# def escape_profile_content(data):
# def parse_datetime(s, utc=True):
# def gen_user_agent():
# def get_cookies_dict(headers):
# def is_module_available(name):
# def build_proxy_params(proxy=None):
# class HTMLFormatter(object):
#     NEWLINE = -1
#     L = []
# 
# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


import pytest
import lxml.html
    import string
    import random
    import string
    import random
    import socks
    import socks
from tabun_api import utils
from tabun_api.compat import PY2, text, binary
from testutil import user
    from io import BytesIO
        from httplib import HTTPMessage
        from http.client import parse_headers
def test_formatter_links_nodisable():
    assert hf('<div>a<a href="http://ya.ru/">ya.ru/</a>b</div>') == 'aya.ru/b'


def test_formatter_links_disable_ok1():
    assert hf('<div>a<a href="http://ya.ru/">ya.ru/</a>b</div>', disable_links=True) == 'ab'


def test_formatter_links_disable_ok2():
    assert hf('<div>a<a href="//ya.ru/">ya.ru/</a>b</div>', disable_links=True) == 'ab'


def test_formatter_links_disable_fake1():
    assert hf('<div>a<a href="//ya.ru/">ya.ru</a>b</div>', disable_links=True) == 'aya.rub'


def test_formatter_links_disable_fake2():
    assert hf('<div>a<a href="//google.ru/">rambler.ru</a>b</div>', disable_links=True) == 'arambler.rub'


def test_find_images_cutted(user):
    post = user.get_post(138982, 'borderline')
    assert utils.find_images(post.body) == [['https://i.imgur.com/V3KzzyAs.png'], ['https://i.imgur.com/NAg929K.jpg']]


def test_parse_datetime_2015():
    assert utils.parse_datetime('2015-01-01T02:00:00+03:00').strftime('%Y-%m-%d %H:%M:%S') == '2014-12-31 23:00:00'


def test_parse_datetime_2015_noutc():

# Path: tabun_api/utils.py
# def parse_html(data, encoding='utf-8'):
# def parse_html_fragment(data, encoding='utf-8'):
#     def __init__(self, params=None):
#     def format(self, node, with_cutted=True):
#     def format_part(self, node, with_cutted=True):
#     def element_children(self, item, noblock=False):
#     def process_br(self, item, data, depth, with_cutted):
#     def default_process(self, item, data, depth, with_cutted):
#     def format_item_tail(self, item, data, depth, full_queue):
#     def format_text(self, ntext, data=None):
#     def escape(self, ntext):
#     def process_a(self, item, data, depth, with_cutted):
#     def process_span(self, item, data, depth, with_cutted):
#     def process_li(self, item, data, depth, with_cutted):
#     def process_blockquote(self, item, data, depth, with_cutted):
#     def process_hr(self, item, data, depth, with_cutted):
#     def process_s(self, item, data, depth, with_cutted):
# def htmlToString(node, with_cutted=True, fancy=True, vk_links=False, hr_lines=True, disable_links=False):
# def node2string(node, encoding="utf-8"):
# def mon2num(s):
# def is_cut(item):
# def find_images(body, spoiler_title=True, no_other=False):
# def encode_multipart_formdata(fields, files, boundary=None):
# def get_content_type(filename):
# def send_form(url, fields, files, timeout=None, headers=None):
# def find_substring(s, start, end, extend=False, with_start=True, with_end=True):
# def download(url, maxmem=20 * 1024 * 1024, timeout=5, waitout=15, headers=None):
# def find_good_image(urls, maxmem=20 * 1024 * 1024):
# def generate_comments_tree(comms):
# def parse_avatar_url(url):
# def decode_cf_email(data):
# def decode_cf_email_for_link(m):
# def replace_cloudflare_emails(data):
# def normalize_body(body=None, raw_body=None, cls='text'):
# def html_escape(s, single_quote=False):
# def escape_topic_contents(data, may_be_short=False):
# def escape_comment_contents(data):
# def escape_blog_content(data):
# def escape_profile_content(data):
# def parse_datetime(s, utc=True):
# def gen_user_agent():
# def get_cookies_dict(headers):
# def is_module_available(name):
# def build_proxy_params(proxy=None):
# class HTMLFormatter(object):
#     NEWLINE = -1
#     L = []
# 
# Path: tabun_api/compat.py
# PY2 = sys.version_info.major == 2


# Path: test/test_utils.py
import pytest
import lxml.html
    import string
    import random
    import string
    import random
    import socks
    import socks
from tabun_api import utils
from tabun_api.compat import PY2, text, binary
from testutil import user
    from io import BytesIO
        from httplib import HTTPMessage
        from http.client import parse_headers

def test_formatter_links_nodisable():
    assert hf('<div>a<a href="http://ya.ru/">ya.ru/</a>b</div>') == 'aya.ru/b'


def test_formatter_links_disable_ok1():
    assert hf('<div>a<a href="http://ya.ru/">ya.ru/</a>b</div>', disable_links=True) == 'ab'


def test_formatter_links_disable_ok2():
    assert hf('<div>a<a href="//ya.ru/">ya.ru/</a>b</div>', disable_links=True) == 'ab'


def test_formatter_links_disable_fake1():
    assert hf('<div>a<a href="//ya.ru/">ya.ru</a>b</div>', disable_links=True) == 'aya.rub'


def test_formatter_links_disable_fake2():
    assert hf('<div>a<a href="//google.ru/">rambler.ru</a>b</div>', disable_links=True) == 'arambler.rub'


def test_find_images_cutted(user):
    post = user.get_post(138982, 'borderline')
    assert utils.find_images(post.body) == [['https://i.imgur.com/V3KzzyAs.png'], ['https://i.imgur.com/NAg929K.jpg']]


def test_parse_datetime_2015():
    assert utils.parse_datetime('2015-01-01T02:00:00+03:00').strftime('%Y-%m-%d %H:%M:%S') == '2014-12-31 23:00:00'


def test_parse_datetime_2015_noutc():

    assert utils.parse_datetime('2015-01-01T02:00:00+03:00', utc=False).strftime('%Y-%m-%d %H:%M:%S') == '2015-01-01 02:00:00'