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.

Title: Inconsistency between string.letters and default encoding.
Type: Stage:
Components: Windows Versions: Python 2.5
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: loewis, ramong
Priority: normal Keywords:

Created on 2008-08-05 00:33 by ramong, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg70725 - (view) Author: Ramon Garcia (ramong) Date: 2008-08-05 00:33
In python on Windows, under Idle, the string.letters includes extended
characters. But the default codec, used when translating from string to
unicode, is still ascii. This behaviour causes crashes with python win32

>>> string.letters


But still, unless the user customizes the installation,
sys.getdefaultencoding() returns ascii.

The consequence is that after instating a COM object, pywin32 211 issues
this exception:

  File "C:\Python25\Lib\site-packages\win32com\client\", line
297, in MakeFuncMethod
    return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File "C:\Python25\Lib\site-packages\win32com\client\", line
318, in MakeDispatchFuncMethod
    s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc,
names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):'
  File "C:\Python25\Lib\site-packages\win32com\client\", line
604, in BuildCallList
    argName = MakePublicAttributeName(argName)
  File "C:\Python25\Lib\site-packages\win32com\client\", line
542, in MakePublicAttributeName
    return filter( lambda char: char in valid_identifier_chars, className)
  File "C:\Python25\Lib\site-packages\win32com\client\", line
542, in <lambda>
    return filter( lambda char: char in valid_identifier_chars, className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x83 in position 52:
ordinal not in range(128)

The line that causes this exception is from

This fragment is enough to reproduce the bug (from in

valid_identifier_chars = string.letters + string.digits + "_"
return filter( lambda char: char in valid_identifier_chars, className)

Try to print the expression in the return statement and set className to
anything you wish in Unicode. It will crash

It is contradictory that the default codec does not allow translation of
characters  0x83, and that string.letters includes it. If one regards
this character as printable, then it should be encoded successfully.
msg70730 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-08-05 05:12
That's a bug in the Win32 extensions. They shouldn't use string.letters,
but string.ascii_letters, in particular when they check for valid
identifier chars.

Closing this report as "won't fix".
Date User Action Args
2022-04-11 14:56:37adminsetgithub: 47752
2008-08-05 05:12:47loewissetstatus: open -> closed
resolution: wont fix
messages: + msg70730
nosy: + loewis
2008-08-05 00:33:52ramongcreate