Commit d237f3b5 authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

Drop dependency on six

parent 39f5a748b46a
......@@ -34,7 +34,6 @@ author_email = "contact@logilab.fr"
install_requires = [
'setuptools',
'six >= 1.4.0',
'logilab-common',
'lxml',
'html2text',
......
logilab-mtconverter (0.9.0-2.1) UNRELEASED; urgency=medium
* Drop python2 packaging
* Drop dependency on six
-- Philippe Pepiot <philippe.pepiot@logilab.fr> Fri, 08 Nov 2019 07:58:25 +0100
......
......@@ -8,7 +8,6 @@ Build-Depends:
dh-python,
python3-all,
python3-setuptools,
python3-six,
python3-html2text,
python3-lxml,
python3-pygments,
......@@ -22,7 +21,6 @@ Vcs-Browser: http://hg.logilab.org/master/logilab/mtconverter
Package: python3-logilab-mtconverter
Architecture: all
Depends:
python3-six,
python3-logilab-common,
python3-lxml,
python3-html2text,
......
......@@ -39,8 +39,7 @@ except AttributeError:
import codecs
from io import BytesIO
from six import text_type, binary_type, int2byte, unichr
from six.moves.html_entities import name2codepoint
from html.entities import name2codepoint
import pkg_resources
__version__ = pkg_resources.get_distribution('logilab-mtconverter').version
......@@ -123,7 +122,7 @@ def guess_mimetype_and_encoding(format=None, encoding=None, data=None,
return format, encoding
CONTROL_CHARS = [int2byte(ci) for ci in range(32)]
CONTROL_CHARS = [bytes((ci,)) for ci in range(32)]
TR_CONTROL_CHARS = [' '] * len(CONTROL_CHARS)
for c in ('\n', '\r', '\t'):
TR_CONTROL_CHARS[ord(c)] = c
......@@ -141,7 +140,7 @@ def html_escape(data):
def xml_escape(data):
"""escapes XML forbidden characters in attributes and PCDATA"""
if isinstance(data, text_type):
if isinstance(data, str):
data = data.translate(ESC_UCAR_TABLE)
else:
data = data.translate(ESC_CAR_TABLE)
......@@ -151,7 +150,7 @@ def xml_escape(data):
def html_unescape(data):
"""unescapes XML/HTML entities"""
for entityname, codepoint in name2codepoint.items():
data = data.replace('&%s;' % entityname, unichr(codepoint))
data = data.replace('&%s;' % entityname, chr(codepoint))
return data.replace('&#39;', "'")
class TransformData(object):
......@@ -163,7 +162,7 @@ class TransformData(object):
self.data = data
self.mimetype = mimetype
self.encoding = encoding
if not self.is_binary() and not encoding and not isinstance(self.data, text_type):
if not self.is_binary() and not encoding and not isinstance(self.data, str):
self.encoding = guess_encoding(data)
def get(self, attr, default=None):
......@@ -172,7 +171,7 @@ class TransformData(object):
def decode(self, force=False):
"""return the data as an unicode string"""
if isinstance(self.data, text_type):
if isinstance(self.data, str):
return self.data
if force:
if self.encoding in BINARY_ENCODINGS:
......@@ -189,7 +188,7 @@ class TransformData(object):
def encode(self, encoding=None):
"""return the data as an encoded string"""
if (encoding is None or self.encoding == encoding) and \
isinstance(self.data, binary_type):
isinstance(self.data, bytes):
return self.data
encoding = encoding or self.encoding or 'utf8'
return self.decode().encode(encoding)
......
......@@ -16,8 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License along
# with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>.
from six import binary_type
from html2text import html2text
from logilab.mtconverter.transform import Transform
......@@ -32,7 +30,7 @@ class html_to_formatted_text(Transform):
def _convert(self, trdata):
if isinstance(trdata.data, binary_type):
if isinstance(trdata.data, bytes):
data = trdata.data.decode(trdata.encoding)
else:
data = trdata.data
......
......@@ -21,7 +21,6 @@ Copyright (C) 2009 Logilab S.A.
from io import BytesIO
from zipfile import ZipFile
from six import binary_type
from lxml import etree
from logilab.mtconverter.transform import Transform
......@@ -36,7 +35,7 @@ class odt_to_unformatted_text(Transform):
def _convert(self, trdata):
data = trdata.data
if isinstance(data, binary_type):
if isinstance(data, bytes):
# ZipFile only works with binary file-like objects
data = BytesIO(data)
zip = ZipFile(data, 'r')
......
......@@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License along
# with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import TestCase, unittest_main
from six.moves.urllib.parse import unquote as url_unquote
from urllib.parse import unquote as url_unquote
import re
import os.path as osp
......
......@@ -17,8 +17,6 @@
# You should have received a copy of the GNU Lesser General Public License along
# with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>.
from logilab.common.testlib import TestCase, unittest_main
from six import u
from six.moves import range
import locale
from io import BytesIO
......@@ -57,12 +55,12 @@ class HtmlEscapeTC(TestCase):
def test_escape_special_chars_unicode(self):
for car, trcar in SPECIAL_CHARS.items():
yield self.assertEqual, xml_escape(u(car)), trcar
yield self.assertEqual, xml_escape(car), trcar
for carnum in range(32):
car = chr(carnum)
if car in SPECIAL_CHARS:
continue
yield self.assertEqual, xml_escape(u(car)), ' '
yield self.assertEqual, xml_escape(car), ' '
def test_html_unescape(self):
for data, expected in [('toto', 'toto'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment