from __future__ import absolute_import

import zipfile
from lxml import etree

from six import StringIO
from six import PY3


def _qn(ns):
    nsmap = {
        'text': 'urn:oasis:names:tc:opendocument:xmlns:text:1.0',
    }
    one, _, two = ns.partition(':')
    return '{{{}}}{}'.format(nsmap[one], two)


def _to_string(text, elem):
    if elem.text is not None:
        text.write(elem.text)
    for c in elem:
        if c.tag == _qn('text:tab'):
            text.write(' ')
        elif c.tag == _qn('text:s'):
            text.write(' ')
            if c.tail is not None:
                text.write(c.tail)
        else:
            _to_string(text, c)
    text.write(u'\n')


def _get_file(f, **kwargs):
    encoding, errors = kwargs['encoding'], kwargs['encoding_errors']
    text = StringIO()

    with zipfile.ZipFile(f, 'r') as z:
        with z.open('content.xml', 'r') as c:
            xml = etree.parse(c)

            for c in xml.iter():
                if c.tag in (_qn('text:p'), _qn('text:h')):
                    _to_string(text, c)

    return text.getvalue()


_get_path = _get_file

@@ -101,28 +101,8 @@
 gIO%0A
-from six import PY3%0A
 %0A%0Ade
@@ -691,77 +691,8 @@
 s):%0A
-    encoding, errors = kwargs%5B'encoding'%5D, kwargs%5B'encoding_errors'%5D%0A
     

make flake8 happy