-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic support for MSI / Plessey #191
base: main
Are you sure you want to change the base?
Conversation
byteorder and encoding parameters default to None ; user must specifically set them to enable conversion of strings or bytes
for more information, see https://pre-commit.ci
Codecov ReportBase: 80.63% // Head: 79.36% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #191 +/- ##
==========================================
- Coverage 80.63% 79.36% -1.27%
==========================================
Files 17 17
Lines 888 916 +28
==========================================
+ Hits 716 727 +11
- Misses 172 189 +17
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wikipedia says "The MSI bar code represents only digits 0–9; it does not support letters or symbols.".
Is the approach taken for encoding strings a standard one? Do you have a reference for it?
barcode/codex.py
Outdated
@@ -129,7 +129,7 @@ class Code128(Barcode): | |||
The writer to render the barcode (default: SVGWriter). | |||
""" | |||
|
|||
name = "Code 128" | |||
ame = "Code 128" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops :-s my keyboard is depressed
barcode/codex.py
Outdated
:parameters: | ||
code : int or bytes or string | ||
Code MSI int without checksum (added automatically). | ||
Code MSI bytes without checksum. requires byteorder for int conversion | ||
Code MSI string without checksum. requires encoding and byteorder for int conversion | ||
writer : barcode.writer Instance | ||
The writer to render the barcode (default: SVGWriter). | ||
byteorder : string | ||
'big' or 'little' ; to convert bytes to int | ||
encoding : string | ||
if set, convert bytes to string and use this as a label. defaults to utf-8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use regular sphinx format here so docs render properly.
:parameters: | |
code : int or bytes or string | |
Code MSI int without checksum (added automatically). | |
Code MSI bytes without checksum. requires byteorder for int conversion | |
Code MSI string without checksum. requires encoding and byteorder for int conversion | |
writer : barcode.writer Instance | |
The writer to render the barcode (default: SVGWriter). | |
byteorder : string | |
'big' or 'little' ; to convert bytes to int | |
encoding : string | |
if set, convert bytes to string and use this as a label. defaults to utf-8 | |
:param code: Code MSI int without checksum (added automatically). | |
Code MSI bytes without checksum. requires byteorder for int conversion | |
Code MSI string without checksum. requires encoding and byteorder for int conversion | |
:param writer: The writer to render the barcode (default: SVGWriter). | |
:param byteorder: 'big' or 'little' ; to convert bytes to int | |
:param encoding : if set, convert bytes to string and use this as a label. defaults to utf-8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had copied the format from Code128... last commit fixes other docstrings in codex.py
barcode/codex.py
Outdated
|
||
name = "MSI/Modified Plessey" | ||
|
||
def __init__(self, code, writer=None, byteorder=None, encoding=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type annotations missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please help me with this? I don't know how to do it when multiple types are allowed.
I have severe back and joint issues that are made much worse when sitting for extended periods of time, so I will not dig further into an obscure doc to find out.
it's not standard at all (hence the new defaults). it's a workaround because no 1D barcode that I know of can encode arbitrary bytes (at most a variant of extended ASCII) the MSI barcode will encode just an int (hence the new default values for "byteorder" and "encoding" : the user must force this workaround, otherwise an exception will be raised at init. I specifically chose to use MSI for this purpose, because since it normally allows only integer encoding the risk of confusion is minimal (user has to explicitly force the conversion : the same approach with ie. Code128 would get very confusing) does this seem like a reasonable approach? it's a quite inefficient method of encoding data (mostly because of BCD being inefficient in itself) but if the purpose is just to encode short strings it's acceptable. the code could be extended to split longer strings on multiple lines (sort-of like DataBar does) that could be read sequentially. |
also, from https://www.dynamsoft.com/blog/insights/the-comprehensive-guide-to-1d-and-2d-barcodes/ :
This basically means that MSI codes are used "internally" by organizations, so it is unlikely that any "consumer" will stumble on such a code (those codes are used in a specific context) ; this is - again - less chance for confusion printing the decoded string under the barcode lessens even more the risk of confusion FIY, for displaying bytestrings that cannot be decoded (I have a great deal of those), I wrote https://github.com/petaflot/bytes_as_braille ; I am likely to add a "label" argument to MSI.init() to let the user specify the label - I didn't want to make |
to encode strings, just use something else (such as Code128)
for more information, see https://pre-commit.ci
|
(also for other types in same file)
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
>>> type(None) <class 'NoneType'> /me confused
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
The JsBarcode project includes multiple implementations of MSI:
|
isn't that javascript? |
It is, but porting the code over to Python would be an easy task. I was just citing it as an implementation of MSI. |
if encoding is not None: | ||
self.label = code.decode(encoding) | ||
else: | ||
self.label = self.code if label is None else label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no variable named label
in this scope.
also allows encoding of strings and bytestrings (allows encoding any symbol) by converting them to int ; in this case, string representation is shown in human-readable string