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