This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: winreg.QueryValue should return bytes, not unicode
Type: behavior Stage:
Components: Extension Modules, Windows Versions: Python 3.1, Python 3.2
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: brian.curtin, eric.smith, stutzbach
Priority: normal Keywords:

Created on 2010-04-07 15:52 by stutzbach, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg102543 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-04-07 15:52
The Windows RegQueryValue function returns a registry value without returning the corresponding type information (e.g., REG_SZ for string, REG_BINARY for binary data, REG_DWORD for a 32-bit number, etc.).

The corresponding wrapper winreg.QueryValue currently calls PyUnicode_FromUnicode on the return data, which is fine if the type happens to be REG_SZ, but gibberish for anything else.  Since the format of data is unknown, it should return a bytes object rather than a unicode object.

If the user wants a REG_SZ converted to the unicode type automatically, than can use winreg.QueryValueEx instead.  QueryValueEx wraps RegQueryValueEx which *does* return the type information of the underlying value.  QueryValueEx uses the type information to convert to an appropriate Python type if possible (or returns a bytes object for unsupported types).
msg102545 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-04-07 16:33
Jumped the gun here.  RegQueryValue returns ERROR_DATA_INVALID if the value isn't a string, so converting to Unicode is OK.
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52581
2010-04-07 16:33:36stutzbachsetstatus: open -> closed

messages: + msg102545
2010-04-07 16:27:37eric.smithsetnosy: + eric.smith
2010-04-07 15:56:51brian.curtinsetpriority: normal
nosy: + brian.curtin
components: + Extension Modules, - Library (Lib)
2010-04-07 15:52:23stutzbachcreate