lemonEX / zhpy

Automatically exported from code.google.com/p/zhpy
0 stars 0 forks source link

zhpy 交互式命令行在中文XP系统下有问题。 #25

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In winxp, open a cmd shell.
2. Run zhpy version 0.92 - 1.4b1 (affect all releases)
3. Input 
[[[
print "呵呵"
打印 "呵呵"
]]]

What is the expected output? What do you see instead?
[[[
>>> print "呵呵"
鏈€鏈€
>>> 打印 "呵呵"
can't recognize your language, set to utf-8
Traceback (most recent call last):
  File "C:\Python25\scripts\zhpy-script.py", line 8, in <module>
    load_entry_point('zhpy==0.9.2', 'console_scripts', 'zhpy')()
  File
"c:\python25\lib\site-packages\zhpy-0.9.2-py2.5.egg\zhpy\zhpy_cmd.py", li
ne 123, in commandtool
    interpreter()
  File
"c:\python25\lib\site-packages\zhpy-0.9.2-py2.5.egg\zhpy\zhpy_interpreter
.py", line 63, in interpreter
    con.interact(banner)
  File "C:\Python25\lib\code.py", line 239, in interact
    more = self.push(line)
  File
"c:\python25\lib\site-packages\zhpy-0.9.2-py2.5.egg\zhpy\zhpy_interpreter
.py", line 40, in push
    more = self.runsource(convertor(source), self.filename)
  File "c:\python25\lib\site-packages\zhpy-0.9.2-py2.5.egg\zhpy\zhpy.py",
line 2
18, in convertor
    utest = test.decode('utf8')
  File "C:\Python25\lib\encodings\utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position 0:
unexpecte
d code byte
]]]

Please use labels and text to provide additional information.

Original issue reported on code.google.com by ren...@gmail.com on 27 Nov 2007 at 4:32

GoogleCodeExporter commented 8 years ago
繁中 XP 是 ok 的

Original comment by gasolin on 21 Dec 2007 at 2:47

GoogleCodeExporter commented 8 years ago
找到最可能原因是 interpreter 在收到 big-5/gb 時沒有先轉碼成 
utf-8。 fixed in [690]

Original comment by gasolin on 14 Jan 2008 at 7:35

GoogleCodeExporter commented 8 years ago
用今天最新的SVN版本,直接打印没有问题,但是:
>>> 打印 u"赫赫"
Traceback (most recent call last):
  File "<console>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\xb5' in position 1: il
legal multibyte sequence

Original comment by ren...@gmail.com on 14 Jan 2008 at 12:55

GoogleCodeExporter commented 8 years ago
如果在转换的时候判断一下是unicode还是string就好了.
type(test)==types.UnicodeType

Original comment by ren...@gmail.com on 17 Jan 2008 at 3:17

GoogleCodeExporter commented 8 years ago
如果 isinstance(test, unicode):
    #已经是unicode
    pass;
否则:
    test.encode(...);

Original comment by ren...@gmail.com on 17 Jan 2008 at 3:27

GoogleCodeExporter commented 8 years ago
如果强制不使用
打印 "呵呵"
而改用
打印 u"呵呵"
把要显示的字符强制指定为unicode, 
这样可以解决win32的CMD下显示不正常的问题.
这样zhpy.convertor里的这行encode就不需要result = 
result.encode(encoding)了.

Original comment by ren...@gmail.com on 17 Jan 2008 at 4:35

GoogleCodeExporter commented 8 years ago
採用 comment 5 的方式似乎比強制要求使用者好 :)

Original comment by gasolin on 17 Jan 2008 at 10:58

GoogleCodeExporter commented 8 years ago
經過試驗,暫不支持 unicode 字串 (u'xxx') 可能是比較好的. 
畢竟 u'' 中的編碼不見得就是真的 unicode. 
而且跑測試結果會讓多數程式執行不正常,

unicode 字串支援等下一版再處理。現在一律使用一般 string ''

Original comment by gasolin on 17 Jan 2008 at 5:33

GoogleCodeExporter commented 8 years ago

Original comment by gasolin on 6 Mar 2008 at 2:54