# Path: openpyxl/shared/xmltools.py
# def get_document_content(xml_node):
# def pretty_indent(elem, level=0):
# def start_tag(doc, name, attr=None, body=None, namespace=None):
# def end_tag(doc, name, namespace=None):
# def tag(doc, name, attr=None, body=None, namespace=None):
# 
# Path: openpyxl/shared/xmltools.py
# def pretty_indent(elem, level=0):
#     """Format xml with nice indents and line breaks."""
#     i = "\n" + level * "  "
#     if len(elem):
#         if not elem.text or not elem.text.strip():
#             elem.text = i + "  "
#         if not elem.tail or not elem.tail.strip():
#             elem.tail = i
#         for elem in elem:
#             pretty_indent(elem, level + 1)
#         if not elem.tail or not elem.tail.strip():
#             elem.tail = i
#     else:
#         if level and (not elem.tail or not elem.tail.strip()):
#             elem.tail = i


import os
import os.path
import shutil
import difflib
from StringIO import StringIO
from pprint import pprint
from tempfile import gettempdir
from openpyxl.shared.xmltools import fromstring, ElementTree
from openpyxl.shared.xmltools import pretty_indent

def make_tmpdir():
    try:
        os.makedirs(TMPDIR)
    except OSError:
        pass


def clean_tmpdir():
    if os.path.isdir(TMPDIR):
        shutil.rmtree(TMPDIR, ignore_errors = True)


def assert_equals_file_content(reference_file, fixture, filetype = 'xml'):
    if os.path.isfile(fixture):
        with open(fixture) as fixture_file:
            fixture_content = fixture_file.read()
    else:
        fixture_content = fixture

    with open(reference_file) as expected_file:
        expected_content = expected_file.read()

    if filetype == 'xml':
        fixture_content = fromstring(fixture_content)
        pretty_indent(fixture_content)
        temp = StringIO()
        ElementTree(fixture_content).write(temp)
        fixture_content = temp.getvalue()


# Path: openpyxl/shared/xmltools.py
# def get_document_content(xml_node):
# def pretty_indent(elem, level=0):
# def start_tag(doc, name, attr=None, body=None, namespace=None):
# def end_tag(doc, name, namespace=None):
# def tag(doc, name, attr=None, body=None, namespace=None):
# 
# Path: openpyxl/shared/xmltools.py
# def pretty_indent(elem, level=0):
#     """Format xml with nice indents and line breaks."""
#     i = "\n" + level * "  "
#     if len(elem):
#         if not elem.text or not elem.text.strip():
#             elem.text = i + "  "
#         if not elem.tail or not elem.tail.strip():
#             elem.tail = i
#         for elem in elem:
#             pretty_indent(elem, level + 1)
#         if not elem.tail or not elem.tail.strip():
#             elem.tail = i
#     else:
#         if level and (not elem.tail or not elem.tail.strip()):
#             elem.tail = i


# Path: openpyxl/tests/helper.py
import os
import os.path
import shutil
import difflib
from StringIO import StringIO
from pprint import pprint
from tempfile import gettempdir
from openpyxl.shared.xmltools import fromstring, ElementTree
from openpyxl.shared.xmltools import pretty_indent


def make_tmpdir():
    try:
        os.makedirs(TMPDIR)
    except OSError:
        pass


def clean_tmpdir():
    if os.path.isdir(TMPDIR):
        shutil.rmtree(TMPDIR, ignore_errors = True)


def assert_equals_file_content(reference_file, fixture, filetype = 'xml'):
    if os.path.isfile(fixture):
        with open(fixture) as fixture_file:
            fixture_content = fixture_file.read()
    else:
        fixture_content = fixture

    with open(reference_file) as expected_file:
        expected_content = expected_file.read()

    if filetype == 'xml':
        fixture_content = fromstring(fixture_content)
        pretty_indent(fixture_content)
        temp = StringIO()
        ElementTree(fixture_content).write(temp)
        fixture_content = temp.getvalue()


        expected_content = fromstring(expected_content)