René's URL Explorer Experiment


Title: fix: reset MagicEncode after font switch (ESC M) and hw init (ESC @) by larsblumberg · Pull Request #729 · python-escpos/python-escpos · GitHub

Open Graph Title: fix: reset MagicEncode after font switch (ESC M) and hw init (ESC @) by larsblumberg · Pull Request #729 · python-escpos/python-escpos

X Title: fix: reset MagicEncode after font switch (ESC M) and hw init (ESC @) by larsblumberg · Pull Request #729 · python-escpos/python-escpos

Description: Bug description Some printers (confirmed: Netum NT-5890K) silently reset their active code page back to the factory default after a font switch (ESC M n). MagicEncode was unaware of this hardware-side reset: its cached self.encoding remained stale, causing subsequent text() calls to skip CODEPAGE_CHANGE. Non-ASCII characters were then sent in the previously-active encoding (e.g. CP1257) but interpreted by the printer under its default code page, producing garbled output. ESC @ (hw("INIT")) is defined in the ESC/POS spec as a full printer reset that restores all settings to factory defaults, including the active code page — so the same fix applies there by spec. Proposed fix Fix: add MagicEncode.reset_encoding() which clears both self.encoding and self.encoder.used_encodings, and call it from set() after every font change and from hw() after INIT. This forces a fresh code page selection and a CODEPAGE_CHANGE re-emission before the next text output. Why used_encodings must also be cleared: self.encoding = None is enough to ensure a CODEPAGE_CHANGE is emitted. However, used_encodings biases find_suitable_encoding() toward previously- used code pages. After a reset, that preference is stale: on NT-5890K the previously-used CP1257 does not function correctly after ESC M, so MagicEncode would re-select it, emit CODEPAGE_CHANGE → CP1257, and send e.g. ü as 0xFC — wrong in the printer's default code page. Clearing used_encodings removes the stale bias and lets slot-number ordering take over, landing on CP850 where ü = 0x81, a byte that is correct in virtually every Western code page regardless of whether the printer honours the code page switch. Demo of the the bug and the applied fix: Future work Follow-up: used_encodings could be removed from MagicEncode entirely. self.encoding is the mechanism that actually avoids redundant switches: it keeps the current code page as long as it can encode the next character, without consulting used_encodings at all. used_encodings is only consulted when a switch is already unavoidable — at which point it cannot prevent any switch, it can only gamble on which encoding might be needed again later. That saves at most one future switch in the rare case where the same non-default code page is needed again after having been forced away. Removing used_encodings would also make reset_encoding() unnecessary: with only self.encoding to clear, callers would just write self.magic.encoding = None directly, with no need for a helper method.

Open Graph Description: Bug description Some printers (confirmed: Netum NT-5890K) silently reset their active code page back to the factory default after a font switch (ESC M n). MagicEncode was unaware of this hardware-s...

X Description: Bug description Some printers (confirmed: Netum NT-5890K) silently reset their active code page back to the factory default after a font switch (ESC M n). MagicEncode was unaware of this hardware-s...

