reformat PEP8 and similar issues

This commit is contained in:
Patrick Kanzler 2017-01-30 00:10:14 +01:00
parent 2ea8e69c66
commit c2fc464c55
No known key found for this signature in database
GPG Key ID: F07F07153306FCEF
12 changed files with 35 additions and 36 deletions

View File

@ -46,8 +46,8 @@ def print_codepage(printer, codepage):
printer._raw("{} ".format(hex(x)[2:]))
printer.set()
for y in range(0,16):
byte = six.int2byte(x*16+y)
for y in range(0, 16):
byte = six.int2byte(x * 16 + y)
if byte in (ESC, CTL_LF, CTL_FF, CTL_CR, CTL_HT, CTL_VT):
byte = ' '
@ -56,5 +56,6 @@ def print_codepage(printer, codepage):
printer._raw(sep)
printer._raw('\n')
if __name__ == '__main__':
main()
main()

View File

@ -3,7 +3,6 @@ import six
from os import path
import yaml
# Load external printer database
with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
CAPABILITIES = yaml.load(f)
@ -11,7 +10,6 @@ with open(path.join(path.dirname(__file__), 'capabilities.json')) as f:
PROFILES = CAPABILITIES['profiles']
class NotSupported(Exception):
"""Raised if a requested feature is not suppored by the
printer profile.
@ -61,7 +59,6 @@ class BaseProfile(object):
return {v: k for k, v in self.codePages.items()}
def get_profile(name=None, **kwargs):
"""Get the profile by name; if no name is given, return the
default profile.
@ -92,17 +89,18 @@ def get_profile_class(name):
def clean(s):
# Remove invalid characters
s = re.sub('[^0-9a-zA-Z_]', '', s)
# Remove leading characters until we find a letter or underscore
s = re.sub('^[^a-zA-Z_]+', '', s)
return str(s)
# Remove invalid characters
s = re.sub('[^0-9a-zA-Z_]', '', s)
# Remove leading characters until we find a letter or underscore
s = re.sub('^[^a-zA-Z_]+', '', s)
return str(s)
class Profile(get_profile_class('default')):
"""
For users, who want to provide their profile
"""
def __init__(self, columns=None, features=None):
super(Profile, self).__init__()
@ -114,7 +112,3 @@ class Profile(get_profile_class('default')):
return self.columns
return super(Profile, self).get_columns(font)

View File

@ -12,11 +12,12 @@ class CodePageManager:
def get_all(self):
return self.data.values()
def get_encoding_name(self, encoding):
@staticmethod
def get_encoding_name(encoding):
# TODO resolve the encoding alias
return encoding.upper()
def get_encoding(self, encoding):
return self.data[encoding]
CodePages = CodePageManager(CAPABILITIES['encodings'])
CodePages = CodePageManager(CAPABILITIES['encodings'])

View File

@ -81,7 +81,7 @@ class Escpos(object):
:param impl: choose image printing mode between `bitImageRaster`, `graphics` or `bitImageColumn`
:param fragment_height: Images larger than this will be split into multiple fragments *default:* 960
"""
"""
im = EscposImage(img_source)
if im.height > fragment_height:
@ -93,13 +93,14 @@ class Escpos(object):
impl=impl,
fragment_height=fragment_height)
return
if impl == "bitImageRaster":
# GS v 0, raster format bit image
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())
if impl == "graphics":
# GS ( L raster format graphics
img_header = self._int_low_high(im.width, 2) + self._int_low_high(im.height, 2)
@ -111,7 +112,7 @@ class Escpos(object):
raster_data = im.to_raster_format()
self._image_send_graphics_data(b'0', b'p', header + raster_data)
self._image_send_graphics_data(b'0', b'2', b'')
if impl == "bitImageColumn":
# ESC *, column format bit image
density_byte = (1 if high_density_horizontal else 0) + (32 if high_density_vertical else 0)
@ -198,7 +199,7 @@ class Escpos(object):
raise ValueError("cn and fn must be one byte each.")
header = self._int_low_high(len(data) + len(m) + 2, 2)
self._raw(GS + b'(k' + header + cn + fn + m + data)
@staticmethod
def _int_low_high(inp_number, out_bytes):
""" Generate multiple bytes for a number: In lower and higher parts, or more parts as needed.
@ -398,6 +399,7 @@ class Escpos(object):
Text has to be encoded in unicode.
:param txt: text to be printed
:param font: font to be used, can be :code:`a` or :code`b`
:param columns: amount of columns
:return: None
"""
@ -539,7 +541,7 @@ class Escpos(object):
if divisor not in LINESPACING_FUNCS:
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))):
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)):

View File

@ -30,13 +30,12 @@ def encode_katakana(text):
if char in TXT_ENC_KATAKANA_MAP:
encoded.append(TXT_ENC_KATAKANA_MAP[char])
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.
pass
return b"".join(encoded)
TXT_ENC_KATAKANA_MAP = {
# Maps UTF-8 Katakana symbols to KATAKANA Page Codes
# TODO: has this really to be hardcoded?

View File

@ -67,7 +67,8 @@ class Encoder(object):
).format(encoding, ','.join(self.codepages.keys())))
return encoding
def _get_codepage_char_list(self, encoding):
@staticmethod
def _get_codepage_char_list(encoding):
"""Get codepage character list
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
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
:param char: char to encode

View File

@ -30,7 +30,7 @@ printer:
)
class TestCLI():
class TestCLI:
""" Contains setups, teardowns, and tests for CLI
"""

View File

@ -35,4 +35,4 @@ def test_lacks_support(bctype, supports_b):
with pytest.raises(BarcodeTypeError):
instance.barcode('test', bctype)
assert instance.output == b''
assert instance.output == b''

View File

@ -17,10 +17,10 @@ def test_line_spacing_rest():
def test_line_spacing_error_handling():
printer = Dummy()
with assert_raises(ValueError):
printer.line_spacing(99, divisor=44)
printer.line_spacing(99, divisor=44)
with assert_raises(ValueError):
printer.line_spacing(divisor=80, spacing=86)
printer.line_spacing(divisor=80, spacing=86)
with assert_raises(ValueError):
printer.line_spacing(divisor=360, spacing=256)
printer.line_spacing(divisor=360, spacing=256)
with assert_raises(ValueError):
printer.line_spacing(divisor=180, spacing=256)
printer.line_spacing(divisor=180, spacing=256)

View File

@ -22,7 +22,6 @@ from escpos.katakana import encode_katakana
from escpos.exceptions import CharCodeError, Error
class TestEncoder:
"""
Tests the single encoders.

View File

@ -26,6 +26,7 @@ if six.PY3:
else:
mock_open_call = '__builtin__.open'
@given(path=text())
def test_load_file_printer(mocker, path):
"""test the loading of the file-printer"""

View File

@ -35,4 +35,4 @@ class TestCustomProfile:
assert Profile(columns=10).get_columns('sdfasdf') == 10
def test_features(self):
assert Profile(features={'foo': True}).supports('foo')
assert Profile(features={'foo': True}).supports('foo')