Export to GitHub

zhpy - issue #9

Add zhpy interpreter


Posted on Aug 24, 2007 by Grumpy Bear

draft zhpy interpreter implementation http://groups.google.com/group/python-cn/browse_thread/thread/d85ad9a285998774/a55caca591268753#a55caca591268753

{{{ zhpy.py

os.chdir(os.getcwd())
+# no args
+if len(sys.argv) == 1:
+    from zhipy import interpreter
+    interpreter()
+    sys.exit()

}}}

{{{

zhipy by jiahua huang

-- coding: utf-8 --

def _indict(dic): '''indict({'a':'1'}) -> {'1':'a'} ''' d = {} dick = dic.keys() dick.reverse() map(d.update, map(lambda i: {dic[i]:i}, dick)) return d

from zhpy import * en_cndict = _indict(cndict) en_twdict = _indict(twdict)

"""def convertToChinese(s, l, t): tmp = t[0] if tmp in en_twdict: return en_twdict[tmp] elif re.match(r'^p_[_\d]*v\d?$', tmp): tmp2 = '' for i in tmp.split(''): if i.isdigit(): tmp2 += unichr(int(i)).encode('utf8') return tmp2 else: return tmp

englishChars = srange('[0-z]') englishWord = Word(englishChars) englishWord.setParseAction(convertToChinese) englishWord = quotedString | englishWord"""

import code def code4zh2en(code): """ """ for k, v in replacedict.items(): code = code.replace(k,v)

ucode = code.decode("utf8")
result = chineseWord.transformString(ucode)
result = result.encode("utf8")
return result

class console(code.InteractiveConsole): """ """ def push(self, line): line = code4zh2en(line) self.buffer.append(line) source = "\n".join(self.buffer) more = self.runsource(source, self.filename) if not more: self.resetbuffer() return more

def interpreter(): """ zhpy interpreter """ import readline, rlcompleter readline.parse_and_bind("tab: complete") con = console() banner = 'Python %s\nzhipy.py - An Chinese Interactive Python shell'%(sys.version) con.interact(banner) }}}

Comment #1

Posted on Aug 30, 2007 by Grumpy Bear

fixed in [198]

Status: Fixed

Labels:
Type-Enhancement Priority-Critical