Opengraph URL: https://github.com/python-escpos/python-escpos/pull/729

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:9fb533e3-34b2-dd45-b5e9-f9f8f8e7bbda
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id9D62:1138FF:9F76F9:D90431:6A4D4FA8
html-safe-nonce4c9816587337e9d36de09a8c7bc42364932c75db061eb5e1027a7972d58ab617
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDYyOjExMzhGRjo5Rjc2Rjk6RDkwNDMxOjZBNEQ0RkE4IiwidmlzaXRvcl9pZCI6IjcyNjE3MDUzNTc1MTYxNjUwMzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacd1121092f5f512885d3428f7258ca64f21dda285be14c9e612e3024e069fdda3
hovercard-subject-tagpull_request:3428498864
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python-escpos/python-escpos/pull/729/files
twitter:imagehttps://avatars.githubusercontent.com/u/5980316?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/5980316?s=400&v=4
og:image:altBug description Some printers (confirmed: Netum NT-5890K) silently reset their active code page back to the factory default after a font switch (ESC M n). MagicEncode was unaware of this hardware-s...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python-escpos/python-escpos git https://github.com/python-escpos/python-escpos.git
octolytics-dimension-user_id16302939
octolytics-dimension-user_loginpython-escpos
octolytics-dimension-repository_id32363483
octolytics-dimension-repository_nwopython-escpos/python-escpos
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id32363483
octolytics-dimension-repository_network_root_nwopython-escpos/python-escpos
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release56fc8347865a14e2ec811533d68f929cf4e0ec19
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-escpos/python-escpos/pull/729/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-escpos%2Fpython-escpos%2Fpull%2F729%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-escpos%2Fpython-escpos%2Fpull%2F729%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-escpos%2Fpython-escpos
Reloadhttps://github.com/python-escpos/python-escpos/pull/729/files
Reloadhttps://github.com/python-escpos/python-escpos/pull/729/files
Reloadhttps://github.com/python-escpos/python-escpos/pull/729/files
Please reload this pagehttps://github.com/python-escpos/python-escpos/pull/729/files
python-escpos https://github.com/python-escpos
python-escposhttps://github.com/python-escpos/python-escpos
Notifications https://github.com/login?return_to=%2Fpython-escpos%2Fpython-escpos
Fork 312 https://github.com/login?return_to=%2Fpython-escpos%2Fpython-escpos
Star 1.3k https://github.com/login?return_to=%2Fpython-escpos%2Fpython-escpos
Code https://github.com/python-escpos/python-escpos
Issues 63 https://github.com/python-escpos/python-escpos/issues
Pull requests 24 https://github.com/python-escpos/python-escpos/pulls
Discussions https://github.com/python-escpos/python-escpos/discussions
Actions https://github.com/python-escpos/python-escpos/actions
Projects https://github.com/python-escpos/python-escpos/projects
Security and quality 0 https://github.com/python-escpos/python-escpos/security
Insights https://github.com/python-escpos/python-escpos/pulse
Code https://github.com/python-escpos/python-escpos
Issues https://github.com/python-escpos/python-escpos/issues
Pull requests https://github.com/python-escpos/python-escpos/pulls
Discussions https://github.com/python-escpos/python-escpos/discussions
Actions https://github.com/python-escpos/python-escpos/actions
Projects https://github.com/python-escpos/python-escpos/projects
Security and quality https://github.com/python-escpos/python-escpos/security
Insights https://github.com/python-escpos/python-escpos/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython-escpos%2Fpython-escpos%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython-escpos%2Fpython-escpos%2Fissues%2Fnew%2Fchoose
larsblumberghttps://github.com/larsblumberg
python-escpos:masterhttps://github.com/python-escpos/python-escpos/tree/master
larsblumberg:fix/reset-magic-encoding-after-font-switchhttps://github.com/larsblumberg/python-escpos/tree/fix/reset-magic-encoding-after-font-switch
Conversation 9 https://github.com/python-escpos/python-escpos/pull/729
Commits 5 https://github.com/python-escpos/python-escpos/pull/729/commits
Checks 0 https://github.com/python-escpos/python-escpos/pull/729/checks
Files changed https://github.com/python-escpos/python-escpos/pull/729/files
Please reload this pagehttps://github.com/python-escpos/python-escpos/pull/729/files
fix: reset MagicEncode after font switch (ESC M) and hw init (ESC @) https://github.com/python-escpos/python-escpos/pull/729/files#top
Show all changes 5 commits https://github.com/python-escpos/python-escpos/pull/729/files
ab15511 fix: reset MagicEncode after font switch (ESC M) and hw init (ESC @) larsblumberg Mar 21, 2026 https://github.com/python-escpos/python-escpos/pull/729/commits/ab15511889e1cf091454a2b1122784d8c2bec226
f6f2dbf test: add TestResetEncoding tests for MagicEncode.reset_encoding() larsblumberg Mar 21, 2026 https://github.com/python-escpos/python-escpos/pull/729/commits/f6f2dbf99e9f25dda45600465d88db87be45915e
052a8f4 docs: add PR #729 link to reset_encoding comments and docstring larsblumberg Mar 21, 2026 https://github.com/python-escpos/python-escpos/pull/729/commits/052a8f4791e3fbc8fed3fb9d2ec61d3290b39a40
729aa49 fix: only reset encoding on actual font change, not every set_with_de… larsblumberg Apr 22, 2026 https://github.com/python-escpos/python-escpos/pull/729/commits/729aa4959fa5d4b85f520a4bfce0ad1ca106670e
2779497 docs: condense comments per reviewer feedback larsblumberg Apr 24, 2026 https://github.com/python-escpos/python-escpos/pull/729/commits/2779497df4dc29a1fc55a40142a0114cbb0dd8d6
Clear filters https://github.com/python-escpos/python-escpos/pull/729/files
Please reload this pagehttps://github.com/python-escpos/python-escpos/pull/729/files
Please reload this pagehttps://github.com/python-escpos/python-escpos/pull/729/files
escpos.py https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
magicencode.py https://github.com/python-escpos/python-escpos/pull/729/files#diff-a364b8354b431136a8e7a1c92df0f2575a4a32328958be421cecb341ca269923
test_magicencode.py https://github.com/python-escpos/python-escpos/pull/729/files#diff-ae6fd9e3fc6d93c6e92a4f634e5b45dbed574ba33f3897d1042d92fbce9cae41
src/escpos/escpos.pyhttps://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
View file https://github.com/python-escpos/python-escpos/blob/2779497df4dc29a1fc55a40142a0114cbb0dd8d6/src/escpos/escpos.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-escpos/python-escpos/pull/729/{{ revealButtonHref }}
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
https://github.com/python-escpos/python-escpos/pull/729/files#diff-91425ded8755c4787655c26fd1d5c170d51b6953802ca2ba55ad9dd8bab0191e
src/escpos/magicencode.pyhttps://github.com/python-escpos/python-escpos/pull/729/files#diff-a364b8354b431136a8e7a1c92df0f2575a4a32328958be421cecb341ca269923
View file https://github.com/python-escpos/python-escpos/blob/2779497df4dc29a1fc55a40142a0114cbb0dd8d6/src/escpos/magicencode.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-escpos/python-escpos/pull/729/{{ revealButtonHref }}
https://github.com/python-escpos/python-escpos/pull/729/files#diff-a364b8354b431136a8e7a1c92df0f2575a4a32328958be421cecb341ca269923
https://github.com/python-escpos/python-escpos/pull/729/files#diff-a364b8354b431136a8e7a1c92df0f2575a4a32328958be421cecb341ca269923
test/test_magicencode.pyhttps://github.com/python-escpos/python-escpos/pull/729/files#diff-ae6fd9e3fc6d93c6e92a4f634e5b45dbed574ba33f3897d1042d92fbce9cae41
View file https://github.com/python-escpos/python-escpos/blob/2779497df4dc29a1fc55a40142a0114cbb0dd8d6/test/test_magicencode.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-escpos/python-escpos/pull/729/{{ revealButtonHref }}
https://github.com/python-escpos/python-escpos/pull/729/files#diff-ae6fd9e3fc6d93c6e92a4f634e5b45dbed574ba33f3897d1042d92fbce9cae41
https://github.com/python-escpos/python-escpos/pull/729/files#diff-ae6fd9e3fc6d93c6e92a4f634e5b45dbed574ba33f3897d1042d92fbce9cae41
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.