Skip to content

Commit 2e26d31

Browse files
authored
Merge pull request #84 from EmbroidePy/tatarize-dst-non-utf8
Error-catch Non-UTF8 DST header
2 parents 2df482d + 22d3fb5 commit 2e26d31

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

pyembroidery/DstReader.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ def process_header_info(out, prefix, value):
5252

5353
def dst_read_header(f, out):
5454
header = f.read(512)
55-
header_string = header.decode('utf8')
56-
for line in [x.strip() for x in header_string.split('\r')]:
57-
if len(line) > 3:
58-
process_header_info(out, line[0:2].strip(), line[3:].strip())
55+
try:
56+
header_string = header.decode('utf8')
57+
for line in [x.strip() for x in header_string.split('\r')]:
58+
if len(line) > 3:
59+
process_header_info(out, line[0:2].strip(), line[3:].strip())
60+
except UnicodeDecodeError: # The header contains non-utf8 information and omitted. See #83
61+
pass
5962

6063

6164
def dst_read_stitches(f, out, settings=None):
@@ -90,7 +93,7 @@ def dst_read_stitches(f, out, settings=None):
9093
trim_distance = settings.get("trim_distance", trim_distance)
9194
clipping = settings.get('clipping', clipping)
9295
if trim_distance is not None:
93-
trim_distance *= 10 # Pixels per mm. Native units are 1/10 mm.
96+
trim_distance *= 10 # Pixels per mm. Native units are 1/10 mm.
9497
out.interpolate_trims(count_max, trim_distance, clipping)
9598

9699

pyembroidery/EmbCompress.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
def expand(data, uncompressed_size=None):
2-
compress = EmbCompress()
3-
return compress.decompress(data, uncompressed_size)
2+
emb_compress = EmbCompress()
3+
return emb_compress.decompress(data, uncompressed_size)
4+
5+
6+
def compress(data):
7+
size = len(data)
8+
return bytearray([(size >> 0) & 0xFF, (size >> 8) & 0xFF, 0x02, 0xA0, 0x01, 0xFE]) + data
49

510

611
class Huffman:

setup.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="pyembroidery",
8-
version="1.4.9",
8+
version="1.4.11",
99
author="Tatarize",
1010
author_email="[email protected]",
1111
description="Embroidery IO library",
@@ -14,9 +14,13 @@
1414
url="https://github.com/EmbroidePy/pyembroidery",
1515
packages=setuptools.find_packages(),
1616
classifiers=(
17-
"Programming Language :: Python :: 2",
18-
"Programming Language :: Python :: 3",
17+
'Development Status :: 5 - Production/Stable',
18+
'Intended Audience :: Developers',
19+
"Programming Language :: Python :: 2.7",
20+
"Programming Language :: Python :: 3.6",
21+
"Programming Language :: Python :: 3.7",
1922
"License :: OSI Approved :: MIT License",
2023
"Operating System :: OS Independent",
24+
'Topic :: Software Development :: Libraries :: Python Modules'
2125
),
2226
)

0 commit comments

Comments
 (0)