Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
GoogleCodeExporter opened this issue Aug 8, 2015 · 9 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

繁中 XP 是 ok 的

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

@GoogleCodeExporter
Copy link
Author

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

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

@GoogleCodeExporter
Copy link
Author

用今天最新的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
Copy link
Author

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

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

@GoogleCodeExporter
Copy link
Author

如果 isinstance(test, unicode):
    #已经是unicode
    pass;
否则:
    test.encode(...);

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

@GoogleCodeExporter
Copy link
Author

如果强制不使用
打印 "呵呵"
而改用
打印 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
Copy link
Author

採用 comment 5 的方式似乎比強制要求使用者好 :)

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

@GoogleCodeExporter
Copy link
Author

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

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

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

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant