reformat PEP8 and similar issues
This commit is contained in:
parent
2ea8e69c66
commit
c2fc464c55
|
@ -56,5 +56,6 @@ def print_codepage(printer, codepage):
|
||||||
printer._raw(sep)
|
printer._raw(sep)
|
||||||
printer._raw('\n')
|
printer._raw('\n')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
|
@ -3,7 +3,6 @@ import six
|
||||||
from os import path
|
from os import path
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
# Load external printer database
|
# Load external printer database
|
||||||
with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
|
with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
|
||||||
CAPABILITIES = yaml.load(f)
|
CAPABILITIES = yaml.load(f)
|
||||||
|
@ -11,7 +10,6 @@ with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
|
||||||
PROFILES = CAPABILITIES['profiles']
|
PROFILES = CAPABILITIES['profiles']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class NotSupported(Exception):
|
class NotSupported(Exception):
|
||||||
"""Raised if a requested feature is not suppored by the
|
"""Raised if a requested feature is not suppored by the
|
||||||
printer profile.
|
printer profile.
|
||||||
|
@ -61,7 +59,6 @@ class BaseProfile(object):
|
||||||
return {v: k for k, v in self.codePages.items()}
|
return {v: k for k, v in self.codePages.items()}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_profile(name=None, **kwargs):
|
def get_profile(name=None, **kwargs):
|
||||||
"""Get the profile by name; if no name is given, return the
|
"""Get the profile by name; if no name is given, return the
|
||||||
default profile.
|
default profile.
|
||||||
|
@ -103,6 +100,7 @@ class Profile(get_profile_class('default')):
|
||||||
"""
|
"""
|
||||||
For users, who want to provide their profile
|
For users, who want to provide their profile
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, columns=None, features=None):
|
def __init__(self, columns=None, features=None):
|
||||||
super(Profile, self).__init__()
|
super(Profile, self).__init__()
|
||||||
|
|
||||||
|
@ -114,7 +112,3 @@ class Profile(get_profile_class('default')):
|
||||||
return self.columns
|
return self.columns
|
||||||
|
|
||||||
return super(Profile, self).get_columns(font)
|
return super(Profile, self).get_columns(font)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@ class CodePageManager:
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
return self.data.values()
|
return self.data.values()
|
||||||
|
|
||||||
def get_encoding_name(self, encoding):
|
@staticmethod
|
||||||
|
def get_encoding_name(encoding):
|
||||||
# TODO resolve the encoding alias
|
# TODO resolve the encoding alias
|
||||||
return encoding.upper()
|
return encoding.upper()
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,8 @@ class Escpos(object):
|
||||||
if impl == "bitImageRaster":
|
if impl == "bitImageRaster":
|
||||||
# GS v 0, raster format bit image
|
# GS v 0, raster format bit image
|
||||||
density_byte = (0 if high_density_horizontal else 1) + (0 if high_density_vertical else 2)
|
density_byte = (0 if high_density_horizontal else 1) + (0 if high_density_vertical else 2)
|
||||||
header = GS + b"v0" + six.int2byte(density_byte) + self._int_low_high(im.width_bytes, 2) + self._int_low_high(im.height, 2)
|
header = GS + b"v0" + six.int2byte(density_byte) + self._int_low_high(im.width_bytes, 2) +\
|
||||||
|
self._int_low_high(im.height, 2)
|
||||||
self._raw(header + im.to_raster_format())
|
self._raw(header + im.to_raster_format())
|
||||||
|
|
||||||
if impl == "graphics":
|
if impl == "graphics":
|
||||||
|
@ -398,6 +399,7 @@ class Escpos(object):
|
||||||
Text has to be encoded in unicode.
|
Text has to be encoded in unicode.
|
||||||
|
|
||||||
:param txt: text to be printed
|
:param txt: text to be printed
|
||||||
|
:param font: font to be used, can be :code:`a` or :code`b`
|
||||||
:param columns: amount of columns
|
:param columns: amount of columns
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
@ -539,7 +541,7 @@ class Escpos(object):
|
||||||
|
|
||||||
if divisor not in LINESPACING_FUNCS:
|
if divisor not in LINESPACING_FUNCS:
|
||||||
raise ValueError("divisor must be either 360, 180 or 60")
|
raise ValueError("divisor must be either 360, 180 or 60")
|
||||||
if (divisor in [360, 180] \
|
if (divisor in [360, 180]
|
||||||
and (not(0 <= spacing <= 255))):
|
and (not(0 <= spacing <= 255))):
|
||||||
raise ValueError("spacing must be a int between 0 and 255 when divisor is 360 or 180")
|
raise ValueError("spacing must be a int between 0 and 255 when divisor is 360 or 180")
|
||||||
if divisor == 60 and (not(0 <= spacing <= 85)):
|
if divisor == 60 and (not(0 <= spacing <= 85)):
|
||||||
|
|
|
@ -30,13 +30,12 @@ def encode_katakana(text):
|
||||||
if char in TXT_ENC_KATAKANA_MAP:
|
if char in TXT_ENC_KATAKANA_MAP:
|
||||||
encoded.append(TXT_ENC_KATAKANA_MAP[char])
|
encoded.append(TXT_ENC_KATAKANA_MAP[char])
|
||||||
else:
|
else:
|
||||||
#TODO doesn't this discard all that is not in the map? Can we be shure that the input does contain only
|
# TODO doesn't this discard all that is not in the map? Can we be sure that the input does contain only
|
||||||
# encodable characters? We could at least throw an exception if encoding is not possible.
|
# encodable characters? We could at least throw an exception if encoding is not possible.
|
||||||
pass
|
pass
|
||||||
return b"".join(encoded)
|
return b"".join(encoded)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TXT_ENC_KATAKANA_MAP = {
|
TXT_ENC_KATAKANA_MAP = {
|
||||||
# Maps UTF-8 Katakana symbols to KATAKANA Page Codes
|
# Maps UTF-8 Katakana symbols to KATAKANA Page Codes
|
||||||
# TODO: has this really to be hardcoded?
|
# TODO: has this really to be hardcoded?
|
||||||
|
|
|
@ -67,7 +67,8 @@ class Encoder(object):
|
||||||
).format(encoding, ','.join(self.codepages.keys())))
|
).format(encoding, ','.join(self.codepages.keys())))
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
def _get_codepage_char_list(self, encoding):
|
@staticmethod
|
||||||
|
def _get_codepage_char_list(encoding):
|
||||||
"""Get codepage character list
|
"""Get codepage character list
|
||||||
|
|
||||||
Gets characters 128-255 for a given code page, as an array.
|
Gets characters 128-255 for a given code page, as an array.
|
||||||
|
@ -126,7 +127,8 @@ class Encoder(object):
|
||||||
is_encodable = char in available_map
|
is_encodable = char in available_map
|
||||||
return is_ascii or is_encodable
|
return is_ascii or is_encodable
|
||||||
|
|
||||||
def _encode_char(self, char, charmap, defaultchar):
|
@staticmethod
|
||||||
|
def _encode_char(char, charmap, defaultchar):
|
||||||
""" Encode a single character with the given encoding map
|
""" Encode a single character with the given encoding map
|
||||||
|
|
||||||
:param char: char to encode
|
:param char: char to encode
|
||||||
|
|
|
@ -30,7 +30,7 @@ printer:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestCLI():
|
class TestCLI:
|
||||||
""" Contains setups, teardowns, and tests for CLI
|
""" Contains setups, teardowns, and tests for CLI
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ from escpos.katakana import encode_katakana
|
||||||
from escpos.exceptions import CharCodeError, Error
|
from escpos.exceptions import CharCodeError, Error
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TestEncoder:
|
class TestEncoder:
|
||||||
"""
|
"""
|
||||||
Tests the single encoders.
|
Tests the single encoders.
|
||||||
|
|
|
@ -26,6 +26,7 @@ if six.PY3:
|
||||||
else:
|
else:
|
||||||
mock_open_call = '__builtin__.open'
|
mock_open_call = '__builtin__.open'
|
||||||
|
|
||||||
|
|
||||||
@given(path=text())
|
@given(path=text())
|
||||||
def test_load_file_printer(mocker, path):
|
def test_load_file_printer(mocker, path):
|
||||||
"""test the loading of the file-printer"""
|
"""test the loading of the file-printer"""
|
||||||
|
|
Loading…
Reference in New Issue