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

@ -56,5 +56,6 @@ def print_codepage(printer, codepage):
printer._raw(sep)
printer._raw('\n')
if __name__ == '__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.
@ -103,6 +100,7 @@ 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,7 +12,8 @@ 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()

View File

@ -97,7 +97,8 @@ class Escpos(object):
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":
@ -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

@ -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"""