diff --git a/setup.py b/setup.py index d29d7b9..ef7b5b1 100755 --- a/setup.py +++ b/setup.py @@ -113,6 +113,7 @@ setup( 'pyyaml', 'argparse', 'argcomplete', + 'future' ], setup_requires=[ 'setuptools_scm', diff --git a/src/escpos/magicencode.py b/src/escpos/magicencode.py index ded60b8..770703c 100644 --- a/src/escpos/magicencode.py +++ b/src/escpos/magicencode.py @@ -145,7 +145,7 @@ class Encoder(object): :param encoding: Encoding name to use (must be defined in capabilities) :param defaultchar: Fallback for non-encodable characters """ - codepage_char_map = self.available_characters[encoding] + codepage_char_map = self._get_codepage_char_map(encoding) output_bytes = bytes([self._encode_char(char, codepage_char_map, defaultchar) for char in text]) return output_bytes diff --git a/test/test_function_text.py b/test/test_function_text.py index d4de426..7f3869c 100644 --- a/test/test_function_text.py +++ b/test/test_function_text.py @@ -20,7 +20,7 @@ from escpos.printer import Dummy def get_printer(): - return Dummy(magic_encode_args={'disabled': True, 'encoding': 'cp437'}) + return Dummy(magic_encode_args={'disabled': True, 'encoding': 'CP437'}) @given(text=st.text()) diff --git a/test/test_magicencode.py b/test/test_magicencode.py index 665369e..45b0d55 100644 --- a/test/test_magicencode.py +++ b/test/test_magicencode.py @@ -26,13 +26,13 @@ from escpos.exceptions import CharCodeError, Error class TestEncoder: def test_can_encode(self): - assert not Encoder({'cp437': 1}).can_encode('cp437', u'€') - assert Encoder({'cp437': 1}).can_encode('cp437', u'á') + assert not Encoder({'CP437': 1}).can_encode('CP437', u'€') + assert Encoder({'CP437': 1}).can_encode('CP437', u'á') assert not Encoder({'foobar': 1}).can_encode('foobar', 'a') def test_find_suitable_encoding(self): - assert not Encoder({'cp437': 1}).find_suitable_encoding(u'€') - assert Encoder({'cp858': 1}).find_suitable_encoding(u'€') == 'cp858' + assert not Encoder({'CP437': 1}).find_suitable_encoding(u'€') + assert Encoder({'CP858': 1}).find_suitable_encoding(u'€') == 'CP858' @raises(ValueError) def test_get_encoding(self): @@ -51,17 +51,17 @@ class TestMagicEncode: def test_init_from_none(self, driver): encode = MagicEncode(driver, encoding=None) - encode.write_with_encoding('cp858', '€ ist teuro.') + encode.write_with_encoding('CP858', '€ ist teuro.') assert driver.output == b'\x1bt\x13\xd5 ist teuro.' def test_change_from_another(self, driver): - encode = MagicEncode(driver, encoding='cp437') - encode.write_with_encoding('cp858', '€ ist teuro.') + encode = MagicEncode(driver, encoding='CP437') + encode.write_with_encoding('CP858', '€ ist teuro.') assert driver.output == b'\x1bt\x13\xd5 ist teuro.' def test_no_change(self, driver): - encode = MagicEncode(driver, encoding='cp858') - encode.write_with_encoding('cp858', '€ ist teuro.') + encode = MagicEncode(driver, encoding='CP858') + encode.write_with_encoding('CP858', '€ ist teuro.') assert driver.output == b'\xd5 ist teuro.' class TestWrite: @@ -72,14 +72,14 @@ class TestMagicEncode: assert driver.output == b'\x1bt\x0f\xa4 ist teuro.' def test_write_disabled(self, driver): - encode = MagicEncode(driver, encoding='cp437', disabled=True) + encode = MagicEncode(driver, encoding='CP437', disabled=True) encode.write('€ ist teuro.') assert driver.output == b'? ist teuro.' def test_write_no_codepage(self, driver): encode = MagicEncode( - driver, defaultsymbol="_", encoder=Encoder({'cp437': 1}), - encoding='cp437') + driver, defaultsymbol="_", encoder=Encoder({'CP437': 1}), + encoding='CP437') encode.write(u'€ ist teuro.') assert driver.output == b'_ ist teuro.' @@ -87,7 +87,7 @@ class TestMagicEncode: def test(self, driver): encode = MagicEncode(driver) - encode.force_encoding('cp437') + encode.force_encoding('CP437') assert driver.output == b'\x1bt\x00' encode.write('€ ist teuro.')