Skip to content

Commit 9ddf7eb

Browse files
committed
allow low letters and _ remove len check
1 parent 54f74aa commit 9ddf7eb

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

dls_barcode/datamatrix/datamatrix.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import logging
2+
import string
3+
from string import ascii_lowercase
4+
5+
from pylibdmtx.pylibdmtx import decode
6+
27
from dls_util.image.image import Image
8+
39
from .locate import Locator
4-
from pylibdmtx.pylibdmtx import decode
5-
import string
610

711
# We predict the location of the center of each square (pixel/bit) in the datamatrix based on the
812
# size and location of the finder pattern, but this can sometimes be slightly off. If the initial
@@ -25,9 +29,7 @@ class DataMatrix:
2529
DEFAULT_SIZE = 14
2630
DEFAULT_SIDE_SIZES = [12, 14]
2731
# allow only capitol letters, digits and dash in the decoded string
28-
ALLOWED_CHARS = set(string.ascii_uppercase + string.digits + '-')
29-
# allow up to 10 chars in the decoded string
30-
ALLOWED_NUMBER_OF_CHARS = 11
32+
ALLOWED_CHARS = set(string.ascii_uppercase + string.ascii_lowercase + string.digits + '-' + '_')
3133

3234
def __init__(self, finder_pattern):
3335
""" Initialize the DataMatrix object with its finder pattern location in an image. To actually
@@ -114,7 +116,7 @@ def _read(self, gray_image):
114116
if len(result) > 0:
115117
d = result[0].data
116118
decoded = d.decode('UTF-8')
117-
if self._contains_allowed_chars_only(decoded) and len(decoded) < self.ALLOWED_NUMBER_OF_CHARS:
119+
if self._contains_allowed_chars_only(decoded):
118120
new_line_removed = decoded.replace("\n","")
119121
self._data = new_line_removed
120122
self._read_ok = True
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import unittest
2+
3+
from mock import Mock, patch
4+
5+
from dls_barcode.datamatrix.datamatrix import DataMatrix
6+
7+
class TestDatamatrix(unittest.TestCase):
8+
9+
def test_contains_allowed_characers(self):
10+
datamatrix = DataMatrix(Mock)
11+
test_string_good = "AbcD123_-"
12+
self.assertTrue(datamatrix._contains_allowed_chars_only(test_string_good))
13+
14+
test_string_bad = "AbcD123_-$<"
15+
self.assertFalse(datamatrix._contains_allowed_chars_only(test_string_bad))
16+
17+
18+
19+

0 commit comments

Comments
 (0)