Commit aa0beec5 authored by Laurent Peuch's avatar Laurent Peuch
Browse files

chore: please the flake8 gods

parent de409ef1ce48
......@@ -63,7 +63,9 @@ TEXT_MIMETYPES = set(("application/xml", "application/xhtml+xml"))
UNICODE_POLICY = "strict"
_CHARSET_DECL_RGX = "(?:charset|(?:(?:en)?coding))[=:\s\"']*([^\s\"']*)".encode("ascii")
_CHARSET_DECL_RGX = "(?:charset|(?:(?:en)?coding))[=:\\s\"']*([^\\s\"']*)".encode(
"ascii"
)
CHARSET_DECL_RGX = re.compile(_CHARSET_DECL_RGX, re.I | re.S)
CHARSET_DECL_SEARCH_SIZE = 512
......@@ -145,6 +147,7 @@ ESC_CAR_TABLE = maketrans(
)
ESC_UCAR_TABLE = ESC_CAR_TABLE.decode("latin1")
# XXX deprecate at some point (once less used :)
# @obsolete('use xml_escape')
def html_escape(data):
......
......@@ -103,5 +103,5 @@ class TransformsChain(list):
else:
try:
del self.output_encoding
except:
except Exception:
pass
......@@ -30,7 +30,6 @@ bin_search_path = [
def bin_search(binary):
"""search the bin_search_path for a given binary returning its fullname or
raises MissingBinary"""
result = None
mode = os.R_OK | os.X_OK
for path in bin_search_path:
pathbin = os.path.join(path, binary)
......
......@@ -94,5 +94,5 @@ class image_to_tiff(PILTransform):
transform_classes = [
c
for c in globals().values()
if isinstance(c, type) and issubclass(c, PILTransform) and not c is PILTransform
if isinstance(c, type) and issubclass(c, PILTransform) and c is not PILTransform
]
......@@ -32,7 +32,11 @@ Original code from active state recipe
original formatting (which is the hard part).
"""
import keyword, token, tokenize
from logilab.mtconverter import html_escape
from logilab.mtconverter.transform import Transform
import keyword
import token
import tokenize
from io import StringIO
_KEYWORD = token.NT_OFFSET + 1
......@@ -109,10 +113,6 @@ class Parser:
self.out.write(close_tag)
from logilab.mtconverter.transform import Transform
from logilab.mtconverter import html_escape
class python_to_html(Transform):
"""Colorize Python source files"""
......
......@@ -22,10 +22,7 @@
"""
__docformat__ = "restructuredtext en"
import os
import sys
import shutil
from os.path import isdir, exists, join, dirname, abspath
from os.path import exists, join, dirname, abspath
from setuptools import setup, find_packages
......
......@@ -21,24 +21,22 @@ from logilab.common.testlib import TestCase, unittest_main
from logilab.mtconverter.engine import TransformEngine
from logilab.mtconverter import (
TransformData,
TransformError,
register_base_transforms,
register_pil_transforms,
register_pygments_transforms,
)
ENGINE = TransformEngine()
register_base_transforms(ENGINE)
register_pil_transforms(ENGINE)
_pygments_available = register_pygments_transforms(ENGINE)
import logilab.mtconverter as mtc
import os
import os.path as osp
import errno
import subprocess
import pytest
ENGINE = TransformEngine()
register_base_transforms(ENGINE)
register_pil_transforms(ENGINE)
_pygments_available = register_pygments_transforms(ENGINE)
DATAPATH = osp.dirname(__file__)
......@@ -106,7 +104,8 @@ r2MAoIO1DSsuM23SzgmqubGJEZuSRWhR
converted = ENGINE.convert(data, "text/plain").decode().strip()
self.assertEqual(
converted,
u"Hello ! OpenOffice.org/2.4$Unix OpenOffice.org_project/680m17$Build-9310 Hello quoi de neuf doc ? bonjour 2008-07-08T16:19:35 2009-01-09T14:44:54 mot-clef 1 PT37S",
u"Hello ! OpenOffice.org/2.4$Unix OpenOffice.org_project/680m17$Build-9310 Hello quoi "
u"de neuf doc ? bonjour 2008-07-08T16:19:35 2009-01-09T14:44:54 mot-clef 1 PT37S",
)
# ZipFile will complain that
# TypeError: file() argument 1 must be (encoded string without NULL bytes), not str
......@@ -119,7 +118,8 @@ r2MAoIO1DSsuM23SzgmqubGJEZuSRWhR
converted = ENGINE.convert(data, "text/plain").decode().strip()
self.assertEqual(
converted,
u"Hello ! OpenOffice.org/2.4$Unix OpenOffice.org_project/680m17$Build-9310 Hello quoi de neuf doc ? bonjour 2008-07-08T16:19:35 2009-01-09T14:44:54 mot-clef 1 PT37S",
u"Hello ! OpenOffice.org/2.4$Unix OpenOffice.org_project/680m17$Build-9310 Hello quoi "
u"de neuf doc ? bonjour 2008-07-08T16:19:35 2009-01-09T14:44:54 mot-clef 1 PT37S",
)
def test_pdf_to_text(self):
......
......@@ -20,7 +20,14 @@ from logilab.common.testlib import TestCase, unittest_main
import locale
from io import BytesIO
from logilab.mtconverter import *
from logilab.mtconverter import (
xml_escape,
html_unescape,
guess_encoding,
DEFAULT_ENCODING,
guess_mimetype_and_encoding,
TransformData,
)
SPECIAL_CHARS = {
"\f": "\n",
......@@ -90,9 +97,12 @@ class GuessEncodingTC(TestCase):
self.assertEqual(guess_encoding(data), "latin1")
def test_html_style_declaration(self):
data = b"""<html xmlns="http://www.w3.org/1999/xhtml" xmlns:erudi="http://www.logilab.fr/" xml:lang="fr" lang="fr">
data = b"""\
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:erudi="http://www.logilab.fr/" xml:lang="fr" \
lang="fr">
<head>
<base href="http://intranet.logilab.fr/jpl/" /><meta http-equiv="content-type" content="text/html; charset=latin1"/>
<base href="http://intranet.logilab.fr/jpl/" />\
<meta http-equiv="content-type" content="text/html; charset=latin1"/>
</head>
<body><p>hello world</p>
</body>
......@@ -106,7 +116,7 @@ class GuessEncodingTC(TestCase):
'''
# ascii detected by chardet
try:
import chardet
import chardet # noqa
self.assertEqual(guess_encoding(data), "ascii")
except ImportError:
......
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