[issue21138] mimetypes.MimeType UnicodeDecodeError

2014-04-02 Thread tanbro

New submission from tanbro:

when new a mimetypes.MimeType instance in a my Windows, whose default coding is 
mbcs, UnicdeDecodeError occurred.

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from mimetypes import MimeTypes
>>> mt = MimeTypes()
Traceback (most recent call last):
  File "", line 1, in 
  File "D:\Python27\lib\mimetypes.py", line 66, in __init__
init()
  File "D:\Python27\lib\mimetypes.py", line 358, in init
db.read_windows_registry()
  File "D:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
for subkeyname in enum_types(hkcr):
  File "D:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 8: ordinal
not in range(128)

i think this error was caused by the code in mimetypes.py's line 256

default_encoding = sys.getdefaultencoding() 

if change this line to:

default_encoding = sys.getfilesystemencoding()

such error will be resolved

--
components: Library (Lib)
messages: 215414
nosy: tanbro
priority: normal
severity: normal
status: open
title: mimetypes.MimeType UnicodeDecodeError
type: behavior
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue21138>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21138] mimetypes.MimeType UnicodeDecodeError

2014-04-02 Thread tanbro

tanbro added the comment:

and in line 249, changes:

if isinstance(ctype, unicode):
ctype = ctype.encode(default_encoding) # omit in 3.x!

--

___
Python tracker 
<http://bugs.python.org/issue21138>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25540] virtual conf file encoding error on windows

2015-11-02 Thread tanbro

New submission from tanbro:

When create a new `venv` on windows, sometimes an `UnicodeDecodeError` occurred.

It seems that, it is caused by the system module `site`.

In `Lib/site.py`, line 468::

with open(virtual_conf) as f:
for line in f:
line = line.strip()

The file `virtual_conf` was open with encoding `gbk` which is my windows 
default encoding, but in fact, the file is an `utf-8` one, so i think it should 
be::

with open(virtual_conf, encoding='utf-8') as f:
for line in f:
line = line.strip()

--
messages: 253968
nosy: tanbro
priority: normal
severity: normal
status: open
title: virtual conf file encoding error on windows
type: crash
versions: Python 3.5

___
Python tracker 
<http://bugs.python.org/issue25540>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24307] pip error on windows whose current user name contains non-ascii characters

2015-05-27 Thread tanbro-liu

New submission from tanbro-liu:

On windows8.1 x64, current user name contains non-ascii characters. When 
executing ``pip`` in the command-line, such an error happens::

C:\Users\雪彦>pip
Traceback (most recent call last):
  File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
  File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
  File "C:\Python27\Scripts\pip.exe\__main__.py", line 9, in 
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 210, in 
main
cmd_name, cmd_args = parseopts(args)
  File "C:\Python27\lib\site-packages\pip\__init__.py", line 165, in 
parseopts
parser.print_help()
  File "C:\Python27\lib\optparse.py", line 1676, in print_help
file.write(self.format_help().encode(encoding, "replace"))
  File "C:\Python27\lib\optparse.py", line 1656, in format_help
result.append(self.format_option_help(formatter))
  File "C:\Python27\lib\optparse.py", line 1639, in format_option_help
result.append(group.format_help(formatter))
  File "C:\Python27\lib\optparse.py", line 1120, in format_help
result += OptionContainer.format_help(self, formatter)
  File "C:\Python27\lib\optparse.py", line 1091, in format_help
result.append(self.format_option_help(formatter))
  File "C:\Python27\lib\optparse.py", line 1080, in format_option_help
result.append(formatter.format_option(option))
  File "C:\Python27\lib\optparse.py", line 322, in format_option
help_text = self.expand_default(option)
  File "C:\Python27\lib\site-packages\pip\baseparser.py", line 110, in 
expand_de
fault
return optparse.IndentedHelpFormatter.expand_default(self, 
option)
  File "C:\Python27\lib\optparse.py", line 288, in expand_default
return option.help.replace(self.default_tag, str(default_value))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
9-10: ordi
nal not in range(128)

i think, we can modify /lib/optparse.py line 288 to avoid such an error in 
windows::

  -- return option.help.replace(self.default_tag, str(default_value))
  ++ return option.help.replace(
  ++ self.default_tag,
  ++ default_value.encode(sys.getfilesystemencoding())
  ++ if isinstance(default_value, uicnode)
  ++ else str(default_value)
  ++ )

--
components: Library (Lib)
messages: 244244
nosy: tanbro-liu
priority: normal
severity: normal
status: open
title: pip error on windows whose current user name contains non-ascii 
characters
type: crash
versions: Python 2.7

___
Python tracker 
<http://bugs.python.org/issue24307>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com