Fix Py2/3 compatibility (#40)

This commit is contained in:
Philipp Klaus
2018-09-03 15:15:58 +02:00
parent 4ac1c76da9
commit 7ab1e672b7
4 changed files with 12 additions and 7 deletions

View File

@@ -5,6 +5,9 @@ Backend to support Brother QL-series printers via the linux kernel USB printer i
Works on Linux. Works on Linux.
""" """
from __future__ import unicode_literals
from builtins import str
import glob, os, time, select import glob, os, time, select
from .generic import BrotherQLBackendGeneric from .generic import BrotherQLBackendGeneric

View File

@@ -5,6 +5,9 @@ Backend to support Brother QL-series printers via network.
Works cross-platform. Works cross-platform.
""" """
from __future__ import unicode_literals
from builtins import str
import socket, os, time, select import socket, os, time, select
from .generic import BrotherQLBackendGeneric from .generic import BrotherQLBackendGeneric

View File

@@ -8,6 +8,9 @@ Requires PyUSB: https://github.com/walac/pyusb/
Install via `pip install pyusb` Install via `pip install pyusb`
""" """
from __future__ import unicode_literals
from builtins import str
import time import time
import usb.core import usb.core

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division from __future__ import division, unicode_literals
from builtins import str
import logging import logging
@@ -12,11 +13,6 @@ from brother_ql.devicedependent import label_type_specs, ENDLESS_LABEL, DIE_CUT_
from brother_ql import BrotherQLUnsupportedCmd from brother_ql import BrotherQLUnsupportedCmd
from brother_ql.image_trafos import filtered_hsv from brother_ql.image_trafos import filtered_hsv
try:
unicode
except:
unicode = str
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING) logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING)
@@ -83,7 +79,7 @@ def convert(qlr, images, label, **kwargs):
for image in images: for image in images:
if isinstance(image, Image.Image): if isinstance(image, Image.Image):
im = image im = image
elif isinstance(image, (unicode, str)): elif isinstance(image, str):
im = Image.open(image) im = Image.open(image)
else: else:
raise NotImplementedError("The image argument needs to be an Image() instance or the filename to an image.") raise NotImplementedError("The image argument needs to be an Image() instance or the filename to an image.")