Tweak some label printing logic to support python 3
This commit is contained in:
parent
c6329cded6
commit
81a2dfa1f4
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2018 Lance Edgar
|
||||
# Copyright © 2010-2019 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -30,7 +30,8 @@ import os
|
|||
import os.path
|
||||
import socket
|
||||
import shutil
|
||||
from six import StringIO
|
||||
|
||||
import six
|
||||
|
||||
from rattail.core import Object
|
||||
from rattail.files import temp_path
|
||||
|
@ -174,7 +175,7 @@ class CommandNetworkPrinter(CommandPrinter):
|
|||
if not self.port:
|
||||
raise LabelPrintingError("Printer does not have a port defined.")
|
||||
|
||||
data = StringIO()
|
||||
data = six.StringIO()
|
||||
|
||||
header = self.batch_header_commands()
|
||||
if header:
|
||||
|
@ -240,7 +241,7 @@ class CommandFormatter(LabelFormatter):
|
|||
"""
|
||||
|
||||
def format_labels(self, labels, progress=None):
|
||||
fmt = StringIO()
|
||||
fmt = six.StringIO()
|
||||
|
||||
def format_label(record, i):
|
||||
product, quantity, data = record
|
||||
|
@ -250,6 +251,9 @@ class CommandFormatter(LabelFormatter):
|
|||
header = "{0}\n".format('\n'.join(header))
|
||||
fmt.write(header.encode('utf_8'))
|
||||
body = "{}\n".format('\n'.join(self.label_body_commands(product, **data)))
|
||||
if six.PY3:
|
||||
fmt.write(body)
|
||||
else: # PY2
|
||||
fmt.write(body.encode('utf_8'))
|
||||
footer = self.label_footer_commands()
|
||||
if footer:
|
||||
|
@ -259,6 +263,9 @@ class CommandFormatter(LabelFormatter):
|
|||
progress_loop(format_label, labels, progress,
|
||||
message="Formatting labels")
|
||||
|
||||
if six.PY3:
|
||||
val = fmt.getvalue()
|
||||
else: # PY2
|
||||
val = fmt.getvalue().decode('utf_8')
|
||||
fmt.close()
|
||||
return val
|
||||
|
@ -304,7 +311,7 @@ class TwoUpCommandFormatter(CommandFormatter):
|
|||
raise NotImplementedError
|
||||
|
||||
def format_labels(self, labels, progress=None):
|
||||
fmt = StringIO()
|
||||
fmt = six.StringIO()
|
||||
self.half_started = False
|
||||
|
||||
def format_label(record, i):
|
||||
|
|
Loading…
Reference in a new issue