pci.PCIIds: Fix reading pci.ids with UTF-8 chars and test it#40
Merged
bernhardkaindl merged 3 commits intoxenserver:masterfrom May 23, 2023
Merged
pci.PCIIds: Fix reading pci.ids with UTF-8 chars and test it#40bernhardkaindl merged 3 commits intoxenserver:masterfrom
bernhardkaindl merged 3 commits intoxenserver:masterfrom
Conversation
f2a89be to
7e4478c
Compare
Codecov Report
@@ Coverage Diff @@
## master #40 +/- ##
==========================================
+ Coverage 69.25% 69.34% +0.09%
==========================================
Files 20 21 +1
Lines 3415 3419 +4
==========================================
+ Hits 2365 2371 +6
+ Misses 1050 1048 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
psafont
approved these changes
May 17, 2023
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
4a0af4c to
bd35c1c
Compare
The ACK XAPI plugin calls xcp.pci.PCIIds.read() without an UTF-8 locale set.
Problem:
Because there are Unicode characters ('²') in `/usr/share/hwdata/pci.ids`,
it needs to be opened with UTF-8 decoding set up for `read()` to succeed.
But, because XAPI plugins are not started with the locale set to an UTF-8
locale this fails on Python 3.6 because in this case, it defaults to using
the `ascii` codec which does not support `ord()` >= 128.
Thus, `xcp.pci.PCIIds.read()` fails to read the PCI IDs database when no
locale is set on Python 3.6.
Fix:
Wrap the open() call using a function which enables the UTF-8 encoding
when run on Python 3.0 or newer.
The use of the wrapper function also fixes the pylint warning
`unspecified-encoding` for not passing `encoding="utf-8"`.
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
bd35c1c to
daab4d1
Compare
rosslagerwall
approved these changes
May 23, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the remaining, second half of PR 35: #35 (which @psafont already approved before):
Fix the remaining Python3 bug in xcp.pci:
The ACK XAPI plugin triggers an Python3 issye by calling xcp.pci.PCIIds.read() without an UTF-8 locale set (XAPI calls plugins without an UTF-8 locale it seems)
Problem:
²) in/usr/share/hwdata/pci.idsit needs to be opened with UTF-8 decoding set up forread()to succeed.UTF-8locale, this fails on Python 3.6 because in this case, it defaults to using theasciicodec which does not supportord()>= 128.xcp.pci.PCIIds.read()fails to read the PCI IDs database when nolocale is set on Python 3.6.
Fix:
unspecified-encodingfor not passingencoding="utf-8".It contains 3 commits:
/usr/share/hwdata/pci.idswith UTF-8 chars and test itAdded a README:
https://github.com/xenserver-next/python-libs/blob/utf8-pci.ids/README-Unicode.md