Handle bytes from socket.gethostname() in GUIDerator.reseed#413
Open
uttam12331 wants to merge 1 commit into
Open
Handle bytes from socket.gethostname() in GUIDerator.reseed#413uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
On some platforms/configurations socket.gethostname() returns bytes rather than str. GUIDerator.reseed() joins it into the salt with str.join(), which then raises 'TypeError: sequence item 1: expected str instance, bytes found' (and, because a module-level GUIDerator is created on import, this breaks importing boltons.iterutils entirely). Decode the hostname to str when it comes back as bytes. Closes mahmoud#295
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.
Summary
Closes #295.
On some platforms/configurations
socket.gethostname()returnsbytesrather thanstr.GUIDerator.reseed()joins it into the salt withstr.join():which raises
TypeError: sequence item 1: expected str instance, bytes found. Because a module-levelGUIDerator()is created at import time, this can break importingboltons.iterutilsentirely on affected systems.Fix
Decode the hostname to
strwhen it comes back asbytes:Tests
Added
test_guiderator_bytes_hostname(monkeypatchessocket.gethostnameto returnb'myhost') asserting a valid hex GUID is produced without raising.Verified locally:
pytest tests/test_iterutils.py→ 45 passed.