├── .hgignore ├── CHANGELOG.txt ├── README.md ├── docs ├── DownloadInstall.txt └── zhpy.nsi ├── setup.cfg ├── zhpy2 ├── AUTHORS.txt ├── CHANGELOG.txt ├── FAQ.txt ├── INSTALL.txt ├── LICENSE.txt ├── NEWS.txt ├── README.txt ├── THANKS.txt ├── TODO.txt ├── examples │ ├── droid │ │ ├── android.py │ │ ├── droid.ini │ │ └── droid.twpy │ ├── game │ │ ├── game.twpy │ │ ├── n_game.py │ │ ├── pygame.ini │ │ └── pygame_icon.bmp │ ├── hello │ │ ├── hello.twpy │ │ ├── hello_arg.twpy │ │ ├── hello_big5.twpy │ │ ├── hello_gb.cnpy │ │ ├── n_hello.py │ │ ├── n_hello_big5.py │ │ └── n_hello_gb.py │ ├── inout │ │ ├── inout │ │ ├── inout.twpy │ │ └── n_inout.py │ ├── loop │ │ ├── contact.cnpy │ │ ├── n_contact.py │ │ ├── n_tabl.py │ │ └── tabl.twpy │ ├── realmath │ │ ├── math.ini │ │ └── math.zhpy │ ├── teashop │ │ ├── n_teashop.py │ │ └── teashop.tw.py │ └── test_example.sh ├── setup.py ├── tests │ ├── ReadMe_test.txt │ ├── __init__.py │ ├── test_api.py │ ├── test_controlflow_cn.py │ ├── test_controlflow_tw.py │ ├── test_keywords_cn.py │ ├── test_keywords_tw.py │ ├── test_types_cn.py │ └── test_types_tw.py └── zhpy │ ├── __init__.py │ ├── commandline.py │ ├── ext │ ├── __init__.py │ └── pygmentplugin.py │ ├── import_hook.py │ ├── info.py │ ├── interpreter.py │ ├── plugcn.py │ ├── plugtw.py │ ├── pyparsing.py │ ├── pyzh.py │ ├── release.py │ ├── zhdc.py │ └── zhpy.py └── zhpy3 ├── cnpy.py ├── core.py ├── examples ├── hello │ └── hello.twpy ├── inout │ └── inout.twpy ├── loop │ ├── contact.cnpy │ └── tabl.twpy └── teashop │ └── teashop.tw.py ├── plugcn.py ├── plugtw.py ├── release.py ├── setup.py ├── twpy.py └── zhdc.py /.hgignore: -------------------------------------------------------------------------------- 1 | .pyc 2 | zhpy.egg* 3 | build* 4 | dist* 5 | ez_setup* 6 | .DS_Store 7 | .egg-info 8 | .redcar 9 | -------------------------------------------------------------------------------- /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | zhpy Changelog 2 | ==================== 3 | 4 | 3.0.0 5 | -------------------- 6 | code name: Tusk 7 | 8 | *Changes* 9 | 10 | *Features* 11 | 12 | * Support python 3! 13 | 14 | *Fixes* 15 | 16 | *Project Updates* 17 | 18 | * use distribute instead of setuptools 19 | 20 | *Contributors* 21 | 22 | Fred Lin, Xin Wang 23 | 24 | 25 | 1.7.4 26 | -------------------- 27 | code name: 28 | 29 | *Changes* 30 | 31 | *Features* 32 | 33 | *Fixes* 34 | 35 | * fix zhpy work in 64, thanks T.C.Chou 36 | 37 | *Project Updates* 38 | 39 | *Contributors* 40 | 41 | Fred Lin, T.C.Chou 42 | 43 | 1.7.3 (12/7/2009) 44 | -------------------- 45 | code name: Justice 46 | 47 | *Changes* 48 | 49 | * Add droid example for Android Scripting Environment 50 | * exclude "tests" folder 51 | * install readline module on Mac 52 | 53 | *Features* 54 | 55 | * Partially Compatible with Android Scripting Environment 56 | * Provide an android.py mockup for desktop development 57 | 58 | *Fixes* 59 | 60 | *Project Updates* 61 | * Move to Mercurial for version control 62 | * NOT TO USE distribute instead of setuptools 63 | 64 | *Contributors* 65 | 66 | Fred Lin, DreamerC 67 | 68 | 1.7.2 (8/11/2009) 69 | -------------------- 70 | code name: Death Thirteen 71 | 72 | *Changes* 73 | 74 | *Features* 75 | 76 | *Fixes* 77 | 78 | * Compatibility with python 2.6 79 | 80 | *Project Updates* 81 | 82 | * update to pyparsing 1.5.2 83 | * update setuptools to date 84 | * test via nose 0.11 85 | 86 | *Contributors* 87 | 88 | Fred Lin 89 | 90 | 1.7.1 (9/11/2008) 91 | -------------------- 92 | code name: Sun 93 | 94 | *Changes* 95 | 96 | * updating "A byte of zhpy" book 97 | 98 | *Features* 99 | 100 | * add realmath example by weijr(Mr. Monkey) 101 | 102 | *Fixes* 103 | 104 | *Project Updates* 105 | 106 | * update to pyparsing 1.5 107 | * update to chardet 1.0.1 108 | 109 | *Contributors* 110 | 111 | Fred Lin, weijr 112 | 113 | 1.7 (5/21/2008) 114 | -------------------- 115 | code name: Lovers 116 | 117 | *Changes* 118 | 119 | remove keywords: 120 | * "其":"self" 121 | 122 | *Features* 123 | 124 | * able to view zhpy version by 'zhpy -V' or 'zhpy --version' command 125 | * intentable interpreter autocomplete in *nix 126 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496812 127 | * chinese keyword autocomplete in *nix 128 | * pygments syntax highlighter placeholder with 'zhpy' for '.py', '.twpy', '.cnpy' (not work properly yet) 129 | 130 | *Fixes* 131 | 132 | *Project Updates* 133 | 134 | * Bob Chao joined as the project member 135 | 136 | *Contributors* 137 | 138 | Fred Lin 139 | 140 | 1.6 (4/12/2008) 141 | -------------------- 142 | code name: Justice 143 | 144 | *Changes* 145 | 146 | * modify banner string 147 | * able to pass 'outcoding' param in zh_exec to control output encoding 148 | * able to pass 'zhtrace' param in try_run to control 149 | if enable chinese traceback 150 | * make try_run support verbose option 151 | 152 | *Features* 153 | 154 | * online zhpy shell in zhpy.appspot.com! 155 | 156 | *Fixes* 157 | 158 | * fix python 2.4 compatibility occurred in 1.5.2, thanks DreamerC's report 159 | * fix no chardet support case 160 | 161 | *Project Updates* 162 | 163 | *Contributors* 164 | 165 | Fred Lin 166 | 167 | 1.5.2 (4/3/2008) 168 | -------------------- 169 | code name: Wheel of Fortune 170 | 171 | *Changes* 172 | 173 | * PEP8 cleanup, thanks ulipad :) 174 | * refactor py_annotator, thanks weijr 175 | * refactor python_convertor 176 | 177 | *Features* 178 | 179 | * no need calling annotator before calling convertor, 180 | annotator will be called automatically 181 | * reduce unnecessary annotator reload, thanks weijr 182 | * add outcoding (output encoding) option in convertor 183 | 184 | *Fixes* 185 | 186 | * fix import_hook 187 | 188 | *Project Updates* 189 | 190 | * update license years 191 | 192 | *Contributors* 193 | 194 | Fred Lin, weijr 195 | 196 | 1.5.1 (3/21/2008) 197 | -------------------- 198 | code name: Empress 199 | 200 | *Changes* 201 | 202 | *Features* 203 | 204 | *Fixes* 205 | 206 | * fix pyzh pattern missing 207 | 208 | *Project Updates* 209 | 210 | *Contributors* 211 | 212 | Fred Lin 213 | 214 | 1.5 (2/29/2008) 215 | -------------------- 216 | code name: Emperor 217 | 218 | *Changes* 219 | 220 | * rename zhimport.py to import_hook.py 221 | * rewrite import_hook from magiccodec, thanks weijr 222 | http://weijr-note.blogspot.com/2008/02/python-magiccodec-01.html 223 | * use isinstance(target,dict) instead of type({}), thanks weijr 224 | * refactor merger 225 | * merge rev_merger to merger 226 | * refactor ini_annotator, py_annotator, 227 | pattern, val_matching, rev_ini_annotator, 228 | rev_py_annotator, trace_annotator to private method 229 | * refactor to distill baseWord 230 | * add some variable docstrings 231 | 232 | *Features* 233 | 234 | * add keywords: 235 | * "屬性":"property", "属性":"property", 236 | * add set methods keyword: 237 | * "定集合":"frozenset", 238 | * "清除":"clear", 239 | * "複製":"copy","拷贝":"copy", 240 | * "加":"add", 241 | * "丟棄":"discard","丢弃":"discard", 242 | * "聯集":"union","联集":"union", 243 | * "交集":"intersection", 244 | * "差集":"difference", 245 | * "對稱差集":"symmetric_difference", "对称差集":"symmetric_difference", 246 | 247 | *Fixes* 248 | 249 | *Project Updates* 250 | 251 | * update to pyparsing 1.4.11 252 | * update setuptools to 0.6.8 253 | * update epydoc to 3.0.1 254 | 255 | *Contributors* 256 | 257 | Fred Lin, weijr 258 | 259 | 1.4 (1/18/2008): 260 | -------------------- 261 | code name: Hang Man 262 | 263 | *Changes* 264 | 265 | * change keyword: 266 | * "元組" instead of "組合":"tuple", 267 | * "元组" instead of "组合":"tuple", 268 | * update example n_tabl.twpy 269 | 270 | *Features* 271 | 272 | * Introdure real chinese traceback support, currently works in compiler mode 273 | 274 | *Fixes* 275 | 276 | * Fix interpreter unicode issue mainly occured on Windows, thanks renhbo 277 | 278 | *Project Updates* 279 | 280 | * use setup.cfg to generate docs 281 | 282 | *Contributors* 283 | 284 | Fred Lin, renhbo 285 | 286 | 1.4b1 (12/3/2007): 287 | -------------------- 288 | code name: Yellow Temperance 289 | 290 | *Changes* 291 | 292 | * change keyword: 293 | * '操作系统错误' instead of '作业系统错误':"OSError" 294 | * '申明' instead of "宣告":"assert" 295 | * "申明錯誤" instead of "宣告錯誤":"AssertionError" 296 | * "申明错误" instead of "宣告错误":"AssertionError" 297 | * add traceback term plugins (not functional yet) 298 | 299 | *Features* 300 | 301 | * while open interpreter, autodetect and show the localized banner 302 | * experimental chinese traceback support in convertor (not support in interpreter) 303 | * add keyword: 304 | * "全域":"global" 305 | * "全域變量":"globals","全域变量":"globals" 306 | * "測試":"test", "测试":"test" 307 | * "物件":"object", "对象":"object" 308 | * able to test though generated python file ($ nosetests n_xxx.py) 309 | 310 | *Fixes* 311 | 312 | * fix triple quote bug, thanks renhbo 313 | * allow cascading 2 identifiers (cascade 3 or more identifiers is not support) 314 | 315 | *Project Updates* 316 | 317 | *Contributors* 318 | 319 | Fred Lin, renhbo 320 | 321 | 1.3 (11/5/2007): 322 | -------------------- 323 | code name: White Snake 324 | 325 | *Changes* 326 | 327 | * Separate traditional and simplified chinese keywords from zhdc to plug[lang].py 328 | * moveout plugins' setuptools dependency, now you can try zhpy without install. 329 | * change keyword: 330 | * "引用錯誤", "引用错误" instead of "参考错误":"ReferenceError" 331 | * make py_annotator work while only plugtw or plugcn exists. 332 | 333 | *Features* 334 | 335 | * support custom name space in zh_exec, thanks renhbo 336 | * able to run the commandline without install 337 | * able to run the interpreter with 4 module ["interpreter", "zhpy", "zhdc", "plug[lang]"] 338 | without install (core mode) 339 | * able to profiling standalone interpreter with "--profile" option 340 | 341 | *Fixes* 342 | 343 | * fix keyword "locals" instead of "local" 344 | * generate proper profix while the origin source is suffixed with '.tw.py' or '.cn.py' 345 | 346 | *Project Updates* 347 | 348 | * include pyparsing in distribution 349 | * doc update 350 | * add official zhpy blog: http://zhpy.blogspot.com/ 351 | * remove zhpy_ext sample 352 | 353 | *Contributors* 354 | 355 | Fred Lin, renhbo 356 | 357 | 1.2 (10/19/2007): 358 | -------------------- 359 | code name: Requiem 360 | 361 | *Changes* 362 | 363 | * Use build-in int function to convert hex string, thanks Jiahua Huang 364 | * refactor repeative tripleQuote pattern to single place (zhpy) 365 | * refactor 'number_to_variable' function to 'zh_chr' function (pyzh) 366 | * refactor 'variable_to_number' function to 'zh_ord' function (zhpy) 367 | * support chinese filename to uri filename while convert with '-p' option 368 | * zh_ord and zh_chr are bi-direction convertable now 369 | * change keyword: 370 | * '最大值' instead of '最大':'max' 371 | * '最小值' instead of '最小':'min' 372 | * '最大值' instead of '最大':'max' 373 | * '最小值' instead of '最小':'min' 374 | * '反转' instead of '逆转':'reverse', 375 | 376 | *Features* 377 | 378 | * add zhimport module to support chinese file name import, thanks Jiahua Huang 379 | * checked in experimental direct zhpy module import(disabled), thanks Jiahua Huang 380 | * add build-in sys module keyword plugin 381 | * add pyzh and bi-directional translation tests 382 | 383 | *Fixes* 384 | 385 | * support multilines comments with triple single quote, thanks renhbo 386 | 387 | *Project Updates* 388 | 389 | * set svn:external to update ez_setup script automaticaly 390 | * renhbo joined as the project member 391 | 392 | *Contributors* 393 | 394 | Fred Lin, Jiahua Huang, renhbo 395 | 396 | 1.1.1 (10/12/2007): 397 | -------------------- 398 | code name: Dark Blue Moon 399 | 400 | *Changes* 401 | 402 | *Features* 403 | 404 | *Fixes* 405 | 406 | * Able to import modules in current directory with interpreter or script, thanks renhbo 407 | * fix python to zhpy command with any ini file in current directory, thanks renhbo 408 | * fix multilines comments translated incorrectly 409 | 410 | *Project Updates* 411 | 412 | * update release note 413 | 414 | *Contributors* 415 | 416 | Fred Lin, renhbo 417 | 418 | 1.1 (10/8/2007): 419 | -------------------- 420 | code name: Echoes 421 | 422 | *Changes* 423 | 424 | *Features* 425 | 426 | * add commandline option '--tw' to convert python code to twpy 427 | * add commandline option '--cn' to convert python code to cnpy 428 | 429 | *Fixes* 430 | 431 | * fix verbose options in commandline tool 432 | * fix zhpy to python function 433 | * remove extra .tw, .cn in reverted filename of python to zhpy 434 | 435 | *Project Updates* 436 | 437 | * update installer code 438 | * update project status to Production/Stable 439 | 440 | *Contributors* 441 | 442 | Fred Lin 443 | 444 | 1.0 (10/3/2007): 445 | -------------------- 446 | code name: Killer Queen 447 | 448 | *Changes* 449 | 450 | * replace keyword 451 | * "鍵列表" instead of "關鍵字列表":"keys" 452 | * "键列表" instead of "关键字列表":"keys" 453 | * "引發","引发" instead of "示警":"raise" 454 | * "評估","评估" instead of "求值":"eval" 455 | 456 | *Features* 457 | 458 | * complete "Byte of Zhpy" book 459 | * add native interpreter banner "zhpy --tw" or "zhpy --cn" 460 | * show keyword number of each plugin in "zhpy --info" command 461 | * add keyword 462 | * "代換":"replace" 463 | * "代换":"replace" 464 | * "初始化":"init", 465 | * "類別方法":"classmethod" 466 | * "类方法":"classmethod" 467 | * "錯誤":"Error" 468 | * "错误":"Error" 469 | * "描述":"repr" 470 | 471 | *Fixes* 472 | 473 | *Project Updates* 474 | 475 | * update Download Install doc 476 | * format inline docs for APIDOC 477 | 478 | *Contributors* 479 | 480 | Fred Lin 481 | 482 | 0.9.4 (9/28/2007): 483 | -------------------- 484 | code name: Silver Chariot 485 | 486 | *Changes* 487 | 488 | * remove chinese punctuations support 489 | * change keyword 490 | * use "檔案", "档案" instead of "文件":"file" 491 | * use "返回" instead of "传回":"return" 492 | * use "組合", "组合" instead of "數組":"tuple" 493 | 494 | *Features* 495 | 496 | * allow zhpy script with commandline arguments 497 | * add keyword: 498 | * "其":"self" 499 | * "我":"self" 500 | 501 | *Fixes* 502 | 503 | * fixed comment shouldn't be translated 504 | * 'byte of zhpy' doc update 505 | 506 | *Project Updates* 507 | 508 | * rename zhpy_interpreter.py to interpreter.py 509 | * rename zhpy_cmd.py to commandline.py 510 | * rename zhpy_info.py to info.py 511 | * new commandline utility 512 | * remove command shortcut: "zhpy [input] [output]", use "zhpy -i [input] -o [output]" or 513 | "zhpy -p [input]" 514 | 515 | *Contributors* 516 | 517 | Fred Lin 518 | 519 | 0.9.3 (09/15/2007): 520 | -------------------- 521 | code name: Gray Tower 522 | 523 | *Changes* 524 | 525 | *Features* 526 | 527 | * catch up exception definitions http://www.chinesepython.org/doc/ref.html 528 | * make chinese punctuation be a plugin 529 | * add keyword: 530 | * "區域變量":"local", "区域变量":"local" 531 | * Downloadable API Doc 532 | 533 | *Fixes* 534 | 535 | * make incorrect ini file not cause exception 536 | * fix replacedict, thanks renhbo 537 | * fix miss-replaced punctuations in quotestring 538 | 539 | *Project Updates* 540 | 541 | * update ez_setup.py to 0.6c7 542 | 543 | *Contributors* 544 | 545 | Fred Lin, renhbo 546 | 547 | 0.9.2 (09/10/2007): 548 | -------------------- 549 | code name: Hierophant Green 550 | 551 | *Changes* 552 | 553 | * move twdict, cndict keyword into plugins 554 | * plugin use object instead of dict to contain more information 555 | * refactory annotator 556 | * update zhpy_ext plugin sample 557 | * keyword change 558 | * "和":"and", "且":"and" instead of "并且":"and" 559 | *"或":"or" instead of "或者":"or" 560 | * "輸入":"raw_input" instead of "输入字符串":"raw_input" 561 | * "浮点数":"float" instead of "小数":"float" 562 | * remove keyword 563 | * "傳回":"return" 564 | * "全局":"global" 565 | 566 | *Features* 567 | 568 | * add keyword 569 | * "非":"not" 570 | * "可調用":"callable", "可调用":"callable" 571 | * "符號":"chr", "符号":"chr" 572 | * "符號轉整數":"ord", "符号转整数":"ord" 573 | * "比較":"cmp","比较":"cmp" 574 | * "複數":"complex","复数":"complex" 575 | * "十六進位":"hex", "十六进制":"hex" 576 | * "列出屬性":"dir", "列出属性":"dir" 577 | * "求值":"eval" 578 | * "文件":"file" 579 | * "输入":"input" 580 | * "取屬性":"getattr", "取属性":"getattr" 581 | * "有屬性":"hasattr", "有属性":"hasattr" 582 | * "設定屬性":"setattr", "设定属性":"setattr" 583 | * "映射":"map" 584 | * "最大":"max", 585 | * "最小":"min", 586 | * "總和":"sum", "总和":"sum" 587 | * "快速範圍":"xrange", "快速范围":"xrange" 588 | * "計數":"count", "计数":"count" 589 | * "索引":"index" 590 | 591 | *Fixes* 592 | 593 | *Project Updates* 594 | 595 | register "twkeyword", "twmethod", "tw_exception", "twzhpy", 596 | "cnkeyword", "cnmethod", "cn_exception", "cnzhpy" as plugin 597 | 598 | *Contributors* 599 | 600 | Fred Lin 601 | 602 | 0.9.1 (09/08/2007): 603 | -------------------- 604 | code name: Magician Red 605 | 606 | *Changes* 607 | 608 | * twdict, cndict now shown in plugin 609 | * worddict formed dynamically without exceptions 610 | * keyword changes 611 | * "中斷" instead of "中止" 612 | 613 | *Features* 614 | 615 | * add keyword: 616 | * "假使":"elif" 617 | * "周蟒":"zhpy" 618 | * "中文執行":"zh_exec", "中文执行":"zh_exec" 619 | 620 | *Fixes* 621 | 622 | * better formatted "zhpy --info" command 623 | * 'byte of zhpy' doc update 624 | 625 | *Project Updates* 626 | 627 | * add download url 628 | 629 | *Contributors* 630 | 631 | Fred Lin 632 | 633 | 0.9 (09/05/2007): 634 | ------------------ 635 | code name: The World 636 | 637 | *Changes* 638 | 639 | * able to pass target dict to merger function 640 | 641 | *Features* 642 | 643 | * module keyword library plug-in system by annotator 644 | * plug-in support for rev_annotator 645 | * annotation support in interpreter 646 | * add command line option '-V/info' for zhpy complete information 647 | * add zhpy_ext as sample plugin template 648 | * add keyword 649 | * "幫助":"help", "帮助":"help" 650 | * "说明":"help" 651 | * Start 'byte of zhpy' doc 652 | 653 | *Fixes* 654 | 655 | * use encoding utf8 as default encoding while auto detection in low confidence(<0.8) 656 | * fix tests cases' doctest 657 | * able to run as script without subname 658 | 659 | *Project Updates* 660 | 661 | *Contributors* 662 | 663 | Fred Lin 664 | 665 | 0.8.1 (09/03/2007): 666 | ------------------ 667 | code name: Hermit Purple 668 | 669 | *Changes* 670 | 671 | * rename zhpyi.py to zhpy_interpreter.py 672 | * update example test cases 673 | * update interpreter banner 674 | 675 | *Features* 676 | 677 | 678 | *Fixes* 679 | 680 | * fix interpreter multiline exception bug 681 | 682 | *Project Updates* 683 | 684 | * Jiahwa Huang joined as the project member 685 | 686 | *Contributors* 687 | 688 | Fred Lin 689 | 690 | 0.8 (08/30/2007): 691 | ------------------ 692 | code name: Stone Free 693 | 694 | *Changes* 695 | 696 | * move all dictionaries to zhdc.py 697 | * move command line tool to zhpy_cmd.py 698 | * use implicit imports 699 | * remove -r option, use -c instead 700 | * keyword changes 701 | * "開頭為" instead of "開始字串", 702 | * "开头为" instead of "开始为" 703 | * "结尾为" instead of "结束为" 704 | * "結尾為" instead of "結束字串" 705 | 706 | *Features* 707 | 708 | * zhpy interpreter, thanks Jiahua Huang 709 | * implement zhpy -> python libraries in pyzh.py 710 | * bi-directional uri variable <-> number function, prototype by Jiahua Huang 711 | * auto detect encodings, now interpreter works on tw/cn windows 712 | * add "-e/--encoding" option to customize the encoding for parsing 713 | * add keyword: 714 | * "執行":"exec", "执行":"exec" 715 | * "布林":"bool", "布尔":"bool" 716 | * "絕對值":"abs", "绝对值":"abs" 717 | * "列舉":"enumerate", "列举":"enumerate" 718 | * "過濾":"filter", "过滤":"filter" 719 | * "打包":"zip" 720 | * "擴展":"extend", "扩展":"extend" 721 | * "插入":"insert", "移除":"remove","排序":"sort" 722 | * "彈出":"pop", "弹出":"pop" 723 | * "列舉":"enumerate", "列举":"enumerate" 724 | * "過濾":"filter", "过滤":"filter" 725 | * "打包":"zip", "打包":"zip", thanks HYRY 726 | * "型別錯誤":"TypeError", "类型错误":"TypeError" 727 | * "下一筆":"next", "下一笔":"next" 728 | * "例外":"Exception" 729 | * "停止迭代":"StopIteration" 730 | * "解碼錯誤":"UnicodeDecodeError","解码错误":"UnicodeDecodeError", 731 | * "導入錯誤":"ImportError","导入错误":"ImportError" 732 | 733 | * add zhpy featured keyword 734 | * "主程式":'if __name__=="__main__"', "主程序":'if __name__=="__main__"' 735 | 736 | *Fixes* 737 | 738 | * keep twdict clean, worddict now real copy from twdict 739 | 740 | *Project Updates* 741 | 742 | * use .tw.py, .cn.py as another zhpy subname to distinguish the coding 743 | * add chardet dependency 744 | 745 | *Contributors* 746 | 747 | Fred Lin, HYRY, Jiahua Huang 748 | 749 | 0.7 (08/25/2007): 750 | ------------------ 751 | code name: Gold Experience 752 | 753 | *Changes* 754 | 755 | * keyword changes 756 | * "全局" instead of "全局变量" 757 | * "导入" instead of "载入" 758 | * "作為" instead of "取名" 759 | * "尝试" instead of "试运行" 760 | * "异常" instead of "错误处理" 761 | * "集合" instead of , "类组" 762 | * "連接" instead of "接合" 763 | * "關鍵字列表" instead of "列出關鍵字" 764 | * "值列表" instead of "列出值" 765 | * "項目列表" instead of "列出項目" 766 | * variables are changed to "p_[var]_v" syntax instead of p[num], 767 | thanks Jiahua Huang 768 | * .has_key() is deprecated, use 'in' 769 | * remove keyword 770 | * "有關鍵字":"has_key", "有关键字":"has_key" 771 | * "若":"if" 772 | * "開啟":"open", "开启":"open" 773 | * remove trail space for pep8 774 | * rename run.sh to test_example.sh 775 | * maintain tw, cn keyword in seperate dict 776 | * Online documents update 777 | 778 | *Features* 779 | 780 | * use universe reference identifier (uri) for 781 | variable/constant/class/methods instead of vnum, thanks Jiahua Huang 782 | * add keyword: 783 | * "作为":"as" 784 | * "最后":"finally" 785 | * "宣告":"assert", "刪除":"del", "执行":"exec" 786 | * "或者":"or","并且":"and", 787 | * "不在":"not in" 788 | * "不為":"is not", "为":"is", "不为":"is not" 789 | 790 | * add "-c/--cmd" option instead of "-r/--raw" to correspond the python command, 791 | "-r/--raw" will be deprecate in next release. 792 | * also test command line options (test_example.sh) 793 | * add contact example (cn) in loop/ 794 | 795 | *Fixes* 796 | 797 | * able to run zhpy in __main__, thanks Jiahua Huang 798 | 799 | *Project Updates* 800 | 801 | * use .twpy, .cnpy as zhpy subname to distinguish the coding 802 | 803 | *Contributors* 804 | 805 | Fred Lin, Jiahua Huang 806 | 807 | 0.6 (08/22/2007): 808 | ------------------ 809 | code name: Crazy Diomand 810 | 811 | *Changes* 812 | 813 | * internal refactor the try_run method 814 | * rename traditional chinese test cases 815 | * Online documents update 816 | 817 | *Features* 818 | 819 | * add "-r/--raw": "input raw zhpy source and run" option for 820 | scripting usage, idea from Jiahua Huang 821 | * add simplified chinese test cases 822 | * Add doctests 823 | * add keyword: 824 | * "实": "True" 825 | * "类型":"type" 826 | * "读取":"read", "写入":"write" 827 | * "读一行":"readline", "读多行":"readlines" 828 | * "开启":"open", "打开":"open", 829 | * "關閉":"close", "关闭":"close" 830 | 831 | *Fixes* 832 | 833 | * "不是":"is not" instead of "不是":"not" 834 | * zhpy.py use normal unix \n instead of mac \r, thanks Jiahua Huang 835 | 836 | *Project Updates* 837 | 838 | * Increase cheesecake_ rating 839 | * Add license statement 840 | * Add todo list 841 | * Add authors list 842 | * Add docs/ 843 | * Add example test runner 844 | * Remove redundent files 845 | * Update setup information 846 | 847 | .. _cheesecake: http://www.pycheesecake.org/ 848 | 849 | *Contributors* 850 | 851 | Fred Lin, Jiahua Huang 852 | 853 | 0.5 (08/19/2007): 854 | ------------------ 855 | code name: Star Platinum 856 | 857 | *Changes* 858 | 859 | *Features* 860 | 861 | * implement zh_exec, now it's possible to test zhpy in interpretor, or 862 | embeded zhpy in python source 863 | * add test cases 864 | 865 | *Fixes* 866 | 867 | * Now parser matches all quotes (single quote, double quote, triple quote) 868 | * fix game example 869 | 870 | *Project Updates* 871 | 872 | * Add README file 873 | * Add tests folder 874 | 875 | *Contributors* 876 | 877 | Fred Lin 878 | 879 | 0.4 (08/16/2007): 880 | ------------------ 881 | code name: Dio 882 | 883 | *Changes* 884 | 885 | * keywords changes 886 | "浮點數":"float" instead of "小數" 887 | 888 | *Features* 889 | 890 | * Enhanced command parser with 2 basic option 891 | * add "-i": input option 892 | * add "-o": output option 893 | * add "-p": "compile to python and run" option, which generate 894 | python source with 'n_' prefix. 895 | * More keywords 896 | * "數組":"tuple", "類組":"set" 897 | * "数组":"tuple", "类组":"set" 898 | * "編碼":"encoding", "解碼":"decoding" 899 | * "编码":"encoding", "解码":"decoding" 900 | * "開啟":"open", "讀取":"read", "寫入":"write" 901 | * "讀一行":"readline", "讀多行":"readlines" 902 | * "接合":"join", "分離":"split" 903 | * "分离":"split" 904 | 905 | *Fixes* 906 | 907 | *Project Updates* 908 | 909 | * update classifiers information 910 | * move to beta phase 911 | 912 | *Contributors* 913 | 914 | Fred Lin 915 | 916 | 0.3 (08/13/2007): 917 | ------------------ 918 | code name: JoJo 919 | 920 | *Changes* 921 | 922 | * Trad keyword changes: 923 | * "傳回":"return" 924 | * "假使":"elif" and "否則如果":"elif" instead of '不然' 925 | * "中止":"break" 926 | * "方程式":"lambda" instead of "函式" 927 | * "產生":"yield" instead of "圈" 928 | * "示警":"raise" instead of "舉出" 929 | * "共用":"global" instead of "全域" 930 | 931 | * Smpl keyword changes: 932 | * "函数":"lambda" 933 | * "产生":"yield", 934 | * "继续":"continue" 935 | * "传回":"return" 936 | 937 | * Removed keywords: 938 | * "加":"+", "減":"-", "乘":"*", "除":"/","取餘數":"%" 939 | * "一":"1", "百":"100", # numbers 940 | 941 | *Features* 942 | 943 | * allow to dynamic add keywords by append ini files in same folder 944 | * catalog keywords 945 | * More keywords 946 | * "真": "True", "假":"False" 947 | * "實": "True", "虛":"False" 948 | * "空":"None" 949 | * "是":"is", "為":"is", "不是":"not" 950 | * "或":"or", "和":"and", "且":"and" 951 | * "開始字串":"startswith", "結束字串":"endswith" 952 | * "开始为":"startswith","结束为":"endswith" 953 | 954 | * More Documents 955 | 956 | *Fixes* 957 | 958 | *Project Updates* 959 | 960 | * Removed python version requirement 961 | * Add ez_setup.py in project incase user haven't installed easy_install command 962 | * Add module version info while import 963 | * Zoom Quiet joined as the project member 964 | 965 | *Contributors* 966 | 967 | Fred Lin 968 | 969 | 0.2 (08/9/2007): 970 | ------------------ 971 | code name: zhou 972 | 973 | *Changes* 974 | 975 | * Refactored from HYRY's original script 976 | * Add Traditional Chinese keywords 977 | 978 | *Features* 979 | 980 | * easy_install-abled 981 | * executable command line 982 | * export python source from zhpy 983 | 984 | *Fixes* 985 | 986 | *Project Updates* 987 | 988 | * host on google code project 989 | 990 | *Contributors* 991 | 992 | Fred Lin, HYRY -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # zhpy 2 | 周蟒, 用中文化 python 語法寫程式 3 | 4 | ## 安裝 5 | 6 | $ pip install -U zhpy 7 | 8 | ## 使用 9 | 10 | 安裝好後你可以立即試用周蟒中文 Python 直譯器. 試著在直譯器上輸入 11 | 12 | ``` 13 | 印出 '哈囉, 世界' 14 | ``` 15 | 16 | ``` 17 | $ python interpreter.py 18 | zhpy X.X in darwin on top of Python 2.X.X 19 | >>> 印出 '哈囉, 世界' 20 | 哈囉, 世界 21 | ``` 22 | 23 | 這樣你就完成了你的第一個中文程式囉! 24 | 25 | ## 使用方法 26 | https://github.com/gasolin/zhpy/blob/wiki/BasicUsage.md 27 | 28 | ## 完整教學 29 | https://github.com/gasolin/zhpy/blob/wiki/ByteOfZhpy.md 30 | 31 | 32 | Migrated from code.google.com/p/zhpy 33 | -------------------------------------------------------------------------------- /docs/DownloadInstall.txt: -------------------------------------------------------------------------------- 1 | #summary 周蟒安裝指南 2 | #labels Featured,Traditional 3 | 4 | = 1. 安裝 Python 程式語言 = 5 | 6 | 1. 前往[http://www.python.org/download/ python 程式語言官方網站]下載最新的安裝檔案 (.exe)。 7 | 下載好的安裝檔,其安裝方式就跟其他的 Windows 程式的安裝方式一樣。 8 | 9 | 如果你想透過 Windows 命令列來使用 Python 語言,那麼你需要先設定好 Windows 環境變數。 10 | 11 | 在 Windows 2000, XP, 2003 這些作業系統裡,點選 "控制台" -> "系統" -> "進階" -> "環境變數"。 12 | 13 | 在"系統變數(S)"欄中,選取 'PATH' 變數名稱後,再點選 '編輯(I)' 按鈕。 14 | 15 | 請先確定你安裝 Python 語言程式的路徑是 'C:Python25',接著在彈出的視窗中將 ';C:Python25' (注意要以分號隔開)這字串添在原本的字串之後。 16 | 17 | 在比較舊的 Windows 作業系統版本上,則是在 'C:AUTOEXEC.BAT' 這個檔案中加入 18 | 19 | {{{ 20 | 'PATH=%PATH%;C:Python25' 21 | }}} 22 | 23 | == 安裝在 Linux/BSD 作業系統上 == 24 | 25 | 如果你正使用某個 Linux 的發行版本如 Ubuntu, Fedora, Mandriva 等等,或者某個 BSD 系統如 FreeBSD,那麼你的系統裡應該早就預先安裝好 Python 程式語言軟體了。要測試 Python 程式語言軟體是否真的已經安裝好在你的作業系統上, 你可以開啟一個命令列 (Shell) 程式 (如 konsole 或 gnome-terminal), 輸入命令 'python -V' ('V' 最好為大寫)。 26 | 27 | {{{ 28 | $ python -V 29 | Python 2.5. 30 | }}} 31 | 32 | 註釋: '$' 符號是命令列程式的提示符號。出現的符號與你的系統設定有關。本書中一律以 '$' 符號表示。 33 | 34 | 如果你看見了如上所示的一些版本訊息,那就表示系統已經預先安裝好 Python 程式語言軟體了。 35 | 36 | 如果你的作業系統上還未安裝 Python。雖然這種情況不太可能發生。 37 | 38 | 當你遇到這種情況時,可以透過這兩種方式在你的作業系統上安裝 Python 程式語言軟體。 39 | 40 | * 透過作業系統提供的安裝管理員程式來安裝 (比如 Ubuntu/Debian Linux 作業系統上的 apt-get , Fedora Linux 作業系統上的 yum, Mandriva Linux 作業系統上的 urpmi, FreeBSD 作業系統上的 pkg_add...等等). 請注意你需要連在網路上才能使用上述方式安裝。 41 | * 或者你可以下載打包好的套件(如 .deb 或 .rpm 檔)後直接安裝。 42 | * 你也可以自行編譯 python 程式語言軟體的程式碼並安裝. 在 python 語言軟體的原始碼中有說明編譯的步驟. http://www.python.org/download/ 43 | 44 | == 安裝在 Mac 作業系統上 == 45 | 46 | 在 Mac OS X 10.3 以上的版本中已經預先安裝了 Python 程式語言軟體. 如果你想安裝較新的 Python 程式語言軟體版本, 可以使用 'DarwinPorts' 程式: 47 | 48 | * 安裝 DarwinPorts 程式 http://www.darwinports.org/getdp/ 49 | * 執行 'sudo port search python' 命令以取得 python 軟體列表。 50 | 目前 DarwinPorts 中 Python 2.5.1 版本的代號為 python25。 51 | * 執行 'sudo port install python25' 命令 52 | 53 | = 2. 安裝周蟒程式語言 = 54 | 55 | 現在我們假設你已經在你的作業系統上準備好了 Python 語言軟體。 56 | 57 | 接著,請使用命令行(command line) 執行命令以安裝周蟒(zhpy): 58 | 59 | == 線上安裝周蟒 == 60 | 61 | 1. 如果是全新安裝的話, 請下載 [http://peak.telecommunity.com/dist/ez_setup.py ez_setup.py] 檔案並執行以下指令安裝 zhpy 模組: 62 | 63 | {{{ 64 | $ python ez_setup.py zhpy 65 | }}} 66 | 67 | zhpy 是周蟒的代號,此指令會透過網路自動安裝一個用來線上安裝 Python 模組的工具: "easy_install" 命令,然後線上安裝 zhpy 模組。 68 | 69 | 70 | 2. 如果已安裝過 easy_install 命令模組的話, 請直接執行以下指令安裝 zhpy 模組: 71 | 72 | {{{ 73 | $ easy_install zhpy 74 | }}} 75 | 76 | 此指令會透過網路自動安裝 zhpy 模組。 77 | 78 | == 透過原始碼安裝周蟒 == 79 | 80 | 自 [http://pypi.python.org/pypi/zhpy/ pypi] 下載 zip 格式壓縮的原始碼, 81 | 使用 zip 解壓縮程式解開後, 使用命令列執行以下指令安裝 zhpy 模組: 82 | 83 | {{{ 84 | $ python setup.py install 85 | }}} 86 | 87 | == 驗證 == 88 | 89 | 90 | 你可以用以下方法來確認是否已安裝成功。 91 | 92 | 1. 開啟命令行以確認目前安裝的版本: 93 | 94 | {{{ 95 | $ zhpy 96 | zhpy 0.9.5 in darwin on top of Python 2.5.1 97 | >>> 98 | }}} 99 | 100 | 2. 使用 python 驗證 101 | 102 | {{{ 103 | $ python 104 | >>> import zhpy 105 | >>> zhpy.__version__ 106 | 0.9.5 107 | }}} 108 | -------------------------------------------------------------------------------- /docs/zhpy.nsi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/zhpy/f4d932a5ab810158ef4e4113df337cbf7d83817a/docs/zhpy.nsi -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [easy_install] 2 | find_links = http://code.google.com/p/zhpy/downloads/list 3 | 4 | #[egg_info] 5 | #tag_build = dev 6 | #tag_svn_revision = true 7 | 8 | [epydoc] 9 | # refer to http://epydoc.sourceforge.net/manual-reference.html 10 | 11 | # check undocumented strings by command:: 12 | # epydoc --check zhpy 13 | 14 | # you could generate api docs by command:: 15 | # epydoc --config setup.cfg 16 | 17 | # Information about the project. 18 | name: ZHPY 19 | url: http://zhpy.googlecode.com/ 20 | 21 | # The list of modules to document. Modules can be named using 22 | # dotted names, module filenames, or package directory names. 23 | # This option may be repeated. 24 | modules: zhpy 25 | 26 | # Input format 27 | docformat: restructuredtext 28 | 29 | # Whether or not parsing should be used to examine objects. 30 | parse: yes 31 | introspect: yes 32 | 33 | # Don't examine in any way the modules whose dotted name match this 34 | # regular expression pattern. 35 | exclude: .*\.tests.*, pyparsing* 36 | 37 | inheritance: listed 38 | private: no 39 | imports: no 40 | include-log: no 41 | 42 | # Write one of html, text, latex, dvi, ps, pdf output to the directory "apidocs" 43 | output: html 44 | target: apidocs/ 45 | 46 | # Include all automatically generated graphs. These graphs are 47 | # generated using Graphviz dot. 48 | # graph: all 49 | # dotpath: /usr/local/bin/dot -------------------------------------------------------------------------------- /zhpy2/AUTHORS.txt: -------------------------------------------------------------------------------- 1 | AUTHORS 2 | ========= 3 | 4 | Fred Lin 5 | HERY 6 | Jiahwa Huang 7 | renhbo 8 | 9 | If you think your name should be on this list, but it isn't _please_ 10 | let us know. It's likely that it was left off by accident and not 11 | on purpose. -------------------------------------------------------------------------------- /zhpy2/CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | zhpy Changelog 2 | ==================== 3 | 4 | 3.0.0 5 | -------------------- 6 | 7 | *Features* 8 | 9 | * initial Python 3 support 10 | 11 | *Contributors* 12 | 13 | Fred Lin, Xin Wang 14 | 15 | 1.7.4 (10/23/2015) 16 | -------------------- 17 | code name: Back to the future 18 | 19 | *Changes* 20 | 21 | * Migrate project to github and update links to pypi 22 | 23 | *Contributors* 24 | 25 | Fred Lin 26 | 27 | 1.7.3 (12/7/2009) 28 | -------------------- 29 | code name: Justice 30 | 31 | *Changes* 32 | 33 | * Add droid example for Android Scripting Environment 34 | * exclude "tests" folder 35 | * install readline module on Mac 36 | 37 | *Features* 38 | 39 | * Partially Compatible with Android Scripting Environment 40 | * Provide an android.py mockup for desktop development 41 | 42 | *Fixes* 43 | 44 | *Project Updates* 45 | * Move to Mercurial for version control 46 | * NOT TO USE distribute instead of setuptools 47 | 48 | *Contributors* 49 | 50 | Fred Lin, DreamerC 51 | 52 | 1.7.2 (8/11/2009) 53 | -------------------- 54 | code name: Death Thirteen 55 | 56 | *Changes* 57 | 58 | *Features* 59 | 60 | *Fixes* 61 | 62 | * Compatibility with python 2.6 63 | 64 | *Project Updates* 65 | 66 | * update to pyparsing 1.5.2 67 | * update setuptools to date 68 | * test via nose 0.11 69 | 70 | *Contributors* 71 | 72 | Fred Lin 73 | 74 | 1.7.1 (9/11/2008) 75 | -------------------- 76 | code name: Sun 77 | 78 | *Changes* 79 | 80 | * updating "A byte of zhpy" book 81 | 82 | *Features* 83 | 84 | * add realmath example by weijr(Mr. Monkey) 85 | 86 | *Fixes* 87 | 88 | *Project Updates* 89 | 90 | * update to pyparsing 1.5 91 | * update to chardet 1.0.1 92 | 93 | *Contributors* 94 | 95 | Fred Lin, weijr 96 | 97 | 1.7 (5/21/2008) 98 | -------------------- 99 | code name: Lovers 100 | 101 | *Changes* 102 | 103 | remove keywords: 104 | * "其":"self" 105 | 106 | *Features* 107 | 108 | * able to view zhpy version by 'zhpy -V' or 'zhpy --version' command 109 | * intentable interpreter autocomplete in *nix 110 | http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496812 111 | * chinese keyword autocomplete in *nix 112 | * pygments syntax highlighter placeholder with 'zhpy' for '.py', '.twpy', '.cnpy' (not work properly yet) 113 | 114 | *Fixes* 115 | 116 | *Project Updates* 117 | 118 | * Bob Chao joined as the project member 119 | 120 | *Contributors* 121 | 122 | Fred Lin 123 | 124 | 1.6 (4/12/2008) 125 | -------------------- 126 | code name: Justice 127 | 128 | *Changes* 129 | 130 | * modify banner string 131 | * able to pass 'outcoding' param in zh_exec to control output encoding 132 | * able to pass 'zhtrace' param in try_run to control 133 | if enable chinese traceback 134 | * make try_run support verbose option 135 | 136 | *Features* 137 | 138 | * online zhpy shell in zhpy.appspot.com! 139 | 140 | *Fixes* 141 | 142 | * fix python 2.4 compatibility occurred in 1.5.2, thanks DreamerC's report 143 | * fix no chardet support case 144 | 145 | *Project Updates* 146 | 147 | *Contributors* 148 | 149 | Fred Lin 150 | 151 | 1.5.2 (4/3/2008) 152 | -------------------- 153 | code name: Wheel of Fortune 154 | 155 | *Changes* 156 | 157 | * PEP8 cleanup, thanks ulipad :) 158 | * refactor py_annotator, thanks weijr 159 | * refactor python_convertor 160 | 161 | *Features* 162 | 163 | * no need calling annotator before calling convertor, 164 | annotator will be called automatically 165 | * reduce unnecessary annotator reload, thanks weijr 166 | * add outcoding (output encoding) option in convertor 167 | 168 | *Fixes* 169 | 170 | * fix import_hook 171 | 172 | *Project Updates* 173 | 174 | * update license years 175 | 176 | *Contributors* 177 | 178 | Fred Lin, weijr 179 | 180 | 1.5.1 (3/21/2008) 181 | -------------------- 182 | code name: Empress 183 | 184 | *Changes* 185 | 186 | *Features* 187 | 188 | *Fixes* 189 | 190 | * fix pyzh pattern missing 191 | 192 | *Project Updates* 193 | 194 | *Contributors* 195 | 196 | Fred Lin 197 | 198 | 1.5 (2/29/2008) 199 | -------------------- 200 | code name: Emperor 201 | 202 | *Changes* 203 | 204 | * rename zhimport.py to import_hook.py 205 | * rewrite import_hook from magiccodec, thanks weijr 206 | http://weijr-note.blogspot.com/2008/02/python-magiccodec-01.html 207 | * use isinstance(target,dict) instead of type({}), thanks weijr 208 | * refactor merger 209 | * merge rev_merger to merger 210 | * refactor ini_annotator, py_annotator, 211 | pattern, val_matching, rev_ini_annotator, 212 | rev_py_annotator, trace_annotator to private method 213 | * refactor to distill baseWord 214 | * add some variable docstrings 215 | 216 | *Features* 217 | 218 | * add keywords: 219 | * "屬性":"property", "属性":"property", 220 | * add set methods keyword: 221 | * "定集合":"frozenset", 222 | * "清除":"clear", 223 | * "複製":"copy","拷贝":"copy", 224 | * "加":"add", 225 | * "丟棄":"discard","丢弃":"discard", 226 | * "聯集":"union","联集":"union", 227 | * "交集":"intersection", 228 | * "差集":"difference", 229 | * "對稱差集":"symmetric_difference", "对称差集":"symmetric_difference", 230 | 231 | *Fixes* 232 | 233 | *Project Updates* 234 | 235 | * update to pyparsing 1.4.11 236 | * update setuptools to 0.6.8 237 | * update epydoc to 3.0.1 238 | 239 | *Contributors* 240 | 241 | Fred Lin, weijr 242 | 243 | 1.4 (1/18/2008): 244 | -------------------- 245 | code name: Hang Man 246 | 247 | *Changes* 248 | 249 | * change keyword: 250 | * "元組" instead of "組合":"tuple", 251 | * "元组" instead of "组合":"tuple", 252 | * update example n_tabl.twpy 253 | 254 | *Features* 255 | 256 | * Introdure real chinese traceback support, currently works in compiler mode 257 | 258 | *Fixes* 259 | 260 | * Fix interpreter unicode issue mainly occured on Windows, thanks renhbo 261 | 262 | *Project Updates* 263 | 264 | * use setup.cfg to generate docs 265 | 266 | *Contributors* 267 | 268 | Fred Lin, renhbo 269 | 270 | 1.4b1 (12/3/2007): 271 | -------------------- 272 | code name: Yellow Temperance 273 | 274 | *Changes* 275 | 276 | * change keyword: 277 | * '操作系统错误' instead of '作业系统错误':"OSError" 278 | * '申明' instead of "宣告":"assert" 279 | * "申明錯誤" instead of "宣告錯誤":"AssertionError" 280 | * "申明错误" instead of "宣告错误":"AssertionError" 281 | * add traceback term plugins (not functional yet) 282 | 283 | *Features* 284 | 285 | * while open interpreter, autodetect and show the localized banner 286 | * experimental chinese traceback support in convertor (not support in interpreter) 287 | * add keyword: 288 | * "全域":"global" 289 | * "全域變量":"globals","全域变量":"globals" 290 | * "測試":"test", "测试":"test" 291 | * "物件":"object", "对象":"object" 292 | * able to test though generated python file ($ nosetests n_xxx.py) 293 | 294 | *Fixes* 295 | 296 | * fix triple quote bug, thanks renhbo 297 | * allow cascading 2 identifiers (cascade 3 or more identifiers is not support) 298 | 299 | *Project Updates* 300 | 301 | *Contributors* 302 | 303 | Fred Lin, renhbo 304 | 305 | 1.3 (11/5/2007): 306 | -------------------- 307 | code name: White Snake 308 | 309 | *Changes* 310 | 311 | * Separate traditional and simplified chinese keywords from zhdc to plug[lang].py 312 | * moveout plugins' setuptools dependency, now you can try zhpy without install. 313 | * change keyword: 314 | * "引用錯誤", "引用错误" instead of "参考错误":"ReferenceError" 315 | * make py_annotator work while only plugtw or plugcn exists. 316 | 317 | *Features* 318 | 319 | * support custom name space in zh_exec, thanks renhbo 320 | * able to run the commandline without install 321 | * able to run the interpreter with 4 module ["interpreter", "zhpy", "zhdc", "plug[lang]"] 322 | without install (core mode) 323 | * able to profiling standalone interpreter with "--profile" option 324 | 325 | *Fixes* 326 | 327 | * fix keyword "locals" instead of "local" 328 | * generate proper profix while the origin source is suffixed with '.tw.py' or '.cn.py' 329 | 330 | *Project Updates* 331 | 332 | * include pyparsing in distribution 333 | * doc update 334 | * add official zhpy blog: http://zhpy.blogspot.com/ 335 | * remove zhpy_ext sample 336 | 337 | *Contributors* 338 | 339 | Fred Lin, renhbo 340 | 341 | 1.2 (10/19/2007): 342 | -------------------- 343 | code name: Requiem 344 | 345 | *Changes* 346 | 347 | * Use build-in int function to convert hex string, thanks Jiahua Huang 348 | * refactor repeative tripleQuote pattern to single place (zhpy) 349 | * refactor 'number_to_variable' function to 'zh_chr' function (pyzh) 350 | * refactor 'variable_to_number' function to 'zh_ord' function (zhpy) 351 | * support chinese filename to uri filename while convert with '-p' option 352 | * zh_ord and zh_chr are bi-direction convertable now 353 | * change keyword: 354 | * '最大值' instead of '最大':'max' 355 | * '最小值' instead of '最小':'min' 356 | * '最大值' instead of '最大':'max' 357 | * '最小值' instead of '最小':'min' 358 | * '反转' instead of '逆转':'reverse', 359 | 360 | *Features* 361 | 362 | * add zhimport module to support chinese file name import, thanks Jiahua Huang 363 | * checked in experimental direct zhpy module import(disabled), thanks Jiahua Huang 364 | * add build-in sys module keyword plugin 365 | * add pyzh and bi-directional translation tests 366 | 367 | *Fixes* 368 | 369 | * support multilines comments with triple single quote, thanks renhbo 370 | 371 | *Project Updates* 372 | 373 | * set svn:external to update ez_setup script automaticaly 374 | * renhbo joined as the project member 375 | 376 | *Contributors* 377 | 378 | Fred Lin, Jiahua Huang, renhbo 379 | 380 | 1.1.1 (10/12/2007): 381 | -------------------- 382 | code name: Dark Blue Moon 383 | 384 | *Changes* 385 | 386 | *Features* 387 | 388 | *Fixes* 389 | 390 | * Able to import modules in current directory with interpreter or script, thanks renhbo 391 | * fix python to zhpy command with any ini file in current directory, thanks renhbo 392 | * fix multilines comments translated incorrectly 393 | 394 | *Project Updates* 395 | 396 | * update release note 397 | 398 | *Contributors* 399 | 400 | Fred Lin, renhbo 401 | 402 | 1.1 (10/8/2007): 403 | -------------------- 404 | code name: Echoes 405 | 406 | *Changes* 407 | 408 | *Features* 409 | 410 | * add commandline option '--tw' to convert python code to twpy 411 | * add commandline option '--cn' to convert python code to cnpy 412 | 413 | *Fixes* 414 | 415 | * fix verbose options in commandline tool 416 | * fix zhpy to python function 417 | * remove extra .tw, .cn in reverted filename of python to zhpy 418 | 419 | *Project Updates* 420 | 421 | * update installer code 422 | * update project status to Production/Stable 423 | 424 | *Contributors* 425 | 426 | Fred Lin 427 | 428 | 1.0 (10/3/2007): 429 | -------------------- 430 | code name: Killer Queen 431 | 432 | *Changes* 433 | 434 | * replace keyword 435 | * "鍵列表" instead of "關鍵字列表":"keys" 436 | * "键列表" instead of "关键字列表":"keys" 437 | * "引發","引发" instead of "示警":"raise" 438 | * "評估","评估" instead of "求值":"eval" 439 | 440 | *Features* 441 | 442 | * complete "Byte of Zhpy" book 443 | * add native interpreter banner "zhpy --tw" or "zhpy --cn" 444 | * show keyword number of each plugin in "zhpy --info" command 445 | * add keyword 446 | * "代換":"replace" 447 | * "代换":"replace" 448 | * "初始化":"init", 449 | * "類別方法":"classmethod" 450 | * "类方法":"classmethod" 451 | * "錯誤":"Error" 452 | * "错误":"Error" 453 | * "描述":"repr" 454 | 455 | *Fixes* 456 | 457 | *Project Updates* 458 | 459 | * update Download Install doc 460 | * format inline docs for APIDOC 461 | 462 | *Contributors* 463 | 464 | Fred Lin 465 | 466 | 0.9.4 (9/28/2007): 467 | -------------------- 468 | code name: Silver Chariot 469 | 470 | *Changes* 471 | 472 | * remove chinese punctuations support 473 | * change keyword 474 | * use "檔案", "档案" instead of "文件":"file" 475 | * use "返回" instead of "传回":"return" 476 | * use "組合", "组合" instead of "數組":"tuple" 477 | 478 | *Features* 479 | 480 | * allow zhpy script with commandline arguments 481 | * add keyword: 482 | * "其":"self" 483 | * "我":"self" 484 | 485 | *Fixes* 486 | 487 | * fixed comment shouldn't be translated 488 | * 'byte of zhpy' doc update 489 | 490 | *Project Updates* 491 | 492 | * rename zhpy_interpreter.py to interpreter.py 493 | * rename zhpy_cmd.py to commandline.py 494 | * rename zhpy_info.py to info.py 495 | * new commandline utility 496 | * remove command shortcut: "zhpy [input] [output]", use "zhpy -i [input] -o [output]" or 497 | "zhpy -p [input]" 498 | 499 | *Contributors* 500 | 501 | Fred Lin 502 | 503 | 0.9.3 (09/15/2007): 504 | -------------------- 505 | code name: Gray Tower 506 | 507 | *Changes* 508 | 509 | *Features* 510 | 511 | * catch up exception definitions http://www.chinesepython.org/doc/ref.html 512 | * make chinese punctuation be a plugin 513 | * add keyword: 514 | * "區域變量":"local", "区域变量":"local" 515 | * Downloadable API Doc 516 | 517 | *Fixes* 518 | 519 | * make incorrect ini file not cause exception 520 | * fix replacedict, thanks renhbo 521 | * fix miss-replaced punctuations in quotestring 522 | 523 | *Project Updates* 524 | 525 | * update ez_setup.py to 0.6c7 526 | 527 | *Contributors* 528 | 529 | Fred Lin, renhbo 530 | 531 | 0.9.2 (09/10/2007): 532 | -------------------- 533 | code name: Hierophant Green 534 | 535 | *Changes* 536 | 537 | * move twdict, cndict keyword into plugins 538 | * plugin use object instead of dict to contain more information 539 | * refactory annotator 540 | * update zhpy_ext plugin sample 541 | * keyword change 542 | * "和":"and", "且":"and" instead of "并且":"and" 543 | *"或":"or" instead of "或者":"or" 544 | * "輸入":"raw_input" instead of "输入字符串":"raw_input" 545 | * "浮点数":"float" instead of "小数":"float" 546 | * remove keyword 547 | * "傳回":"return" 548 | * "全局":"global" 549 | 550 | *Features* 551 | 552 | * add keyword 553 | * "非":"not" 554 | * "可調用":"callable", "可调用":"callable" 555 | * "符號":"chr", "符号":"chr" 556 | * "符號轉整數":"ord", "符号转整数":"ord" 557 | * "比較":"cmp","比较":"cmp" 558 | * "複數":"complex","复数":"complex" 559 | * "十六進位":"hex", "十六进制":"hex" 560 | * "列出屬性":"dir", "列出属性":"dir" 561 | * "求值":"eval" 562 | * "文件":"file" 563 | * "输入":"input" 564 | * "取屬性":"getattr", "取属性":"getattr" 565 | * "有屬性":"hasattr", "有属性":"hasattr" 566 | * "設定屬性":"setattr", "设定属性":"setattr" 567 | * "映射":"map" 568 | * "最大":"max", 569 | * "最小":"min", 570 | * "總和":"sum", "总和":"sum" 571 | * "快速範圍":"xrange", "快速范围":"xrange" 572 | * "計數":"count", "计数":"count" 573 | * "索引":"index" 574 | 575 | *Fixes* 576 | 577 | *Project Updates* 578 | 579 | register "twkeyword", "twmethod", "tw_exception", "twzhpy", 580 | "cnkeyword", "cnmethod", "cn_exception", "cnzhpy" as plugin 581 | 582 | *Contributors* 583 | 584 | Fred Lin 585 | 586 | 0.9.1 (09/08/2007): 587 | -------------------- 588 | code name: Magician Red 589 | 590 | *Changes* 591 | 592 | * twdict, cndict now shown in plugin 593 | * worddict formed dynamically without exceptions 594 | * keyword changes 595 | * "中斷" instead of "中止" 596 | 597 | *Features* 598 | 599 | * add keyword: 600 | * "假使":"elif" 601 | * "周蟒":"zhpy" 602 | * "中文執行":"zh_exec", "中文执行":"zh_exec" 603 | 604 | *Fixes* 605 | 606 | * better formatted "zhpy --info" command 607 | * 'byte of zhpy' doc update 608 | 609 | *Project Updates* 610 | 611 | * add download url 612 | 613 | *Contributors* 614 | 615 | Fred Lin 616 | 617 | 0.9 (09/05/2007): 618 | ------------------ 619 | code name: The World 620 | 621 | *Changes* 622 | 623 | * able to pass target dict to merger function 624 | 625 | *Features* 626 | 627 | * module keyword library plug-in system by annotator 628 | * plug-in support for rev_annotator 629 | * annotation support in interpreter 630 | * add command line option '-V/info' for zhpy complete information 631 | * add zhpy_ext as sample plugin template 632 | * add keyword 633 | * "幫助":"help", "帮助":"help" 634 | * "说明":"help" 635 | * Start 'byte of zhpy' doc 636 | 637 | *Fixes* 638 | 639 | * use encoding utf8 as default encoding while auto detection in low confidence(<0.8) 640 | * fix tests cases' doctest 641 | * able to run as script without subname 642 | 643 | *Project Updates* 644 | 645 | *Contributors* 646 | 647 | Fred Lin 648 | 649 | 0.8.1 (09/03/2007): 650 | ------------------ 651 | code name: Hermit Purple 652 | 653 | *Changes* 654 | 655 | * rename zhpyi.py to zhpy_interpreter.py 656 | * update example test cases 657 | * update interpreter banner 658 | 659 | *Features* 660 | 661 | 662 | *Fixes* 663 | 664 | * fix interpreter multiline exception bug 665 | 666 | *Project Updates* 667 | 668 | * Jiahwa Huang joined as the project member 669 | 670 | *Contributors* 671 | 672 | Fred Lin 673 | 674 | 0.8 (08/30/2007): 675 | ------------------ 676 | code name: Stone Free 677 | 678 | *Changes* 679 | 680 | * move all dictionaries to zhdc.py 681 | * move command line tool to zhpy_cmd.py 682 | * use implicit imports 683 | * remove -r option, use -c instead 684 | * keyword changes 685 | * "開頭為" instead of "開始字串", 686 | * "开头为" instead of "开始为" 687 | * "结尾为" instead of "结束为" 688 | * "結尾為" instead of "結束字串" 689 | 690 | *Features* 691 | 692 | * zhpy interpreter, thanks Jiahua Huang 693 | * implement zhpy -> python libraries in pyzh.py 694 | * bi-directional uri variable <-> number function, prototype by Jiahua Huang 695 | * auto detect encodings, now interpreter works on tw/cn windows 696 | * add "-e/--encoding" option to customize the encoding for parsing 697 | * add keyword: 698 | * "執行":"exec", "执行":"exec" 699 | * "布林":"bool", "布尔":"bool" 700 | * "絕對值":"abs", "绝对值":"abs" 701 | * "列舉":"enumerate", "列举":"enumerate" 702 | * "過濾":"filter", "过滤":"filter" 703 | * "打包":"zip" 704 | * "擴展":"extend", "扩展":"extend" 705 | * "插入":"insert", "移除":"remove","排序":"sort" 706 | * "彈出":"pop", "弹出":"pop" 707 | * "列舉":"enumerate", "列举":"enumerate" 708 | * "過濾":"filter", "过滤":"filter" 709 | * "打包":"zip", "打包":"zip", thanks HYRY 710 | * "型別錯誤":"TypeError", "类型错误":"TypeError" 711 | * "下一筆":"next", "下一笔":"next" 712 | * "例外":"Exception" 713 | * "停止迭代":"StopIteration" 714 | * "解碼錯誤":"UnicodeDecodeError","解码错误":"UnicodeDecodeError", 715 | * "導入錯誤":"ImportError","导入错误":"ImportError" 716 | 717 | * add zhpy featured keyword 718 | * "主程式":'if __name__=="__main__"', "主程序":'if __name__=="__main__"' 719 | 720 | *Fixes* 721 | 722 | * keep twdict clean, worddict now real copy from twdict 723 | 724 | *Project Updates* 725 | 726 | * use .tw.py, .cn.py as another zhpy subname to distinguish the coding 727 | * add chardet dependency 728 | 729 | *Contributors* 730 | 731 | Fred Lin, HYRY, Jiahua Huang 732 | 733 | 0.7 (08/25/2007): 734 | ------------------ 735 | code name: Gold Experience 736 | 737 | *Changes* 738 | 739 | * keyword changes 740 | * "全局" instead of "全局变量" 741 | * "导入" instead of "载入" 742 | * "作為" instead of "取名" 743 | * "尝试" instead of "试运行" 744 | * "异常" instead of "错误处理" 745 | * "集合" instead of , "类组" 746 | * "連接" instead of "接合" 747 | * "關鍵字列表" instead of "列出關鍵字" 748 | * "值列表" instead of "列出值" 749 | * "項目列表" instead of "列出項目" 750 | * variables are changed to "p_[var]_v" syntax instead of p[num], 751 | thanks Jiahua Huang 752 | * .has_key() is deprecated, use 'in' 753 | * remove keyword 754 | * "有關鍵字":"has_key", "有关键字":"has_key" 755 | * "若":"if" 756 | * "開啟":"open", "开启":"open" 757 | * remove trail space for pep8 758 | * rename run.sh to test_example.sh 759 | * maintain tw, cn keyword in seperate dict 760 | * Online documents update 761 | 762 | *Features* 763 | 764 | * use universe reference identifier (uri) for 765 | variable/constant/class/methods instead of vnum, thanks Jiahua Huang 766 | * add keyword: 767 | * "作为":"as" 768 | * "最后":"finally" 769 | * "宣告":"assert", "刪除":"del", "执行":"exec" 770 | * "或者":"or","并且":"and", 771 | * "不在":"not in" 772 | * "不為":"is not", "为":"is", "不为":"is not" 773 | 774 | * add "-c/--cmd" option instead of "-r/--raw" to correspond the python command, 775 | "-r/--raw" will be deprecate in next release. 776 | * also test command line options (test_example.sh) 777 | * add contact example (cn) in loop/ 778 | 779 | *Fixes* 780 | 781 | * able to run zhpy in __main__, thanks Jiahua Huang 782 | 783 | *Project Updates* 784 | 785 | * use .twpy, .cnpy as zhpy subname to distinguish the coding 786 | 787 | *Contributors* 788 | 789 | Fred Lin, Jiahua Huang 790 | 791 | 0.6 (08/22/2007): 792 | ------------------ 793 | code name: Crazy Diomand 794 | 795 | *Changes* 796 | 797 | * internal refactor the try_run method 798 | * rename traditional chinese test cases 799 | * Online documents update 800 | 801 | *Features* 802 | 803 | * add "-r/--raw": "input raw zhpy source and run" option for 804 | scripting usage, idea from Jiahua Huang 805 | * add simplified chinese test cases 806 | * Add doctests 807 | * add keyword: 808 | * "实": "True" 809 | * "类型":"type" 810 | * "读取":"read", "写入":"write" 811 | * "读一行":"readline", "读多行":"readlines" 812 | * "开启":"open", "打开":"open", 813 | * "關閉":"close", "关闭":"close" 814 | 815 | *Fixes* 816 | 817 | * "不是":"is not" instead of "不是":"not" 818 | * zhpy.py use normal unix \n instead of mac \r, thanks Jiahua Huang 819 | 820 | *Project Updates* 821 | 822 | * Increase cheesecake_ rating 823 | * Add license statement 824 | * Add todo list 825 | * Add authors list 826 | * Add docs/ 827 | * Add example test runner 828 | * Remove redundent files 829 | * Update setup information 830 | 831 | .. _cheesecake: http://www.pycheesecake.org/ 832 | 833 | *Contributors* 834 | 835 | Fred Lin, Jiahua Huang 836 | 837 | 0.5 (08/19/2007): 838 | ------------------ 839 | code name: Star Platinum 840 | 841 | *Changes* 842 | 843 | *Features* 844 | 845 | * implement zh_exec, now it's possible to test zhpy in interpretor, or 846 | embeded zhpy in python source 847 | * add test cases 848 | 849 | *Fixes* 850 | 851 | * Now parser matches all quotes (single quote, double quote, triple quote) 852 | * fix game example 853 | 854 | *Project Updates* 855 | 856 | * Add README file 857 | * Add tests folder 858 | 859 | *Contributors* 860 | 861 | Fred Lin 862 | 863 | 0.4 (08/16/2007): 864 | ------------------ 865 | code name: Dio 866 | 867 | *Changes* 868 | 869 | * keywords changes 870 | "浮點數":"float" instead of "小數" 871 | 872 | *Features* 873 | 874 | * Enhanced command parser with 2 basic option 875 | * add "-i": input option 876 | * add "-o": output option 877 | * add "-p": "compile to python and run" option, which generate 878 | python source with 'n_' prefix. 879 | * More keywords 880 | * "數組":"tuple", "類組":"set" 881 | * "数组":"tuple", "类组":"set" 882 | * "編碼":"encoding", "解碼":"decoding" 883 | * "编码":"encoding", "解码":"decoding" 884 | * "開啟":"open", "讀取":"read", "寫入":"write" 885 | * "讀一行":"readline", "讀多行":"readlines" 886 | * "接合":"join", "分離":"split" 887 | * "分离":"split" 888 | 889 | *Fixes* 890 | 891 | *Project Updates* 892 | 893 | * update classifiers information 894 | * move to beta phase 895 | 896 | *Contributors* 897 | 898 | Fred Lin 899 | 900 | 0.3 (08/13/2007): 901 | ------------------ 902 | code name: JoJo 903 | 904 | *Changes* 905 | 906 | * Trad keyword changes: 907 | * "傳回":"return" 908 | * "假使":"elif" and "否則如果":"elif" instead of '不然' 909 | * "中止":"break" 910 | * "方程式":"lambda" instead of "函式" 911 | * "產生":"yield" instead of "圈" 912 | * "示警":"raise" instead of "舉出" 913 | * "共用":"global" instead of "全域" 914 | 915 | * Smpl keyword changes: 916 | * "函数":"lambda" 917 | * "产生":"yield", 918 | * "继续":"continue" 919 | * "传回":"return" 920 | 921 | * Removed keywords: 922 | * "加":"+", "減":"-", "乘":"*", "除":"/","取餘數":"%" 923 | * "一":"1", "百":"100", # numbers 924 | 925 | *Features* 926 | 927 | * allow to dynamic add keywords by append ini files in same folder 928 | * catalog keywords 929 | * More keywords 930 | * "真": "True", "假":"False" 931 | * "實": "True", "虛":"False" 932 | * "空":"None" 933 | * "是":"is", "為":"is", "不是":"not" 934 | * "或":"or", "和":"and", "且":"and" 935 | * "開始字串":"startswith", "結束字串":"endswith" 936 | * "开始为":"startswith","结束为":"endswith" 937 | 938 | * More Documents 939 | 940 | *Fixes* 941 | 942 | *Project Updates* 943 | 944 | * Removed python version requirement 945 | * Add ez_setup.py in project incase user haven't installed easy_install command 946 | * Add module version info while import 947 | * Zoom Quiet joined as the project member 948 | 949 | *Contributors* 950 | 951 | Fred Lin 952 | 953 | 0.2 (08/9/2007): 954 | ------------------ 955 | code name: zhou 956 | 957 | *Changes* 958 | 959 | * Refactored from HYRY's original script 960 | * Add Traditional Chinese keywords 961 | 962 | *Features* 963 | 964 | * easy_install-abled 965 | * executable command line 966 | * export python source from zhpy 967 | 968 | *Fixes* 969 | 970 | *Project Updates* 971 | 972 | * host on google code project 973 | 974 | *Contributors* 975 | 976 | Fred Lin, HYRY 977 | -------------------------------------------------------------------------------- /zhpy2/FAQ.txt: -------------------------------------------------------------------------------- 1 | FAQ 2 | ---- 3 | 4 | check FAQs on 5 | http://code.google.com/p/zhpy/wiki/AboutZhpy -------------------------------------------------------------------------------- /zhpy2/INSTALL.txt: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Use :: 5 | 6 | $ easy_install zhpy 7 | 8 | to install zhpy. 9 | 10 | or follow the detail installation guide on 11 | http://code.google.com/p/zhpy/wiki/DownloadInstall -------------------------------------------------------------------------------- /zhpy2/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 Fred Lin 2 | 3 | This is the MIT license: 4 | http://www.opensource.org/licenses/mit-license.php 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to 8 | deal in the Software without restriction, including without limitation the 9 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 | sell copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | 24 | The following module has it's own license, please refer to its own 25 | descriptions: 26 | 27 | * pyparsing -------------------------------------------------------------------------------- /zhpy2/NEWS.txt: -------------------------------------------------------------------------------- 1 | NEWS 2 | ------ 3 | 4 | check news on 5 | http://code.google.com/p/zhpy/wiki/RoadMap 6 | 7 | or view the ZHPY official blog 8 | http://zhpy.blogspot.com 9 | -------------------------------------------------------------------------------- /zhpy2/README.txt: -------------------------------------------------------------------------------- 1 | zhpy 2 | ==== 3 | 4 | zhpy is the python on Chinese, which is good for Taiwan and China beginners 5 | to learn python in our native language. 6 | 7 | Install: https://github.com/gasolin/zhpy/blob/wiki/DownloadInstall.md 8 | 9 | Open the command line, enter the current source directory and type following 10 | command: 11 | 12 | $ python setup.py install 13 | 14 | 15 | Basic Usage: https://github.com/gasolin/zhpy/blob/wiki/BasicUsage.md 16 | 17 | 18 | To play zhpy you even don't need to install it. 19 | 20 | All you need to do is follow the 3 steps guide: 21 | 22 | 1. Download the source pack 23 | 2. Extract the pack with zip tool 24 | 3. Run:: 25 | 26 | $ python interpreter.py 27 | 28 | Then you got the usable zhpy interpreter! 29 | -------------------------------------------------------------------------------- /zhpy2/THANKS.txt: -------------------------------------------------------------------------------- 1 | THANKS 2 | --------- 3 | 4 | Thanks Glace, the Chinese python author made an early progress on chinese programming on python. 5 | 6 | Thanks HYRY, his little script make this project come true. 7 | 8 | Thanks JiaHua Huang, he brings universal variable and interpreter into my vision, 9 | 10 | Thanks for all of you let zhpy could catch up with python's exciting features. 11 | 12 | Thank Paul T. McGuire, his pyparsing module is heavily used in zhpy. 13 | 14 | Thanks Swroop C. H for his wonderful book "Byte of Python", 15 | 16 | Thanks C.C. license to let me able to remix and made the free Traditional 17 | Chinese version of "Byte of Python". 18 | 19 | For all of this contribution we could get "Byte of zhpy" in a short period of time. 20 | 21 | 22 | Thanks people who intrested in zhpy and give me helpful advices to improve zhpy. 23 | 24 | -- 25 | gasolin -------------------------------------------------------------------------------- /zhpy2/TODO.txt: -------------------------------------------------------------------------------- 1 | TODO 2 | ====== 3 | 4 | * documents 5 | * advocation 6 | * some useful module ini 7 | * python 3000 compatible 8 | * One-click evaluation environment -------------------------------------------------------------------------------- /zhpy2/examples/droid/android.py: -------------------------------------------------------------------------------- 1 | class Android(object): 2 | """ 3 | __author__: fredlin 4 | __version__: 0.11_1 5 | __date__: 2009/8/19 6 | 7 | The mock up of 8 | http://code.google.com/p/android-scripting/source/browse/python/ase/android.py 9 | """ 10 | def __init__(self): 11 | print "Create Android instance" 12 | 13 | def makeToast(self, text): 14 | print "message: " + text 15 | 16 | def getInput(self, title, message=""): 17 | if not message.endswith(": ") or not message.endswith(":"): 18 | message+=": " 19 | input = raw_input(message) 20 | return {"result":input} 21 | 22 | def Speak(self, text): 23 | print "speak: " + text 24 | 25 | def scanBarcode(self): 26 | print "Start barcode scaning ..." 27 | return {"result":{"SCAN_RESULT_FORMAT":"EAN_13","data":"#intent;action=com.google.zxing.client.android.SCAN;S.SCAN_RESULT_FORMAT=EAN_13;S.SCAN_RESULT=1234567890123", 28 | "SCAN_RESULT":"1234567890123"}} 29 | 30 | def captureImage(self): 31 | print "get image" -------------------------------------------------------------------------------- /zhpy2/examples/droid/droid.ini: -------------------------------------------------------------------------------- 1 | [droid] 2 | 機器人 = android 3 | 變形 = Android 4 | 5 | [actions] 6 | #動作 = startActivity 7 | #回應 = startActivityForResult 8 | 9 | [interactive] 10 | 提示 = makeToast 11 | 輸入 = getInput 12 | 說 = Speak 13 | 掃條碼 = scanBarcode 14 | 抓圖 = captureImage 15 | #震動 = vibrate 16 | #搜尋 = webSearch -------------------------------------------------------------------------------- /zhpy2/examples/droid/droid.twpy: -------------------------------------------------------------------------------- 1 | 導入 機器人 2 | 大黃蜂 = 機器人.變形() 3 | 條碼 = 大黃蜂.掃條碼() 4 | 大黃蜂.提示(條碼['result']['SCAN_RESULT']) -------------------------------------------------------------------------------- /zhpy2/examples/game/game.twpy: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | 導入 系統, 遊戲 3 | 大小 = 寬,長=320,240 4 | 速度 = [2,2] 5 | 顏色 = 255,255,255 6 | 螢幕 = 遊戲.顯示.設定模式(大小) 7 | 物體 = 遊戲.影像.讀入("pygame_icon.bmp") 8 | 物體邊界 = 物體.取得邊界() 9 | 當 1: 10 | 取 事件 自 遊戲.事件.取得(): 11 | 如果 事件.類型 == 遊戲.停止: 系統.退出() 12 | 13 | 物體邊界 = 物體邊界.移動(速度) 14 | 如果 物體邊界.左 < 0 或 物體邊界.右 > 寬: 15 | 速度[0] = -速度[0] 16 | 如果 物體邊界.頂 < 0 或 物體邊界.底 > 長: 17 | 速度[1] = -速度[1] 18 | 19 | 螢幕.填滿(顏色) 20 | 螢幕.標示(物體,物體邊界) 21 | 遊戲.顯示.翻動() -------------------------------------------------------------------------------- /zhpy2/examples/game/n_game.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | import sys, pygame 3 | p_5927_5c0f_v = p_5bec_v,p_9577_v=320,240 4 | p_901f_5ea6_v = [2,2] 5 | p_984f_8272_v = 255,255,255 6 | p_87a2_5e55_v = pygame.display.set_mode(p_5927_5c0f_v) 7 | p_7269_9ad4_v = pygame.image.load("pygame_icon.bmp") 8 | p_7269_9ad4_908a_754c_v = p_7269_9ad4_v.get_rect() 9 | while 1: 10 | for event in pygame.event.get(): 11 | if event.type == pygame.QUIT: sys.exit() 12 | 13 | p_7269_9ad4_908a_754c_v = p_7269_9ad4_908a_754c_v.move(p_901f_5ea6_v) 14 | if p_7269_9ad4_908a_754c_v.left < 0 or p_7269_9ad4_908a_754c_v.right > p_5bec_v: 15 | p_901f_5ea6_v[0] = -p_901f_5ea6_v[0] 16 | if p_7269_9ad4_908a_754c_v.top < 0 or p_7269_9ad4_908a_754c_v.bottom > p_9577_v: 17 | p_901f_5ea6_v[1] = -p_901f_5ea6_v[1] 18 | 19 | p_87a2_5e55_v.fill(p_984f_8272_v) 20 | p_87a2_5e55_v.blit(p_7269_9ad4_v,p_7269_9ad4_908a_754c_v) 21 | pygame.display.flip() -------------------------------------------------------------------------------- /zhpy2/examples/game/pygame.ini: -------------------------------------------------------------------------------- 1 | [module] 2 | 系統=sys 3 | 遊戲=pygame 4 | 5 | [sys] 6 | 退出=exit 7 | 8 | [methods] 9 | 顯示=display 10 | 影像=image 11 | 事件=event 12 | 停止=QUIT 13 | 14 | [display] 15 | 設定模式=set_mode 16 | 填滿=fill 17 | 翻動=flip 18 | 光點=blit 19 | 標示=blit 20 | 21 | [image] 22 | 讀入=load 23 | 取得邊界=get_rect 24 | 移動=move 25 | 左=left 26 | 右=right 27 | 頂=top 28 | 底=bottom 29 | 上=top 30 | 下=bottom 31 | 32 | [event] 33 | 類型=type 34 | 取得=get -------------------------------------------------------------------------------- /zhpy2/examples/game/pygame_icon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/zhpy/f4d932a5ab810158ef4e4113df337cbf7d83817a/zhpy2/examples/game/pygame_icon.bmp -------------------------------------------------------------------------------- /zhpy2/examples/hello/hello.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # this is a sample Python program 3 | 定義 範例_1(訊息, 次數): 4 | 取 數 在 range(次數): 5 | 印出 "哈囉, %s!" % 訊息 6 | 7 | 範例_1("世界", 100) -------------------------------------------------------------------------------- /zhpy2/examples/hello/hello_arg.twpy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zhpy 2 | # -*- coding: utf-8 -*- 3 | 4 | 導入 系統 5 | 6 | 印出 系統.參數 -------------------------------------------------------------------------------- /zhpy2/examples/hello/hello_big5.twpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/zhpy/f4d932a5ab810158ef4e4113df337cbf7d83817a/zhpy2/examples/hello/hello_big5.twpy -------------------------------------------------------------------------------- /zhpy2/examples/hello/hello_gb.cnpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/zhpy/f4d932a5ab810158ef4e4113df337cbf7d83817a/zhpy2/examples/hello/hello_gb.cnpy -------------------------------------------------------------------------------- /zhpy2/examples/hello/n_hello.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # this is a sample Python program 3 | def p_7bc4_4f8b_v_1(p_8a0a_606f_v, p_6b21_6578_v): 4 | for p_6578_v in range(p_6b21_6578_v): 5 | print "哈囉, %s!" % p_8a0a_606f_v 6 | 7 | p_7bc4_4f8b_v_1("世界", 100) -------------------------------------------------------------------------------- /zhpy2/examples/hello/n_hello_big5.py: -------------------------------------------------------------------------------- 1 | print 'hello' -------------------------------------------------------------------------------- /zhpy2/examples/hello/n_hello_gb.py: -------------------------------------------------------------------------------- 1 | argv=1 2 | print argv 3 | 4 | for i in range(10): 5 | print i -------------------------------------------------------------------------------- /zhpy2/examples/inout/inout: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zhpy 2 | # -*- coding: utf-8 -*- 3 | 資料 = 輸入("輸入姓名: ") 4 | 印出 "歡迎,", 資料 -------------------------------------------------------------------------------- /zhpy2/examples/inout/inout.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 資料 = 輸入("輸入姓名: ") 3 | 印出 "歡迎,", 資料 -------------------------------------------------------------------------------- /zhpy2/examples/inout/n_inout.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | p_8cc7_6599_v = raw_input("輸入姓名: ") 3 | print "歡迎,", p_8cc7_6599_v -------------------------------------------------------------------------------- /zhpy2/examples/loop/contact.cnpy: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | # by jiahua huang 3 | 4 | 姓名表=('张三','李斯','王海','荷花') 5 | 定义 打印姓名表(): 6 | 计数=1 7 | 取 姓名 在 姓名表: 8 | 打印 计数, 姓名 9 | 计数+=1 10 | 11 | 主程序: 12 | 打印姓名表() -------------------------------------------------------------------------------- /zhpy2/examples/loop/n_contact.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | # by jiahua huang 3 | 4 | p_59d3_540d_8868_v=('张三','李斯','王海','荷花') 5 | def p_6253_5370_59d3_540d_8868_v(): 6 | count=1 7 | for p_59d3_540d_v in p_59d3_540d_8868_v: 8 | print count, p_59d3_540d_v 9 | count+=1 10 | 11 | if __name__=="__main__": 12 | p_6253_5370_59d3_540d_8868_v() -------------------------------------------------------------------------------- /zhpy2/examples/loop/n_tabl.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | def p_7b97_8868_v(p_8868_683c_5927_5c0f_v): 3 | for p_4e58_6578_v in range(1, p_8868_683c_5927_5c0f_v+1): 4 | for p_88ab_4e58_6578_v in range(1, p_8868_683c_5927_5c0f_v+1): 5 | print "%d*%d=%d"%(p_4e58_6578_v,p_88ab_4e58_6578_v,p_4e58_6578_v*p_88ab_4e58_6578_v) 6 | 7 | p_7b97_8868_v(9) -------------------------------------------------------------------------------- /zhpy2/examples/loop/tabl.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 定義 算表(表格大小): 3 | 取 乘數 自 範圍(1, 表格大小+1): 4 | 取 被乘數 自 範圍(1, 表格大小+1): 5 | 印出 "%d*%d=%d"%(乘數,被乘數,乘數*被乘數) 6 | 7 | 算表(9) -------------------------------------------------------------------------------- /zhpy2/examples/realmath/math.ini: -------------------------------------------------------------------------------- 1 | # example by Mr. Monkey 2 | 3 | [math] 4 | λ=lambda 5 | π=pi 6 | Σ=sum 7 | ≠=!= 8 | ÷=/ 9 | ×=* 10 | ㏒=log10 11 | ㏑=log 12 | √=sqrt 13 | ≧=>= 14 | ≦=<= 15 | ∩=& 16 | ∪=l -------------------------------------------------------------------------------- /zhpy2/examples/realmath/math.zhpy: -------------------------------------------------------------------------------- 1 | # example by Mr. Monkey 2 | 3 | from math import * 4 | from operator import * 5 | 6 | # use math operators for calculation 7 | print "" 8 | print Σ(range(100)) 9 | print sin(π/4) ≠ √(2)/2 10 | print ㏒(100), ㏑(e) 11 | print 5 × 30 ÷ 2 ≦ tan(√(5)*π/4) 12 | Π=λ f:reduce(mul, f, 1) 13 | print Π(range(1,6)) 14 | print set([1, 2, 3, 4, 5]) ∩ set([1, 3, 5, 7, 9]) -------------------------------------------------------------------------------- /zhpy2/examples/teashop/n_teashop.py: -------------------------------------------------------------------------------- 1 | #coding = utf-8 2 | """ 3 | 泡沫紅茶店 0.1 4 | 5 | 1. 茶種 紅 綠 清 抹 烏龍 6 | 2. 配料 珍珠 粉圓 百香 檸檬 梅子 7 | 3. 糖量 少糖 3/4, 半糖 1/2 微糖 1/4 8 | 4. 冰量 去冰 少冰 9 | """ 10 | 11 | p_8336_7a2e_v = {"紅茶":15,"綠茶":15, "清茶":15, "抹茶":15, \ 12 | "烏龍":15, "奶茶":20, "奶綠":20} #字典 13 | 14 | p_914d_6599_v = {"珍珠":5, "粉圓":5, "百香":5, "檸檬":5, "梅子":5} 15 | 16 | p_7cd6_91cf_v = ["少糖","半糖","微糖"] #列表 17 | 18 | p_51b0_91cf_v = ["去冰", "少冰"] 19 | 20 | def p_98f2_6599_55ae_751f_6210_5668_v(): 21 | """ 22 | 產生飲料價目單 23 | """ 24 | for p_6599_v in p_914d_6599_v.keys(): # 迴圈 25 | for p_8336_v in p_8336_7a2e_v.keys(): 26 | p_6a19_50f9_v = p_8336_7a2e_v[p_8336_v] + p_914d_6599_v[p_6599_v] 27 | print p_6599_v+p_8336_v, p_6a19_50f9_v, 28 | for p_7cd6_v in p_7cd6_91cf_v: 29 | print p_7cd6_v, 30 | for p_51b0_v in p_51b0_91cf_v: 31 | print p_51b0_v, 32 | print '' 33 | 34 | if __name__=="__main__": 35 | p_98f2_6599_55ae_751f_6210_5668_v() -------------------------------------------------------------------------------- /zhpy2/examples/teashop/teashop.tw.py: -------------------------------------------------------------------------------- 1 | #coding = utf-8 2 | """ 3 | 泡沫紅茶店 0.1 4 | 5 | 1. 茶種 紅 綠 清 抹 烏龍 6 | 2. 配料 珍珠 粉圓 百香 檸檬 梅子 7 | 3. 糖量 少糖 3/4, 半糖 1/2 微糖 1/4 8 | 4. 冰量 去冰 少冰 9 | """ 10 | 11 | 茶種 = {"紅茶":15,"綠茶":15, "清茶":15, "抹茶":15, \ 12 | "烏龍":15, "奶茶":20, "奶綠":20} #字典 13 | 14 | 配料 = {"珍珠":5, "粉圓":5, "百香":5, "檸檬":5, "梅子":5} 15 | 16 | 糖量 = ["少糖","半糖","微糖"] #列表 17 | 18 | 冰量 = ["去冰", "少冰"] 19 | 20 | 定義 飲料單生成器(): 21 | """ 22 | 產生飲料價目單 23 | """ 24 | 取 料 自 配料.鍵列表(): # 迴圈 25 | 取 茶 自 茶種.鍵列表(): 26 | 標價 = 茶種[茶] + 配料[料] 27 | 印出 料+茶, 標價, 28 | 取 糖 自 糖量: 29 | 印出 糖, 30 | 取 冰 自 冰量: 31 | 印出 冰, 32 | 印出 '' 33 | 34 | 主程式: 35 | 飲料單生成器() -------------------------------------------------------------------------------- /zhpy2/examples/test_example.sh: -------------------------------------------------------------------------------- 1 | rm -rf hello/*.py 2 | rm -rf inout/*.py 3 | rm -rf loop/*.py 4 | rm -rf game/*.py 5 | 6 | echo "test zhpy as script, total: 2" 7 | zhpy -c "印出 '哈囉'" 8 | zhpy -c "打印 '哈啰'" 9 | 10 | echo "test zhpy examples: total: 12" 11 | 12 | echo "zhpy hello example..." 13 | 14 | cd hello 15 | echo "simple command zhpy [in]:" 16 | zhpy hello.twpy 17 | echo "input command zhpy [in]:" 18 | zhpy -i hello.twpy 19 | echo "input command zhpy [in] [encoding]:" 20 | zhpy -i hello.twpy -e 'utf8' 21 | echo "hello example:" 22 | zhpy -p hello.twpy 23 | echo "big5 example:" 24 | zhpy -p hello_big5.twpy 25 | echo "gbk example:" 26 | zhpy -p hello_gb.cnpy 27 | echo "run hello as script with arguments:" 28 | ./hello_arg.twpy hello world 29 | cd .. 30 | 31 | echo "zhpy in/out example..." 32 | cd inout 33 | zhpy -i inout.twpy -o n_inout.py 34 | zhpy -p inout.twpy 35 | echo "run in/out as script:" 36 | ./inout 37 | cd .. 38 | 39 | echo "zhpy loop example..." 40 | cd loop 41 | zhpy -p tabl.twpy 42 | zhpy -p contact.cnpy 43 | cd .. 44 | 45 | echo "zhpy game example..." 46 | echo "it's an optional test, pygame module required. Use 'Ctrl+c' to escape" 47 | 48 | cd game 49 | zhpy -p game.twpy 50 | cd .. 51 | 52 | echo "finish" -------------------------------------------------------------------------------- /zhpy2/setup.py: -------------------------------------------------------------------------------- 1 | try: 2 | from setuptools import setup, find_packages 3 | except ImportError: 4 | from ez_setup import use_setuptools 5 | use_setuptools() 6 | from setuptools import setup, find_packages 7 | 8 | from pkg_resources import DistributionNotFound 9 | 10 | import sys 11 | import os 12 | import glob 13 | 14 | execfile(os.path.join('zhpy', 'release.py')) 15 | 16 | # setup params 17 | # it's possible to remove chardet dependency while porting 18 | required_modules = ["chardet >=1.0.1"] 19 | #if mac, install readline 20 | #if(sys.platform=="darwin"): 21 | # required_modules.append("readline >= 2.6.4") 22 | 23 | # pyparsing already included in release 24 | # nose is used for test 25 | extra_modules = {'pyparsing': ["pyparsing >=1.5.2"], 'nose': ["nose>=0.9"]} 26 | 27 | setup( 28 | name="zhpy", 29 | version=version, 30 | author=author, 31 | author_email=email, 32 | download_url=download_url, 33 | license=license, 34 | keywords = "traditional, simplified, chinese", 35 | description=description, 36 | long_description=long_description, 37 | url=url, 38 | zip_safe=False, 39 | install_requires = required_modules, 40 | extras_require = extra_modules, 41 | include_package_data = True, 42 | packages=find_packages(exclude=["ez_setup", 'examples', 'apidocs', "tests"]), 43 | entry_points = """ 44 | [console_scripts] 45 | zhpy = zhpy.commandline:commandline 46 | [pygments.lexers] 47 | zhpy = zhpy.ext.pygmentplugin:ZhpyLexer 48 | """, 49 | classifiers = [ 50 | 'Development Status :: 5 - Production/Stable', 51 | 'Environment :: Console', 52 | 'Intended Audience :: Education', 53 | 'Intended Audience :: Developers', 54 | 'Intended Audience :: System Administrators', 55 | 'License :: OSI Approved :: MIT License', 56 | 'Natural Language :: Chinese (Traditional)', 57 | 'Natural Language :: Chinese (Simplified)', 58 | 'Operating System :: OS Independent', 59 | 'Programming Language :: Python', 60 | 'Topic :: Software Development :: Libraries :: Python Modules', 61 | 'Topic :: Software Development :: Code Generators'], 62 | test_suite = 'nose.collector', 63 | ) 64 | 65 | -------------------------------------------------------------------------------- /zhpy2/tests/ReadMe_test.txt: -------------------------------------------------------------------------------- 1 | install nose testtool to test:: 2 | 3 | $ easy_install nose 4 | 5 | to test zhpy, enter the top zhpy directory and execute the command:: 6 | 7 | $ nosetests --with-doctest -------------------------------------------------------------------------------- /zhpy2/tests/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | test with command:: 3 | 4 | nosetests --with-doctest 5 | 6 | """ 7 | 8 | 9 | #always run annotator before access worddict 10 | #from zhpy import annotator 11 | 12 | #annotator() 13 | -------------------------------------------------------------------------------- /zhpy2/tests/test_api.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test api 4 | """ 5 | from zhpy import zh_ord, convertor 6 | from zhpy.pyzh import zh_chr 7 | from zhpy.pyzh import rev_annotator, python_convertor 8 | 9 | def test_convertor(): 10 | """ 11 | test convertor 12 | """ 13 | rev_annotator() 14 | assert convertor("印出 'hello'") == "print 'hello'" 15 | assert python_convertor("print 'hello'") == ("印出 'hello'") 16 | assert python_convertor(convertor("印出 'hello'")) == ("印出 'hello'") 17 | # check if variable convert correctly, not a python valid syntax 18 | assert python_convertor(convertor("打出 '''哈囉'''")) == ("打出 '''哈囉'''") 19 | assert python_convertor(convertor("打出 '''p_哈囉_v'''")) == ("打出 '''p_哈囉_v'''") 20 | assert python_convertor(convertor("打出 '''哈\ 21 | 囉'''")) == ("打出 '''哈\ 22 | 囉'''") 23 | assert python_convertor(convertor('打出 """哈\ 24 | _囉"""')) == ('打出 """哈\ 25 | _囉"""') 26 | 27 | 28 | def test_uri(): 29 | """ 30 | test uri 31 | """ 32 | assert zh_ord('範例'.decode("utf8")) == 'p_7bc4_4f8b_v' 33 | assert zh_ord('p_範例_v'.decode("utf8")) == 'p_70_5f_7bc4_4f8b_5f_76_v' 34 | assert zh_chr('p_7bc4_4f8b_v') == '範例' 35 | assert zh_chr(zh_ord('範例'.decode("utf8"))) == '範例' 36 | -------------------------------------------------------------------------------- /zhpy2/tests/test_controlflow_cn.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test control flow 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_if(): 8 | """ 9 | test if, elif, else 10 | """ 11 | assert convertor("如果 a: 略过") == "if a: pass" 12 | assert convertor("如果 a: 略过; 否则: 略过") == "if a: pass; else: pass" 13 | assert convertor("如果 a: 略过; 否则如果 b: 略过; 否则: 略过") == \ 14 | "if a: pass; elif b: pass; else: pass" 15 | 16 | def test_for_loop(): 17 | """ 18 | test for loop 19 | """ 20 | assert convertor("取 i 在 [1,2,3,4]: 打印 i") == "for i in [1,2,3,4]: print i" 21 | 22 | def test_while_loop(): 23 | """ 24 | test while loop 25 | """ 26 | assert convertor("当 1: 打印 'hello'; 中断") == "while 1: print 'hello'; break" 27 | 28 | def test_try(): 29 | """ 30 | test try except 31 | """ 32 | assert convertor("尝试: 导入 a; 异常 ImportError, e: 打印 e") == \ 33 | "try: import a; except ImportError, e: print e" 34 | assert convertor("引发 例外") == "raise Exception" 35 | 36 | def test_is(): 37 | """ 38 | test is, is not statement 39 | """ 40 | assert convertor("4 為 4") == ("4 is 4") 41 | assert convertor("4 是 4") == ("4 is 4") 42 | assert convertor("4 不是 2") == ("4 is not 2") -------------------------------------------------------------------------------- /zhpy2/tests/test_controlflow_tw.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test control flow 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_if(): 8 | """ 9 | test if, elif, else 10 | """ 11 | assert convertor("如果 a: 略過") == "if a: pass" 12 | assert convertor("如果 a: 略過; 否則: 略過") == "if a: pass; else: pass" 13 | assert convertor("如果 a: 略過; 假使 b: 略過; 否則: 略過") == \ 14 | "if a: pass; elif b: pass; else: pass" 15 | 16 | def test_for_loop(): 17 | """ 18 | test for loop 19 | """ 20 | assert convertor("取 i 在 [1,2,3,4]: 印出 i") == "for i in [1,2,3,4]: print i" 21 | 22 | def test_while_loop(): 23 | """ 24 | test while loop 25 | """ 26 | assert convertor("當 1: 印出 'hello'; 跳出") == "while 1: print 'hello'; break" 27 | 28 | def test_try(): 29 | """ 30 | test try except 31 | """ 32 | assert convertor("嘗試: 導入 a; 異常 ImportError, e: 印出 e") == \ 33 | "try: import a; except ImportError, e: print e" 34 | assert convertor("引發 例外") == "raise Exception" 35 | 36 | def test_is(): 37 | """ 38 | test is, is not statement 39 | """ 40 | assert convertor("4 為 4") == ("4 is 4") 41 | assert convertor("4 是 4") == ("4 is 4") 42 | assert convertor("4 不是 2") == ("4 is not 2") -------------------------------------------------------------------------------- /zhpy2/tests/test_keywords_cn.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test keywords 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_print(): 8 | """ 9 | test output statement and string types 10 | 11 | >>> print "hello" 12 | hello 13 | """ 14 | assert convertor("打印 'hello'") == "print 'hello'" 15 | assert convertor('打印 "hello"') == 'print "hello"' 16 | assert convertor("""打印 'hello'""") == "print 'hello'" 17 | 18 | def test_input(): 19 | """ 20 | test input statement 21 | """ 22 | assert convertor("name = 输入('your name:')") == \ 23 | "name = raw_input('your name:')" 24 | 25 | def test_variable(): 26 | """ 27 | variable is tested in keywords_tw 28 | """ 29 | assert convertor("代码 = 'zhpy'") == "p_4ee3_7801_v = 'zhpy'" 30 | 31 | def test_operators(): 32 | """ 33 | test operators 34 | 35 | >>> 1 == 1 36 | True 37 | """ 38 | assert convertor("a 等于 b") == "a == b" 39 | assert convertor("a 不等于 b") == "a != b" 40 | 41 | def test_def(): 42 | """ 43 | test definition 44 | """ 45 | assert convertor("定义 hello(): 打印 'hello'") == "def hello(): print 'hello'" 46 | 47 | def test_class(): 48 | """ 49 | test class 50 | """ 51 | assert convertor("类 hello: 定义 hello(): 打印 'hello'") == \ 52 | "class hello: def hello(): print 'hello'" 53 | 54 | def test_import(): 55 | """ 56 | test import statement with from/import/as 57 | """ 58 | assert convertor("导入 sys") == "import sys" 59 | assert convertor("导入 sys 作为 unix") == "import sys as unix" 60 | assert convertor("从 os 导入 path 作为 url") == "from os import path as url" 61 | -------------------------------------------------------------------------------- /zhpy2/tests/test_keywords_tw.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test keywords 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_print(): 8 | """ 9 | test output statement and string types 10 | 11 | >>> print "hello" 12 | hello 13 | """ 14 | assert convertor("印出 'hello'") == "print 'hello'" 15 | assert convertor('印出 "hello"') == 'print "hello"' 16 | assert convertor("""印出 'hello'""") == "print 'hello'" 17 | 18 | def test_input(): 19 | """ 20 | test input statement 21 | """ 22 | assert convertor("name = 輸入('your name:')") == \ 23 | "name = raw_input('your name:')" 24 | 25 | def test_variable(): 26 | """ 27 | test variable 28 | """ 29 | assert convertor("代號 = 'zhpy'") == "p_4ee3_865f_v = 'zhpy'" 30 | 31 | def test_operators(): 32 | """ 33 | test operators 34 | 35 | >>> 1 == 1 36 | True 37 | """ 38 | assert convertor("a 等於 b") == "a == b" 39 | assert convertor("a 不等於 b") == "a != b" 40 | 41 | def test_def(): 42 | """ 43 | test definition 44 | """ 45 | assert convertor("定義 hello(): 印出 'hello'") == "def hello(): print 'hello'" 46 | 47 | def test_class(): 48 | """ 49 | test class 50 | """ 51 | assert convertor("類別 hello: 定義 hello(): 印出 'hello'") == \ 52 | "class hello: def hello(): print 'hello'" 53 | 54 | def test_import(): 55 | """ 56 | test import statement with from/import/as 57 | """ 58 | assert convertor("導入 sys") == "import sys" 59 | assert convertor("導入 sys 作為 unix") == "import sys as unix" 60 | assert convertor("從 os 導入 path 作為 url") == "from os import path as url" 61 | -------------------------------------------------------------------------------- /zhpy2/tests/test_types_cn.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test build-in types 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_int(): 8 | """ 9 | test int type 10 | 11 | >>> int(2.0) 12 | 2 13 | >>> int(3.1415926) 14 | 3 15 | """ 16 | assert convertor("整数(2.0)") == "int(2.0)" 17 | 18 | def test_float(): 19 | """ 20 | test float type 21 | """ 22 | assert convertor("浮点数(2)") == "float(2)" 23 | 24 | def test_bool(): 25 | """ 26 | test boolean type 27 | """ 28 | assert convertor("布尔(1)") == "bool(1)" 29 | assert convertor("n is 真") == "n is True" 30 | assert convertor("n 是 真") == "n is True" 31 | assert convertor("p 为 假") == "p is False" 32 | assert convertor("q 不是 实") == "q is not True" 33 | assert convertor("r 不为 虛") == "r is not False" 34 | 35 | def test_string(): 36 | """ 37 | same as print test 38 | 39 | >>> s = "hello.py" 40 | >>> s.startswith('he') 41 | True 42 | >>> s.endswith('py') 43 | True 44 | >>> s = ['one', 'two'] 45 | >>> ''.join(s) 46 | 'onetwo' 47 | """ 48 | assert convertor("s.开头为('he')") == "s.startswith('he')" 49 | assert convertor("s.结尾为('py')") == "s.endswith('py')" 50 | assert convertor("items = 'zero one two three'.分离()") == "items = 'zero one two three'.split()" 51 | assert convertor("''.连接(s)") == "''.join(s)" 52 | 53 | def test_list(): 54 | """ 55 | test list type 56 | 57 | >>> list((1,2,3,4)) == [1,2,3,4] 58 | True 59 | """ 60 | assert convertor("列表((1,2,3,4)) == [1,2,3,4]") == \ 61 | "list((1,2,3,4)) == [1,2,3,4]" 62 | assert convertor("a = []; a.加入(2); 申明 a == [2]") == \ 63 | "a = []; a.append(2); assert a == [2]" 64 | p = "h,e,l,l,o" 65 | assert convertor('p.分离(",")') == 'p.split(",")' 66 | 67 | def test_dict(): 68 | """ 69 | test dict type 70 | 71 | >>> dict(a=1, b=2) == {'a':1, 'b':2} 72 | True 73 | """ 74 | assert convertor("字典(a=1, b=2) == {'a':1, 'b':2}") == \ 75 | "dict(a=1, b=2) == {'a':1, 'b':2}" 76 | 77 | def test_tuple(): 78 | """ 79 | test tuple type 80 | 81 | >>> tuple([1,2,3,4]) == (1,2,3,4) 82 | True 83 | """ 84 | assert convertor("元组([1,2,3,4]) == (1,2,3,4)") == \ 85 | "tuple([1,2,3,4]) == (1,2,3,4)" 86 | 87 | def test_set(): 88 | """ 89 | test set type 90 | 91 | >>> set([1,2,3,4]) == set([1, 2, 3, 4]) 92 | True 93 | """ 94 | assert convertor("集合([1,2,3,4]) == set([1, 2, 3, 4])") == \ 95 | "set([1,2,3,4]) == set([1, 2, 3, 4])" 96 | 97 | def test_file(): 98 | """ 99 | test file type 100 | """ 101 | assert convertor('fd = 打开("ReadMe_test.txt", "r")') == \ 102 | 'fd = open("ReadMe_test.txt", "r")' 103 | assert convertor('temp = fd.读一行()') == 'temp = fd.readline()' 104 | assert convertor('temp = fd.读多行()') == 'temp = fd.readlines()' 105 | assert convertor('temp = fd.读取()') == 'temp = fd.read()' 106 | assert convertor('fd.写入(temp)') == 'fd.write(temp)' 107 | assert convertor('fd.关闭()') == 'fd.close()' 108 | 109 | def test_docstring(): 110 | """ 111 | test docstring 112 | """ 113 | assert convertor('印出 """哈啰, 世界"""') == 'print """哈啰, 世界"""' 114 | assert convertor("印出 '''哈啰, 世界'''") == "print '''哈啰, 世界'''" 115 | -------------------------------------------------------------------------------- /zhpy2/tests/test_types_tw.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | """ 3 | test build-in types 4 | """ 5 | from zhpy import convertor 6 | 7 | def test_int(): 8 | """ 9 | test int type 10 | 11 | >>> int(2.0) 12 | 2 13 | >>> int(3.1415926) 14 | 3 15 | """ 16 | assert convertor("整數(2.0)") == "int(2.0)" 17 | 18 | def test_float(): 19 | """ 20 | test float type 21 | """ 22 | assert convertor("浮點數(2)") == "float(2)" 23 | 24 | def test_bool(): 25 | """ 26 | test boolean type 27 | 28 | """ 29 | assert convertor("布林(1)") == "bool(1)" 30 | assert convertor("n is 真") == "n is True" 31 | assert convertor("n 是 真") == "n is True" 32 | assert convertor("p 為 假") == "p is False" 33 | assert convertor("q 不是 實") == "q is not True" 34 | assert convertor("r 不為 虛") == "r is not False" 35 | 36 | def test_string(): 37 | """ 38 | same as print test 39 | 40 | >>> s = "hello.py" 41 | >>> s.startswith('he') 42 | True 43 | >>> s.endswith('py') 44 | True 45 | >>> s = ['one', 'two'] 46 | >>> ''.join(s) 47 | 'onetwo' 48 | """ 49 | assert convertor("s.開頭為('he')") == "s.startswith('he')" 50 | assert convertor("s.結尾為('py')") == "s.endswith('py')" 51 | assert convertor("items = 'zero one two three'.分離()") == "items = 'zero one two three'.split()" 52 | s = ['one', 'two'] 53 | assert convertor("''.連接(s)") == "''.join(s)" 54 | 55 | def test_list(): 56 | """ 57 | test list type 58 | 59 | >>> list((1,2,3,4)) == [1,2,3,4] 60 | True 61 | """ 62 | assert convertor("列表((1,2,3,4)) == [1,2,3,4]") == \ 63 | "list((1,2,3,4)) == [1,2,3,4]" 64 | assert convertor("a = []; a.加入(2); 申明 a == [2]") == \ 65 | "a = []; a.append(2); assert a == [2]" 66 | p = "h,e,l,l,o" 67 | assert convertor('p.分離(",")') == 'p.split(",")' 68 | 69 | def test_dict(): 70 | """ 71 | test dict type 72 | 73 | >>> dict(a=1, b=2) == {'a':1, 'b':2} 74 | True 75 | """ 76 | assert convertor("字典(a=1, b=2) == {'a':1, 'b':2}") == \ 77 | "dict(a=1, b=2) == {'a':1, 'b':2}" 78 | 79 | def test_tuple(): 80 | """ 81 | test tuple type 82 | 83 | >>> tuple([1,2,3,4]) == (1,2,3,4) 84 | True 85 | """ 86 | assert convertor("元組([1,2,3,4]) == (1,2,3,4)") == \ 87 | "tuple([1,2,3,4]) == (1,2,3,4)" 88 | 89 | def test_set(): 90 | """ 91 | test set type 92 | 93 | >>> set([1,2,3,4]) == set([1, 2, 3, 4]) 94 | True 95 | """ 96 | assert convertor("集合([1,2,3,4]) == set([1, 2, 3, 4])") == \ 97 | "set([1,2,3,4]) == set([1, 2, 3, 4])" 98 | 99 | def test_file(): 100 | """ 101 | test file type 102 | """ 103 | assert convertor('fd = 打開("ReadMe_test.txt", "r")') == \ 104 | 'fd = open("ReadMe_test.txt", "r")' 105 | assert convertor('temp = fd.讀一行()') == 'temp = fd.readline()' 106 | assert convertor('temp = fd.讀多行()') == 'temp = fd.readlines()' 107 | assert convertor('temp = fd.讀取()') == 'temp = fd.read()' 108 | assert convertor('fd.寫入(temp)') == 'fd.write(temp)' 109 | assert convertor('fd.關閉()') == 'fd.close()' 110 | 111 | def test_docstring(): 112 | """ 113 | test docstring 114 | """ 115 | assert convertor('印出 """哈囉, 世界"""') == 'print """哈囉, 世界"""' 116 | assert convertor("印出 '''哈囉, 世界'''") == "print '''哈囉, 世界'''" 117 | -------------------------------------------------------------------------------- /zhpy2/zhpy/__init__.py: -------------------------------------------------------------------------------- 1 | from release import version 2 | __version__ = version 3 | 4 | from zhpy import * 5 | -------------------------------------------------------------------------------- /zhpy2/zhpy/commandline.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """zhpy command line tool 5 | 6 | This is the MIT license: 7 | http://www.opensource.org/licenses/mit-license.php 8 | 9 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to 13 | deal in the Software without restriction, including without limitation the 14 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | sell copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | """ 29 | 30 | import os 31 | import sys 32 | from zhpy import convertor, zh_ord, zh_exec 33 | 34 | 35 | def commandline(): 36 | """zhpy, the python language in chinese 37 | 38 | Accept options: 39 | -i --input: 40 | speficy the input source 41 | -o --output: 42 | speficy the output source 43 | -p --python: 44 | compile to python and run 45 | -c --cmp: 46 | input raw zhpy source and run 47 | -e --encoding: 48 | specify the encoding 49 | --info: 50 | zhpy information 51 | -v --verbose: 52 | show zhpy progress in detail 53 | -V --version 54 | show zhpy version 55 | --tw: 56 | convert python to twpy 57 | --cn: 58 | convert python to cnpy 59 | 60 | help: 61 | get information: 62 | zhpy --info 63 | 64 | interpreter usage: 65 | zhpy [--tw | --cn] 66 | 67 | command usage: 68 | zhpy [-i | -p] input [-o] [output] [-e] [encoding] [-v] 69 | 70 | :: 71 | 72 | $ zhpy input.py (.twpy, .cnpy) [arguments] 73 | $ zhpy -i input.py (.twpy, .cnpy) 74 | $ zhpy -i input.py -o output.py (.twpy, .cnpy) 75 | $ zhpy -p input.py 76 | 77 | script usage: 78 | zhpy [-c] source [-e] [encoding] [-v] 79 | 80 | convertor usage: 81 | zhpy [--tw | --cn] input.py [-v] 82 | 83 | :: 84 | 85 | $ zhpy --tw input.py [-v] 86 | $ zhpy --cn input.py [-v] 87 | 88 | """ 89 | argv = sys.argv[1:] 90 | os.chdir(os.getcwd()) 91 | 92 | source = None 93 | target = None 94 | encoding = None 95 | raw_source = None 96 | verbose = False 97 | python = False 98 | tw = False 99 | cn = False 100 | NonEnglish = False 101 | 102 | # run as interpreter 103 | if len(argv) == 0: 104 | from interpreter import interpreter 105 | import import_hook 106 | display = os.getenv("LANG") 107 | if display == None: 108 | interpreter() 109 | elif "zh_TW" in display: 110 | interpreter('tw') 111 | elif "zh_CN" in display: 112 | interpreter('cn') 113 | else: 114 | interpreter() 115 | sys.exit() 116 | # run as script 117 | # not accept any option 118 | elif not argv[0].startswith('-'): 119 | source = argv[0] 120 | sys.argv = argv 121 | # run as command 122 | elif len(argv)==1: 123 | if argv[0] == '--info': 124 | from info import info 125 | info() 126 | sys.exit() 127 | if argv[0] == '-V' or argv[0] == '--version': 128 | from release import version 129 | print "zhpy %s on python %s"%(version, sys.version.split()[0]) 130 | sys.exit() 131 | elif argv[0] == '-h' or argv[0] == '--help': 132 | print commandline.__doc__ 133 | sys.exit() 134 | # run as native interpreter 135 | elif argv[0] == '--tw': 136 | from interpreter import interpreter 137 | import import_hook 138 | interpreter('tw') 139 | sys.exit() 140 | elif argv[0] == '--cn': 141 | from interpreter import interpreter 142 | import import_hook 143 | interpreter('cn') 144 | sys.exit() 145 | else: 146 | print commandline.__doc__ 147 | sys.exit() 148 | # accept "-c -e -v" 149 | elif len(argv)>=2: 150 | if argv[0] == '-c' or argv[0] == '--cmp': 151 | raw_source = argv[1] 152 | del(argv[:2]) 153 | if len(argv)>=2 and (argv[0] == '-e' or argv[0] == '--encoding'): 154 | encoding = argv[1] 155 | del(argv[:2]) 156 | if (len(argv)!=0) and (argv[0] == '-v' or \ 157 | argv[0] == '--verbose'): 158 | verbose = True 159 | # python to twpy 160 | elif argv[0] == '--tw': 161 | from pyzh import zh_chr, rev_annotator 162 | rev_annotator() 163 | 164 | source = argv[1] 165 | filename = os.path.splitext(source)[0] 166 | # remove extra .tw in filename 167 | profix = os.path.splitext(filename)[-1] 168 | if profix =='.tw': 169 | filename = os.path.splitext(filename)[0] 170 | del(argv[:2]) 171 | tw = True 172 | target = "v_"+zh_chr(filename)+".twpy" 173 | if (len(argv)!=0) and (argv[0] == '-v' or argv[0] == '--verbose'): 174 | verbose = True 175 | # python to cnpy 176 | elif argv[0] == '--cn': 177 | from pyzh import zh_chr, rev_annotator 178 | rev_annotator() 179 | 180 | source = argv[1] 181 | filename = os.path.splitext(source)[0] 182 | # remove extra .cn in filename 183 | profix = os.path.splitext(filename)[-1] 184 | if profix == '.cn': 185 | filename = os.path.splitext(filename)[0] 186 | del(argv[:2]) 187 | cn = True 188 | target = "v_"+zh_chr(filename)+".cnpy" 189 | if (len(argv)!=0) and (argv[0] == '-v' or argv[0] == '--verbose'): 190 | verbose = True 191 | # accept "-i -o -e -v" or "-p -e" or "-c -e -v" 192 | elif argv[0] == '-i' or argv[0] == '--input': 193 | source = argv[1] 194 | del(argv[:2]) 195 | if (len(argv)!=0) and (argv[0] == '-v' or argv[0] == '--verbose'): 196 | verbose = True 197 | if len(argv)>=2 and (argv[0] == '-e' or argv[0] == '--encoding'): 198 | encoding = argv[1] 199 | del(argv[:2]) 200 | if (len(argv)!=0) and (argv[0] == '-v' or \ 201 | argv[0] == '--verbose'): 202 | verbose = True 203 | if len(argv)>=2 and (argv[0] == '-o' or argv[0] == '--output'): 204 | target = argv[1] 205 | del(argv[:2]) 206 | if len(argv)>=2 and (argv[0] == '-e' or \ 207 | argv[0] == '--encoding'): 208 | encoding = argv[1] 209 | del(argv[:2]) 210 | if (len(argv)!=0) and (argv[0] == '-v' or \ 211 | argv[0] == '--verbose'): 212 | verbose = True 213 | elif argv[0] == '-p' or argv[0] == '--python': 214 | source = argv[1] 215 | filename = os.path.splitext(source)[0] 216 | # remove extra .tw in filename 217 | profix = os.path.splitext(filename)[-1] 218 | if (profix =='.tw') or (profix =='.cn'): 219 | filename = os.path.splitext(filename)[0] 220 | del(argv[:2]) 221 | # chinese filename to uri filename 222 | for i in filename: 223 | if i not in \ 224 | list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.'): 225 | NonEnglish = True 226 | print i, "file name is not in english" 227 | break 228 | 229 | if NonEnglish: 230 | target = zh_ord(filename.decode('utf8'))+".py" 231 | print "compile to python and run: %s"%( 232 | zh_ord(filename.decode('utf8'))+".py") 233 | else: 234 | target = "n_"+filename+".py" 235 | print "compile to python and run: %s"%("n_"+filename+".py") 236 | python = True 237 | 238 | if (len(argv)!=0) and (argv[0] == '-v' or argv[0] == '--verbose'): 239 | verbose = True 240 | if len(argv)>=2 and (argv[0] == '-e' or argv[0] == '--encoding'): 241 | encoding = argv[1] 242 | del(argv[:2]) 243 | if (len(argv)!=0) and (argv[0] == '-v' or \ 244 | argv[0] == '--verbose'): 245 | verbose = True 246 | else: 247 | print commandline.__doc__ 248 | sys.exit() 249 | #convert 250 | if raw_source: 251 | if verbose: 252 | print "run raw_source", raw_source 253 | #annotator() 254 | if encoding: 255 | result = convertor(raw_source, verbose, encoding) 256 | else: 257 | result = convertor(raw_source, verbose) 258 | zh_exec(result) 259 | import import_hook 260 | sys.exit() 261 | 262 | if encoding: 263 | print "encoding", encoding 264 | 265 | if source: 266 | if verbose: 267 | print "input", source 268 | # convertor 269 | if(tw or cn): 270 | if verbose: 271 | print "convert python code to", 272 | try: 273 | from pyzh import rev_annotator, python_convertor 274 | test = file(source, "r").read() 275 | if tw: 276 | print "twpy" 277 | rev_annotator('tw', verbose) 278 | result = python_convertor(test, lang='tw') 279 | if cn: 280 | print "cnpy" 281 | rev_annotator('cn', verbose) 282 | result = python_convertor(test, lang='cn') 283 | except Exception, e: 284 | print "zhpy Exception: you may input unproper source" 285 | if verbose: 286 | print e 287 | sys.exit() 288 | else: 289 | try: 290 | test = file(source, "r").read() 291 | #annotator() 292 | import import_hook 293 | if encoding: 294 | result = convertor(test, verbose, encoding) 295 | else: 296 | result = convertor(test, verbose) 297 | except Exception, e: 298 | print "zhpy Exception: you may input unproper source" 299 | if verbose: 300 | print e 301 | sys.exit() 302 | if target: 303 | if verbose: 304 | print "output", target 305 | file(target,"w").write(result) 306 | if python: 307 | zh_exec(result) 308 | else: 309 | zh_exec(result) 310 | 311 | if __name__=="__main__": 312 | commandline() 313 | -------------------------------------------------------------------------------- /zhpy2/zhpy/ext/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gasolin/zhpy/f4d932a5ab810158ef4e4113df337cbf7d83817a/zhpy2/zhpy/ext/__init__.py -------------------------------------------------------------------------------- /zhpy2/zhpy/ext/pygmentplugin.py: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | 3 | import re 4 | try: 5 | set 6 | except NameError: 7 | from sets import Set as set 8 | 9 | #from pygments.lexers.agile import PythonLexer 10 | from pygments.lexer import Lexer, RegexLexer, ExtendedRegexLexer, \ 11 | LexerContext, include, combined, do_insertions, bygroups, using 12 | from pygments.token import Error, Text, \ 13 | Comment, Operator, Keyword, Name, String, Number, Generic, Punctuation 14 | from pygments.util import get_bool_opt, get_list_opt, shebang_matches 15 | from pygments import unistring as uni 16 | 17 | from pygments.lexers.functional import SchemeLexer 18 | 19 | line_re = re.compile('.*?\n') 20 | 21 | class ZhpyLexer(RegexLexer): 22 | """ 23 | for zhpy source code 24 | """ 25 | name = "Zhpy" 26 | aliases = ['zhpy'] 27 | filenames = ['*.twpy', '*.cnpy', '*.py'] 28 | 29 | tokens = { 30 | 'root': [ 31 | (r'\n', Text), 32 | (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)), #docstring 33 | (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)), #docstring 34 | (r'[^\S\n]+', Text), 35 | (r'#.*$', Comment), #comment 36 | (r'[]{}:(),;[]', Punctuation), 37 | (r'\\\n', Text), 38 | (r'\\', Text), 39 | (r'(in|is|and|or|not)\b', Operator.Word), 40 | (r'!=|==|<<|>>|[-~+/*%=<>&^|.]', Operator), 41 | include('keywords'), 42 | (r'(def)(\s+)', bygroups(Keyword, Text), 'funcname'), 43 | (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'), 44 | (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'), 45 | (r'(import)(\s+)', bygroups(Keyword, Text), 'import'), 46 | include('builtins'), 47 | include('backtick'), 48 | ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'), 49 | ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'), 50 | ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'), 51 | ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'), 52 | ('[uU]?"""', String, combined('stringescape', 'tdqs')), 53 | ("[uU]?'''", String, combined('stringescape', 'tsqs')), 54 | ('[uU]?"', String, combined('stringescape', 'dqs')), 55 | ("[uU]?'", String, combined('stringescape', 'sqs')), 56 | include('name'), 57 | include('numbers'), 58 | ], 59 | 'keywords': [ 60 | (r'(assert|break|continue|del|elif|else|except|exec|' 61 | r'finally|for|global|if|lambda|pass|print|raise|' 62 | r'return|try|while|yield|as|with|' 63 | r'印出|輸入)\b', Keyword), 64 | ], 65 | 'builtins': [ 66 | (r'(?>> print zh_chr('p_7bc4_4f8b_v') 149 | 範例 150 | >>> print zh_chr('p_7bc4_4f8b_v_1') 151 | 範例_1 152 | >>> print zh_chr('p_7bc4_4f8b_v1') 153 | 範例1 154 | >>> print zh_chr("p_6e2c_8a66_v_p_7bc4_4f8b_v") 155 | 測試_範例 156 | >>> print zh_chr("p_6e2c_8a66_v_p_7bc4_4f8b_v2") 157 | 測試_範例2 158 | """ 159 | if tmp.startswith("p_") and "_v" in tmp: 160 | tmp, profix = tmp.split('_v', 1) 161 | tmp2 = _val_matching(tmp) 162 | if not ('v' in profix and 'p' in profix): 163 | return tmp2 + profix 164 | else: # allow 2 cascade identifiers 165 | sep = profix[0:profix.index('p_')] 166 | tmp = profix[profix.index('p_')::] 167 | tmp, profix = tmp.split('_v', 1) 168 | tmp2 += sep + _val_matching(tmp) 169 | return tmp2 +profix 170 | else: 171 | return tmp 172 | 173 | # backward compatibility 174 | number_to_variable = zh_chr 175 | _pattern = r'^p_[_a-f\d]*_v\w*$' 176 | 177 | from pyparsing import Word, alphanums, \ 178 | quotedString, pythonStyleComment 179 | 180 | 181 | def convertToTW(s,l,t): 182 | """ 183 | search rev_twdict to match keywords 184 | """ 185 | tmp = t[0] 186 | if tmp in rev_twdict: 187 | return rev_twdict[tmp] 188 | elif re.match(_pattern, tmp): 189 | return zh_chr(tmp) 190 | else: 191 | return tmp 192 | 193 | 194 | def convertToCN(s,l,t): 195 | """ 196 | search rev_cndict to match keywords 197 | """ 198 | tmp = t[0] 199 | if tmp in rev_cndict: 200 | return rev_cndict[tmp] 201 | elif re.match(_pattern, tmp): 202 | return zh_chr(tmp) 203 | else: 204 | return tmp 205 | 206 | 207 | def convertToTraceBack(s,l,t): 208 | """ 209 | search rev_tbdict to match keywords 210 | """ 211 | tmp = t[0] 212 | if tmp in rev_tbdict: 213 | return rev_tbdict[tmp] 214 | elif re.match(_pattern, tmp): 215 | return zh_chr(tmp) 216 | else: 217 | return tmp 218 | 219 | #: basic parsing pattern 220 | baseWord = tripleQuote | quotedString | pythonStyleComment 221 | 222 | twenWord = Word(alphanums+"_") 223 | twenWord.setParseAction(convertToTW) 224 | #: Traditional Chinese parsing pattern 225 | twpyWord = baseWord | twenWord 226 | 227 | tbWord = Word(alphanums+"_") 228 | tbWord.setParseAction(convertToTraceBack) 229 | #: Traceback parsing pattern 230 | tbpyWord = baseWord | tbWord 231 | 232 | cnenWord = Word(alphanums+"_") 233 | cnenWord.setParseAction(convertToCN) 234 | #: Simplified Chinese parsing pattern 235 | cnpyWord = baseWord | cnenWord 236 | 237 | 238 | def python_convertor(text, lang='tw', traceback=False): 239 | """ 240 | convert python source to zhpy source 241 | 242 | Accept args: 243 | lang: 244 | 'tw' or 'cn' 245 | 246 | >>> print python_convertor("print 'hello'", 'tw') 247 | 印出 'hello' 248 | >>> print python_convertor("print 'hello'", 'cn') 249 | 打印 'hello' 250 | >>> print python_convertor("# print 'hello'", 'tw') 251 | # print 'hello' 252 | >>> print python_convertor("print '''哈囉, 世界'''", 'tw') 253 | 印出 '''哈囉, 世界''' 254 | >>> print python_convertor("p_6e2c_8a66_v_p_7bc4_4f8b_v2") 255 | 測試_範例2 256 | >>> print python_convertor("p_6e2c_8a66_v2p_7bc4_4f8b_v") 257 | 測試2範例 258 | >>> print python_convertor("p_6e2c_8a66_v2p_7bc4_4f8b_v2") 259 | 測試2範例2 260 | """ 261 | if isinstance(text, unicode): 262 | text = text.encode('utf8') 263 | 264 | if lang == 'tw': 265 | if traceback==False: 266 | result = twpyWord.transformString(text) 267 | else: 268 | result = tbpyWord.transformString(text)#+str(rev_tbdict) 269 | elif lang == 'cn': 270 | if traceback==False: 271 | result = cnpyWord.transformString(text) 272 | else: 273 | result = tbpyWord.transformString(text) 274 | else: 275 | #TODO: auto detect coding 276 | print "not valid lang option in python_convertor" 277 | return text 278 | 279 | return result 280 | -------------------------------------------------------------------------------- /zhpy2/zhpy/release.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Release information""" 4 | 5 | 6 | version = "1.7.4" 7 | author = "Fred Lin" 8 | email = "gasolin+zhpy@gmail.com" 9 | copyright = "Copyright 2007~ Fred Lin and contributors" 10 | license = "MIT " 11 | url = "https://github.com/gasolin/zhpy" 12 | download_url="https://github.com/gasolin/zhpy" 13 | description="周蟒, Write python language in chinese" 14 | long_description = """ 15 | .. contents:: 16 | :depth: 2 17 | 18 | Introduction 19 | -------------- 20 | 21 | "If it walks like a duck and quacks like a duck, I would call it a duck." 22 | 23 | Zhpy on python is good for Taiwan and China beginners to learn python in 24 | our native language (Currently it support Traditional and Simplified chinese). 25 | 26 | Zhpy acts like python and play like python, you (chinese users) 27 | could use it as python to educate yourself the program skills 28 | plus with your native language. 29 | 30 | Check examples here. 31 | 32 | * https://github.com/gasolin/zhpy/tree/master/zhpy2/examples 33 | 34 | (Please install python 2.x to use this project) 35 | 36 | Play locally 37 | -------------- 38 | 39 | To play zhpy locally, you even don't need to install it. 40 | 41 | All you need to do is follow the 3 steps guide: 42 | 43 | 1. Download the source pack (the zip file) 44 | 2. Extract the pack with zip tool. Enter the folder 45 | 3. Run:: 46 | 47 | $ python interpreter.py 48 | 49 | Then you got the usable zhpy interpreter! 50 | 51 | 52 | Install 53 | ---------- 54 | 55 | If you'd like to play zhpy with full features, you should install zhpy. 56 | 57 | You could use easy_install command to install or upgrade zhpy:: 58 | 59 | $ easy_install -U zhpy 60 | 61 | or check instructions for detail. 62 | 63 | * https://github.com/gasolin/zhpy/blob/wiki/DownloadInstall.md 64 | 65 | 66 | Usage 67 | ------- 68 | 69 | You could use zhpy interpreter to test zhpy:: 70 | 71 | $ zhpy 72 | zhpy [version] in [platform] on top of Python [py_version] 73 | >>> print 'hello in chinese' 74 | hello in chinese 75 | 76 | Browse project homepage to get examples in chinese. 77 | 78 | * https://github.com/gasolin/zhpy 79 | 80 | check the BasicUsage for detail. 81 | 82 | * https://github.com/gasolin/zhpy/blob/wiki/BasicUsage.md 83 | 84 | 85 | Programming Guide 86 | ------------------- 87 | 88 | You could freely view the C.C. licensed book "A Byte of python (Zhpy)" 89 | on zhpy website, which contained zhpy example codes as well. 90 | 91 | * https://github.com/gasolin/zhpy/blob/wiki/ByteOfZhpy.md 92 | 93 | There's the API document available in zhpy download list, too. 94 | 95 | * http://code.google.com/p/zhpy/downloads/list 96 | 97 | PS: The book is based on "A Byte of Python". 98 | 99 | * http://swaroopch.info/text/Byte_of_Python:Main_Page 100 | 101 | 102 | What is Zhpy 103 | -------------- 104 | 105 | Zhpy is the full feature python language with fully tested chinese 106 | keywords, variables, and parameters support. Zhpy is INDEPENDENT on python 107 | version(2.4, 2.5....), bundle with command line tool, interpreter, 108 | bi-directional zhpy <-> python code translation, 109 | chinese shell script capability, in-place ini reference feature 110 | for keyword reuse, and great document (the book Byte of Python with chinese examples). 111 | 112 | The core of zhpy is a lightweight python module and a chinese 113 | source convertor based on python, which provides interpreter and 114 | command line tool to translate zhpy code to python. 115 | 116 | See http://www.flickr.com/photos/gasolin/2064120327 117 | 118 | You could invoke interpreter with 'zhpy' command instead of "python" in command line to execute source code wrote in either Chinese or English. 119 | The zhpy interpreter also support autocomplete function to save your typing. 120 | 121 | Zhpy provide a method 'zh_exec' that allow you to embed 122 | chinese script in python; Zhpy could be used as the chinese 123 | shell script as well. 124 | 125 | The zhpy code written in traditional and simplified chinese could be 126 | translated and converted to natual python code. 127 | Thus it could be execute as nature python code and be used in 128 | normal python programs. 129 | 130 | Bidirectional python-zhpy translation is possible. 131 | Normal python programs could be translated to traditional(.twpy) or 132 | simplified(.cnpy) chinese zhpy source via 'zhpy' command line tool. 133 | 134 | The framework is not hard to extend to another languages such as japenese or korean. 135 | 136 | 137 | Change Log 138 | ------------- 139 | 140 | You could view the ChangeLog to see what's new in these version. 141 | 142 | * https://github.com/gasolin/zhpy/blob/master/CHANGELOG.txt 143 | 144 | """ 145 | -------------------------------------------------------------------------------- /zhpy2/zhpy/zhdc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """zhpy keywords convertion library 5 | 6 | This is the MIT license: 7 | http://www.opensource.org/licenses/mit-license.php 8 | 9 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to 13 | deal in the Software without restriction, including without limitation the 14 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | sell copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | """ 29 | 30 | 31 | # Universal keywords repository 32 | #: always run annotator before access worddict 33 | worddict = {} 34 | #: Traditional Chinese keywords repository 35 | twdict = {} 36 | #: Simplified Chinese keywords repository 37 | cndict = {} 38 | 39 | class ZhpyPlugin(object): 40 | """ 41 | basic plugin class 42 | """ 43 | pass 44 | 45 | 46 | def revert_dict(lang_dict): 47 | """make a reverse dictionary from the input dictionary 48 | 49 | >>> revert_dict({'a':'1', 'b':'2'}) 50 | {'1': 'a', '2': 'b'} 51 | """ 52 | rev_dict = {} 53 | dict_keys = lang_dict.keys() 54 | dict_keys.reverse() 55 | #map(rev_dict.update, map(lambda i: {lang_dict[i]:i}, dict_keys)) 56 | for i in dict_keys: 57 | rev_dict.update({lang_dict[i]:i}) 58 | return rev_dict 59 | -------------------------------------------------------------------------------- /zhpy2/zhpy/zhpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """Transform zhpy source to python source 5 | 6 | zhpy is the python language with chinese native keywords, variables, and 7 | parameters support, independent on python's version. 8 | 9 | zhpy's core function is a convertor/pre-processor to translate chinese 10 | python code to nature python code (english) and vice versa. 11 | 12 | zhpy is motivated by HYRY's origin code. 13 | 14 | gasolin+zhpy@gmail.com 15 | 16 | This is the MIT license: 17 | http://www.opensource.org/licenses/mit-license.php 18 | 19 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining a copy 22 | of this software and associated documentation files (the "Software"), to 23 | deal in the Software without restriction, including without limitation the 24 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 25 | sell copies of the Software, and to permit persons to whom the Software is 26 | furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in 29 | all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 32 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 34 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 36 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 37 | THE SOFTWARE. 38 | """ 39 | 40 | 41 | from zhdc import worddict, twdict, cndict 42 | 43 | supported_dicts = [("plugtw", twdict), 44 | ("plugcn", cndict)] 45 | 46 | 47 | def merger(anno_dict, use_dict=worddict, verbose=True, reverse=False): 48 | """ 49 | merge extra bindings into worddict 50 | 51 | Accept args: 52 | anno_dict: 53 | source dict 54 | use_dict: 55 | target dict to be merged, default: 'worddict' 56 | verbose: 57 | show detail message, default: True 58 | 59 | merger could accept list input: 60 | 61 | >>> keys = [('遊戲', 'pygame'), ('螢幕', 'screen')] 62 | >>> merger(keys) 63 | add 遊戲=pygame 64 | add 螢幕=screen 65 | >>> '遊戲' in worddict 66 | True 67 | 68 | merger could accept dict input: 69 | 70 | >>> keydic = {'作業系統':'os', '分支':'fork'} 71 | >>> merger(keydic) 72 | add 分支=fork 73 | add 作業系統=os 74 | >>> '作業系統' in worddict 75 | True 76 | """ 77 | if isinstance(anno_dict, dict): 78 | data_iter = anno_dict.iteritems() 79 | else: 80 | data_iter = anno_dict 81 | 82 | if reverse: 83 | #data_iter=((v,k) for (k,v) in data_iter) 84 | rev_iter = [] 85 | for (k,v) in data_iter: 86 | rev_iter.append((v,k)) 87 | data_iter = rev_iter 88 | 89 | for k,v in data_iter: 90 | if k not in use_dict: 91 | use_dict[k] = v 92 | if verbose: 93 | print "add %s=%s"%(k, v) 94 | else: 95 | if verbose: 96 | print "already has key: %s, %s" % (k, v) 97 | 98 | import os 99 | import ConfigParser 100 | 101 | 102 | def _ini_annotator(verbose=True, force=False): 103 | """ 104 | find ini files and use keywords defined in ini during 105 | convertion progress. 106 | 107 | Accept args: 108 | verbose: 109 | show detail message, default: True 110 | 111 | """ 112 | #lazy load 113 | if not force and getattr(_ini_annotator, "already", False): 114 | return 115 | _ini_annotator.already=True 116 | 117 | inifiles = [] 118 | for x in os.listdir("."): 119 | if x.endswith(".ini"): 120 | inifiles.append(x) 121 | for f in inifiles: 122 | if verbose: 123 | print "file", f 124 | conf = ConfigParser.ConfigParser() 125 | try: 126 | conf.read(f) 127 | for sect in conf.sections(): 128 | if verbose: 129 | print "sect:", sect 130 | merger(conf.items(sect)) 131 | except: 132 | print "!%s is not a valid keyword file"%f 133 | 134 | 135 | def _py_annotator(verbose=False,force=False): 136 | """ 137 | find python keyword plugins and update to dicts 138 | 139 | Accept args: 140 | verbose: 141 | show detail message, default: False 142 | 143 | 'verbose' argument is only for debug(will generate too mush messages). 144 | """ 145 | #lazy load 146 | if not force and getattr(_py_annotator, "already", False): 147 | return 148 | _py_annotator.already=True 149 | 150 | # parameter to check if there's any plugin available 151 | has_annotator = False 152 | # process plugins 153 | for plugin, use_dict in supported_dicts: 154 | try: 155 | #py2.4 doesn't have level argument 156 | load_dict=__import__(plugin, globals(), locals(), ['tools']) 157 | for tool in load_dict.tools: 158 | if verbose: 159 | print tool.title 160 | merger(tool.keyword, use_dict=use_dict, verbose=verbose) 161 | merger(use_dict, verbose=verbose) 162 | has_annotator = True 163 | except ImportError, e: 164 | if verbose: 165 | print "import plug%s error"%plugin, e 166 | if not has_annotator: 167 | raise ReferenceError("no plugin was referenced in annotator") 168 | _py_annotator.__loaded=False 169 | 170 | 171 | def annotator(verbose=True, force=False): 172 | """ 173 | provide two ways to expand the worddict: 174 | 175 | 1. ini files 176 | 177 | 2. python plugin system. 178 | 179 | Accept args: 180 | verbose: 181 | show detail message, default: True 182 | 183 | """ 184 | _ini_annotator(verbose, force) 185 | _py_annotator(False, force) 186 | 187 | 188 | def zh_ord(tmp): 189 | """ 190 | convert chinese variable to pseudo hex identifer 191 | 192 | >>> '範例'.decode("utf8") 193 | u'\u7bc4\u4f8b' 194 | >>> s = '範例'.decode("utf8") 195 | >>> zh_ord(s) 196 | 'p_7bc4_4f8b_v' 197 | """ 198 | word_list=[] 199 | for i in tmp: 200 | ori = str(hex(ord(i)))[2:] 201 | word_list.append(ori) 202 | return 'p_' + "_".join(word_list) + '_v' 203 | 204 | # backward compatibility 205 | variable_to_number = zh_ord 206 | 207 | from pyparsing import srange, Word, quotedString, pythonStyleComment, \ 208 | QuotedString 209 | 210 | 211 | def convertToEnglish(s,l,t): 212 | """search worddict to match keywords 213 | 214 | if not in keyword, replace the chinese variable/argument/ 215 | function name/class name/method name to a variable with prefix 'p' 216 | """ 217 | tmp = t[0].encode("utf8") 218 | if tmp in worddict: 219 | word = worddict[tmp].decode("utf8") 220 | else: 221 | word = zh_ord(t[0]) 222 | return word 223 | 224 | chineseChars = srange(r"[\0x0080-\0xfe00]") 225 | chineseWord = Word(chineseChars) 226 | chineseWord.setParseAction(convertToEnglish) 227 | tripleQuote = QuotedString('"""', multiline=True, unquoteResults=False) | \ 228 | QuotedString("'''", multiline=True, unquoteResults=False) 229 | 230 | pythonWord = tripleQuote | quotedString | pythonStyleComment | chineseWord 231 | 232 | try: 233 | import chardet 234 | has_chardet = True 235 | except: 236 | has_chardet = False 237 | print "chardet module is not installed" 238 | 239 | 240 | def convertor(text, verbose=False, encoding="", outcoding=""): 241 | """ 242 | convert zhpy source (Chinese) to Python Source. 243 | 244 | annotator will be called automatically. 245 | 246 | Accept args: 247 | test: 248 | source to be converted 249 | verbose: 250 | show detail message, default: False 251 | encoding: 252 | codec for encoding 253 | outcoding: 254 | codec for output encoding 255 | 256 | #annotator() 257 | >>> convertor("印出 'hello'") 258 | "print 'hello'" 259 | 260 | >>> convertor("印出 'hello'", encoding="utf8") 261 | "print 'hello'" 262 | 263 | >>> convertor('測試_範例') 264 | 'test_p_7bc4_4f8b_v' 265 | 266 | more keyword test cases are in /tests folder. 267 | """ 268 | # annotate if necessary 269 | annotator(force=False) 270 | #Use the provided encoding, if not exist select utf-8 as default. 271 | if encoding and encoding.lower() != 'utf-8': 272 | utext = text.decode(encoding) 273 | else: 274 | if has_chardet: 275 | try: 276 | #detect encoding 277 | det = chardet.detect(text) 278 | if verbose: 279 | print "chardet", det 280 | if det['confidence'] >= 0.8: 281 | encoding = chardet.detect(text)['encoding'] 282 | else: 283 | if verbose: 284 | print """low confidence encoding detection, 285 | use utf8 encoding""" 286 | encoding = 'utf8' 287 | #prepare for unicode type support 288 | if isinstance(text, unicode): 289 | utext = text 290 | else: 291 | utext = text.decode(encoding) 292 | except UnicodeDecodeError, e: 293 | print "can't recognize your language, \ 294 | set to sys.stdout.encoding" 295 | utext = text.decode('utf8') 296 | except ImportError, e: 297 | if verbose: 298 | print "proceed no chardet mode" 299 | utext = text.decode('utf8') 300 | else: 301 | utext = text 302 | result = pythonWord.transformString(utext) 303 | if outcoding: 304 | return result.encode(outcoding) 305 | elif isinstance(text, unicode): 306 | return result 307 | else: 308 | if encoding: 309 | return result.encode(encoding) 310 | else: 311 | return result 312 | 313 | import sys 314 | # parameter to control if support chinese traceback 315 | has_zhtraceback=None 316 | try: 317 | import traceback 318 | from pyzh import python_convertor, rev_annotator 319 | has_zhtraceback=True 320 | except: 321 | print "not support chinese traceback" 322 | has_zhtraceback=None 323 | 324 | 325 | def try_run(result, global_ns={}, local_ns={}, verbose=True, zhtrace=True): 326 | """ 327 | execute result and catch exceptions in specified namespace 328 | 329 | Accept args: 330 | result: 331 | the converted source to be executed 332 | global_ns: 333 | Global namespace, deafult is {} 334 | local_ns: 335 | Local namespace, default is: {} 336 | 337 | >>> global_ns = {'x':'g'} 338 | >>> local_ns = {'x':'l'} 339 | >>> global_ns.update( {"__name__": "__main__", "__doc__": None}) 340 | >>> try_run("print 'hello'", {}, {}) 341 | hello 342 | >>> try_run("print x", global_ns, local_ns) 343 | l 344 | >>> try_run("print x", global_ns) 345 | g 346 | """ 347 | try: 348 | # able to import modules in current directory 349 | sys.path.insert(0, '') 350 | exec result in global_ns, local_ns 351 | #compile(result, os.getcwd(), "exec") 352 | except Exception, e: 353 | # Print error and track back. 354 | if has_zhtraceback and zhtrace: 355 | display = os.getenv("LANG") 356 | if display == None: 357 | lang = None 358 | elif "zh_TW" in display: 359 | lang = "tw" 360 | elif "zh_CN" in display: 361 | lang = "cn" 362 | else: 363 | lang = None 364 | stack = traceback.format_exc() 365 | if lang: 366 | rev_annotator(lang) 367 | print python_convertor(stack, lang, 368 | traceback=True).decode("utf-8") 369 | else: 370 | # Standard English output 371 | print stack 372 | else: 373 | if verbose: 374 | print result 375 | print e 376 | 377 | 378 | def zh_exec(content, 379 | global_ns={"__name__": "__main__", "__doc__": None}, 380 | local_ns={}, 381 | outcoding=""): 382 | """ 383 | the zhpy exec 384 | 385 | Accept args: 386 | content: 387 | the source to be converted and executed with zhpy in specified 388 | namespace 389 | global_ns: 390 | Global namespace, deafult is {"__name__": "__main__", "__doc__": None} 391 | local_ns: 392 | Local namespace, default is: {} 393 | 394 | >>> zh_exec("印出 'hello'") 395 | hello 396 | """ 397 | #annotator() 398 | result = convertor(content, outcoding=outcoding) 399 | if local_ns == {}: 400 | local_ns = global_ns 401 | try_run(result, global_ns, local_ns) 402 | -------------------------------------------------------------------------------- /zhpy3/cnpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | import os 6 | import tokenize 7 | import plugcn 8 | import runpy 9 | from core import translate_code 10 | 11 | translations = plugcn.trans 12 | 13 | def commandline(): 14 | """zhpy3, the python language in Simplified Chinese 15 | 16 | usage: cnpy file.cnpy 17 | """ 18 | if len(sys.argv) != 2: 19 | print(commandline.__doc__) 20 | sys.exit(1) 21 | 22 | file_path = sys.argv[1] 23 | 24 | if not os.path.exists(file_path): 25 | print("twpy: file '%s' does not exists" % file_path) 26 | sys.exit(1) 27 | 28 | #sys.meta_path = [ImportHook()] 29 | 30 | sys.path[0] = os.path.dirname(os.path.join(os.getcwd(), file_path)) 31 | 32 | source = tokenize.untokenize( 33 | list(translate_code(open(file_path).readline, translations))) 34 | 35 | #translate_module(__builtins__) 36 | 37 | code = compile(source, file_path, "exec") 38 | 39 | runpy._run_module_code(code, mod_name="__main__") 40 | 41 | if __name__=="__main__": 42 | commandline() -------------------------------------------------------------------------------- /zhpy3/core.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import tokenize 4 | 5 | def translate_code(readline, translations): 6 | for type, name, _,_,_ in tokenize.generate_tokens(readline): 7 | if type == tokenize.NAME and name in translations: 8 | yield tokenize.NAME, translations[name] 9 | else: 10 | yield type, name 11 | 12 | -------------------------------------------------------------------------------- /zhpy3/examples/hello/hello.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # this is a sample Python program 3 | 定義 範例_1(訊息, 次數): 4 | 取 數 在 range(次數): 5 | 印出("哈囉, ", 訊息) 6 | 7 | 範例_1("世界", 100) -------------------------------------------------------------------------------- /zhpy3/examples/inout/inout.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 資料 = 輸入("輸入姓名: ") 3 | 印出("歡迎,", 資料) -------------------------------------------------------------------------------- /zhpy3/examples/loop/contact.cnpy: -------------------------------------------------------------------------------- 1 | #coding=utf-8 2 | # by jiahua huang 3 | 4 | 姓名表=('张三','李斯','王海','荷花') 5 | 定义 打印姓名表(): 6 | 计数=1 7 | 取 姓名 在 姓名表: 8 | 打印(计数, 姓名) 9 | 计数+=1 10 | 11 | 主程序: 12 | 打印姓名表() -------------------------------------------------------------------------------- /zhpy3/examples/loop/tabl.twpy: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 定義 乘法表(表格大小): 3 | 取 乘數 自 範圍(1, 表格大小+1): 4 | 取 被乘數 自 範圍(1, 表格大小+1): 5 | 印出(乘數,"*", 被乘數, "=", 乘數*被乘數) 6 | 7 | 乘法表(9) -------------------------------------------------------------------------------- /zhpy3/examples/teashop/teashop.tw.py: -------------------------------------------------------------------------------- 1 | #coding = utf-8 2 | """ 3 | 泡沫紅茶店 0.1 4 | 5 | 1. 茶種 紅 綠 清 抹 烏龍 6 | 2. 配料 珍珠 粉圓 百香 檸檬 梅子 7 | 3. 糖量 少糖 3/4, 半糖 1/2 微糖 1/4 8 | 4. 冰量 去冰 少冰 9 | """ 10 | 11 | 茶種 = {"紅茶":15,"綠茶":15, "清茶":15, "抹茶":15, \ 12 | "烏龍":15, "奶茶":20, "奶綠":20} #字典 13 | 14 | 配料 = {"珍珠":5, "粉圓":5, "百香":5, "檸檬":5, "梅子":5} 15 | 16 | 糖量 = ["少糖","半糖","微糖"] #列表 17 | 18 | 冰量 = ["去冰", "少冰"] 19 | 20 | 定義 飲料單生成器(): 21 | """ 22 | 產生飲料價目單 23 | """ 24 | 取 料 自 配料.鍵列表(): # 迴圈 25 | 取 茶 自 茶種.鍵列表(): 26 | 標價 = 茶種[茶] + 配料[料] 27 | 印出(料+茶, 標價,) 28 | 取 糖 自 糖量: 29 | 印出(糖,) 30 | 取 冰 自 冰量: 31 | 印出(冰,) 32 | 印出('') 33 | 34 | 主程式: 35 | 飲料單生成器() -------------------------------------------------------------------------------- /zhpy3/plugcn.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """Simplified Chinese keyword dictionaries 5 | 6 | This is the MIT license: 7 | http://www.opensource.org/licenses/mit-license.php 8 | 9 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to 13 | deal in the Software without restriction, including without limitation the 14 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | sell copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | """ 29 | 30 | 31 | from zhdc import ZhpyPlugin 32 | 33 | # Simplized chinese keywords 34 | class cn_keyword(ZhpyPlugin): 35 | """ 36 | python cn keyword 37 | """ 38 | title = "内建关键词" 39 | description = "Python 内建关键词" 40 | keyword = { 41 | # logic 42 | "和":"and", 43 | "且":"and", 44 | "或":"or", 45 | "真": "True", 46 | "假":"False", 47 | "实":"True", 48 | "虛":"False", 49 | "空":"None", 50 | # def 51 | "定义":"def", 52 | "类":"class", 53 | "类別":"class", 54 | "我":"self", 55 | "自个儿":"self", 56 | "共用":"global", 57 | "全域":"global", 58 | # import 59 | "从":"from", 60 | "导入":"import", 61 | "作为":"as", 62 | # flow 63 | "返回":"return", 64 | "略过":"pass", 65 | "引发":"raise", 66 | "继续":"continue", 67 | # control 68 | "如果":"if", 69 | "假使":"elif", 70 | "否则如果":"elif", 71 | "否则":"else", 72 | # for loop 73 | "取":"for", 74 | "自":"in", 75 | "在":"in", 76 | "不在":"not in", 77 | # while loop 78 | "当":"while", 79 | "跳出":"break", 80 | "中断":"break", 81 | # try 82 | "尝试":"try", 83 | "异常":"except", 84 | "最后":"finally", 85 | "申明":"assert", 86 | # build in methods 87 | "执行":"exec", 88 | "函数":"lambda", 89 | "打印":"print", 90 | "伴隨":"with", 91 | "产生":"yield", 92 | } 93 | 94 | 95 | class cn_buildin_method(ZhpyPlugin): 96 | """ 97 | python cn methods 98 | """ 99 | title = "内部函数" 100 | description = "Python 内部函数" 101 | keyword = { 102 | "输入":"input", 103 | # build-in types 104 | "字符串":"str", 105 | "布尔":"bool", 106 | "列表": "list", 107 | "字典":"dict", 108 | "元组":"tuple", 109 | "集合":"set", 110 | "定集合":"frozenset", 111 | "符号":"chr", 112 | "符号转整数":"ord", 113 | "档案":"file", 114 | # number methods 115 | "整数":"int", 116 | "浮点数":"float", 117 | "复数":"complex", 118 | "十六进制":"hex", 119 | "绝对值":"abs", 120 | "比较":"cmp", 121 | # string methods 122 | "开头为":"startswith", 123 | "结尾为":"endswith", 124 | "连接":"join", 125 | "分离":"split", 126 | "代换":"replace", 127 | "编码":"encoding", 128 | "解码":"decoding", 129 | # list methods 130 | "加入":"append", 131 | "追加":"append", 132 | "扩展":"extend", 133 | "插入":"insert", 134 | "弹出":"pop", 135 | "下一笔":"next", 136 | "移除":"remove", 137 | "反转":"reverse", 138 | "计数":"count", 139 | "索引":"index", 140 | "排序":"sort", 141 | # dict methods 142 | "键列表":"keys", 143 | "值列表":"values", 144 | "项目列表":"items", 145 | "更新":"update", 146 | "拷贝":"copy", 147 | # set methods 148 | "清除":"clear", 149 | "加":"add", 150 | "丢弃":"discard", 151 | "联集":"union", 152 | "交集":"intersection", 153 | "差集":"difference", 154 | "对称差集":"symmetric_difference", 155 | # file methods 156 | "打开":"open", 157 | "读取":"read", 158 | "写入":"write", 159 | "读一行":"readline", 160 | "读多行":"readlines", 161 | "关闭":"close", 162 | # OO 163 | "可调用":"callable", 164 | "列出属性":"dir", 165 | "取属性":"getattr", 166 | "有属性":"hasattr", 167 | "设定属性":"setattr", 168 | "属性":"property", 169 | # build in functions 170 | "长度":"len", 171 | "最大值":"max", 172 | "最小值":"min", 173 | # build in methods 174 | "列举":"enumerate", 175 | "评估":"eval", 176 | "过滤":"filter", 177 | "映射":"map", 178 | "范围":"range", 179 | "快速范围":"xrange", 180 | "总和":"sum", 181 | "类型":"type", 182 | "对象":"object", 183 | "打包":"zip", 184 | "帮助":"help", 185 | "说明":"help", 186 | "区域变量":"locals", 187 | "全域变量":"globals", 188 | "类方法":"classmethod", 189 | } 190 | 191 | 192 | class cn_exception(ZhpyPlugin): 193 | """ 194 | python cn exceptions 195 | """ 196 | title = "例外" 197 | description = "Python 内建例外关键词" 198 | keyword = { 199 | "例外":"Exception", 200 | "错误":"Error", 201 | # error 202 | "运算错误":"ArithmeticError", 203 | "申明错误":"AssertionError", 204 | "属性错误":"AttributeError", 205 | "相容性警示":"DeprecationWarning", 206 | "空值错误":"EOFError", 207 | "环境错误":"EnvironmentError", 208 | "浮点数错误":"FloatingPointError", 209 | "输出入错误":"IOError", 210 | "导入错误":"ImportError", 211 | "缩排错误":"IndentationError", 212 | "索引错误":"IndexError", 213 | "键错误":"KeyError", 214 | "键盘中断":"KeyboardInterrupt", 215 | "查找错误":"LookupError", 216 | "内存错误":"MemoryError", 217 | "名称错误":"NameError", 218 | "尚未实作":"NotImplemented", 219 | "尚未实作错误":"NotImplementedError", 220 | "操作系统错误":"OSError", 221 | "溢值错误":"OverflowError", 222 | "溢值警告":"OverflowWarning", 223 | "引用错误":"ReferenceError", 224 | "运行期错误":"RuntimeError", 225 | "运行期警告":"RuntimeWarning", 226 | "标准错误":"StandardError", 227 | "停止迭代":"StopIteration", 228 | "语法错误":"SyntaxError", 229 | "语法警告":"SyntaxWarning", 230 | "系统错误":"SystemError", 231 | "系统结束":"SystemExit", 232 | "型别错误":"TypeError", 233 | "跳格错误":"TabError", 234 | "未绑定区域参数错误":"UnboundLocalError", 235 | "万国码解码错误":"UnicodeError", 236 | "自订警告":"UserWarning", 237 | "值错误":"ValueError", 238 | "警告":"Warning", 239 | "Windows错误":"WindowsError", 240 | "除零错误":"ZeroDivisionError", 241 | "解码错误":"UnicodeDecodeError", 242 | } 243 | 244 | 245 | class cn_zhpy(ZhpyPlugin): 246 | """ 247 | zhpy cn keyword plugin 248 | """ 249 | title = "周蟒" 250 | description = "周蟒内建关键词" 251 | keyword = { 252 | "周蟒":"zhpy", 253 | "主程序":'if __name__=="__main__"', 254 | # must do 'from zhpy import zh_exec'/'从 周蟒 导入 中文执行' first 255 | "中文执行":"zh_exec", 256 | # logic 257 | "等于":"==", 258 | "不等于":"!=", 259 | "非": "not", 260 | "是":"is", 261 | "为":"is", 262 | "不是":"is not", 263 | "不为":"is not", 264 | # private 265 | "文件":"doc", 266 | "初始化":"init", 267 | "刪除":"del", 268 | "描述":"repr", 269 | "测试":"test", 270 | } 271 | 272 | #enter simplified chinese dict here 273 | class cn_sys(ZhpyPlugin): 274 | """ 275 | zhpy sys module simplified chinese plugin 276 | """ 277 | title = "系统" 278 | description = "系统模块" 279 | keyword = {"系统":"sys", 280 | "版本":"version", 281 | "参数":"argv", 282 | "结束":"exit", 283 | "取得档案系统编码":"getfilesystemencoding", 284 | "模块列表":"modules", 285 | "平台":"platform", 286 | "标准错误":"stderr", 287 | "标准输入":"stdin", 288 | "标准输出":"stdout", 289 | # sys path with list methods 290 | "路径":"path", 291 | } 292 | 293 | class cn_traceback(ZhpyPlugin): 294 | """ 295 | zhpy traceback simplified chinese plugin 296 | """ 297 | title = "系统" 298 | description = "系统模组" 299 | keyword = {"未定义":"is not defined", 300 | "名称":"name", 301 | "行":"line", 302 | "档案":"File", 303 | "不合法的":"invalid", 304 | "语法":"syntax", 305 | } 306 | 307 | # [zhpy.cndict] 308 | keyword = cn_keyword() 309 | method = cn_buildin_method() 310 | exception = cn_exception() 311 | zhpy= cn_zhpy() 312 | sys = cn_sys() 313 | trace = cn_traceback() 314 | 315 | #tools = [cnkeyword, cnmethod, cnexception, cnzhpy, cnsys] 316 | #trace = [cnkeyword, cnmethod, cnexception, cntrace, cnsys] 317 | trans = dict(keyword.keyword, **method.keyword) 318 | trans = dict(trans, **exception.keyword) 319 | trans = dict(trans, **zhpy.keyword) 320 | trans = dict(trans, **sys.keyword) 321 | trans = dict(trans, **trace.keyword) 322 | -------------------------------------------------------------------------------- /zhpy3/plugtw.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """Traditional Chinese keyword dictionaries 5 | 6 | This is the MIT license: 7 | http://www.opensource.org/licenses/mit-license.php 8 | 9 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to 13 | deal in the Software without restriction, including without limitation the 14 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | sell copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | """ 29 | 30 | 31 | from zhdc import ZhpyPlugin 32 | 33 | # Traditional chinese keywords 34 | class tw_keyword(ZhpyPlugin): 35 | """ 36 | python tw keyword 37 | """ 38 | title = "內建關鍵詞" 39 | description = "Python 內建關鍵詞" 40 | keyword = { 41 | # logic 42 | "和":"and", 43 | "且":"and", 44 | "或":"or", 45 | "真":"True", 46 | "假":"False", 47 | "實":"True", 48 | "虛":"False", 49 | "空":"None", 50 | # def 51 | "定義":"def", 52 | "類別":"class", 53 | "我":"self", 54 | "共用":"global", 55 | "全域":"global", 56 | # import 57 | "從":"from", 58 | "導入":"import", 59 | "作為":"as", 60 | # flow 61 | "返回":"return", 62 | "略過":"pass", 63 | "引發":"raise", 64 | "繼續":"continue", 65 | # control 66 | "如果":"if", 67 | "假使":"elif", 68 | "否則如果":"elif", 69 | "否則":"else", 70 | # for loop 71 | "取":"for", 72 | "自":"in", 73 | "在":"in", 74 | "不在":"not in", 75 | # while loop 76 | "當":"while", 77 | "跳出":"break", 78 | "中斷":"break", 79 | # try 80 | "嘗試":"try", 81 | "異常":"except", 82 | "最後":"finally", 83 | "申明":"assert", 84 | # build in methods 85 | "執行":"exec", 86 | "方程式":"lambda", 87 | "印出":"print", 88 | "伴隨":"with", 89 | "產生":"yield", 90 | } 91 | 92 | 93 | class tw_buildin_method(ZhpyPlugin): 94 | """ 95 | python tw methods 96 | """ 97 | title = "內部函數" 98 | description = "Python 內部函數" 99 | keyword = { 100 | "輸入":"input", 101 | # build-in types 102 | "字串":"str", 103 | "布林":"bool", 104 | "列表":"list", 105 | "字典":"dict", 106 | "元組":"tuple", 107 | "集合":"set", 108 | "定集合":"frozenset", 109 | "符號":"chr", 110 | "符號轉整數":"ord", 111 | "檔案":"file", 112 | # number methods 113 | "整數":"int", 114 | "浮點數":"float", 115 | "複數":"complex", 116 | "十六進位":"hex", 117 | "絕對值":"abs", 118 | "比較":"cmp", 119 | # string methods 120 | "開頭為":"startswith", 121 | "結尾為":"endswith", 122 | "連接":"join", 123 | "分離":"split", 124 | "代換":"replace", 125 | "編碼":"encoding", 126 | "解碼":"decoding", 127 | # list methods 128 | "加入":"append", 129 | "追加":"append", 130 | "擴展":"extend", 131 | "插入":"insert", 132 | "彈出":"pop", 133 | "下一筆":"next", 134 | "移除":"remove", 135 | "反轉":"reverse", 136 | "計數":"count", 137 | "索引":"index", 138 | "排序":"sort", 139 | # dict methods 140 | "鍵列表":"keys", 141 | "值列表":"values", 142 | "項目列表": "items", 143 | "更新":"update", 144 | "複製":"copy", 145 | # set methods 146 | "清除":"clear", 147 | "加":"add", 148 | "丟棄":"discard", 149 | "聯集":"union", 150 | "交集":"intersection", 151 | "差集":"difference", 152 | "對稱差集":"symmetric_difference", 153 | # file methods 154 | "打開":"open", 155 | "讀取":"read", 156 | "寫入":"write", 157 | "讀一行":"readline", 158 | "讀多行":"readlines", 159 | "關閉":"close", 160 | # OO 161 | "可調用":"callable", 162 | "列出屬性":"dir", 163 | "取屬性":"getattr", 164 | "有屬性":"hasattr", 165 | "設定屬性":"setattr", 166 | "屬性":"property", 167 | # build in functions 168 | "長度":"len", 169 | "最大值":"max", 170 | "最小值":"min", 171 | # build in methods 172 | "列舉":"enumerate", 173 | "評估":"eval", 174 | "過濾":"filter", 175 | "映射":"map", 176 | "範圍":"range", 177 | "快速範圍":"xrange", 178 | "總和":"sum", 179 | "型別":"type", 180 | "物件":"object", 181 | "打包":"zip", 182 | "說明":"help", 183 | "幫助":"help", 184 | "區域變量":"locals", 185 | "全域變量":"globals", 186 | "類別方法":"classmethod", 187 | } 188 | 189 | 190 | class tw_exception(ZhpyPlugin): 191 | """ 192 | python tw exceptions 193 | """ 194 | title = "例外" 195 | description = "Python 內建例外關鍵詞" 196 | keyword = { 197 | "例外":"Exception", 198 | "錯誤":"Error", 199 | # error 200 | "運算錯誤":"ArithmeticError", 201 | "申明錯誤":"AssertionError", 202 | "屬性錯誤":"AttributeError", 203 | "相容性警示":"DeprecationWarning", 204 | "空值錯誤":"EOFError", 205 | "環境錯誤":"EnvironmentError", 206 | "浮點數錯誤":"FloatingPointError", 207 | "輸出入錯誤":"IOError", 208 | "導入錯誤":"ImportError", 209 | "縮排錯誤":"IndentationError", 210 | "索引錯誤":"IndexError", 211 | "鍵錯誤":"KeyError", 212 | "鍵盤中斷":"KeyboardInterrupt", 213 | "查找錯誤":"LookupError", 214 | "記憶體錯誤":"MemoryError", 215 | "名稱錯誤":"NameError", 216 | "尚未實作":"NotImplemented", 217 | "尚未實作錯誤":"NotImplementedError", 218 | "作業系統錯誤":"OSError", 219 | "溢值錯誤":"OverflowError", 220 | "溢值警告":"OverflowWarning", 221 | "引用錯誤":"ReferenceError", 222 | "運行期錯誤":"RuntimeError", 223 | "運行期警告":"RuntimeWarning", 224 | "標準錯誤":"StandardError", 225 | "停止迭代":"StopIteration", 226 | "語法錯誤":"SyntaxError", 227 | "語法警告":"SyntaxWarning", 228 | "系統錯誤":"SystemError", 229 | "系統結束":"SystemExit", 230 | "型別錯誤":"TypeError", 231 | "跳格錯誤":"TabError", 232 | "未綁定區域變量錯誤":"UnboundLocalError", 233 | "萬國碼解碼錯誤":"UnicodeError", 234 | "自訂警告":"UserWarning", 235 | "值錯誤":"ValueError", 236 | "警告":"Warning", 237 | "Windows錯誤":"WindowsError", 238 | "除零錯誤":"ZeroDivisionError", 239 | "解碼錯誤":"UnicodeDecodeError", 240 | } 241 | 242 | 243 | class tw_zhpy(ZhpyPlugin): 244 | """ 245 | zhpy tw keyword plugin 246 | """ 247 | title = "周蟒" 248 | description = "周蟒內建關鍵詞" 249 | keyword = { 250 | "周蟒":"zhpy", 251 | "主程式":'if __name__=="__main__"', 252 | # must do 'from zhpy import zh_exec'/'從 周蟒 導入 中文執行' first 253 | "中文執行":"zh_exec", 254 | # logic 255 | "等於":"==", 256 | "不等於":"!=", 257 | "非":"not", 258 | "是":"is", 259 | "為":"is", 260 | "不是":"is not", 261 | "不為":"is not", 262 | # private 263 | "文件":"doc", 264 | "初始化":"init", 265 | "刪除":"del", 266 | "描述":"repr", 267 | "測試":"test", 268 | } 269 | 270 | #enter traditional chinese dict here 271 | class tw_sys(ZhpyPlugin): 272 | """ 273 | zhpy sys module traditional chinese plugin 274 | """ 275 | title = "系統" 276 | description = "系統模組" 277 | keyword = {"系統":"sys", 278 | "版本":"version", 279 | "參數":"argv", 280 | "結束":"exit", 281 | "取得檔案系統編碼":"getfilesystemencoding", 282 | "模組列表":"modules", 283 | "平台":"platform", 284 | "標準錯誤":"stderr", 285 | "標準輸入":"stdin", 286 | "標準輸出":"stdout", 287 | # sys path with list methods 288 | "路徑":"path", 289 | } 290 | 291 | class tw_traceback(ZhpyPlugin): 292 | """ 293 | zhpy traceback traditional chinese plugin 294 | """ 295 | title = "系統" 296 | description = "系統模組" 297 | keyword = {"未定義":"is not defined", 298 | "名稱":"name", 299 | "行":"line", 300 | "檔案":"File", 301 | "不合法的":"invalid", 302 | "語法":"syntax", 303 | } 304 | 305 | # [zhpy.twdict] 306 | keyword = tw_keyword() 307 | method = tw_buildin_method() 308 | exception = tw_exception() 309 | zhpy= tw_zhpy() 310 | sys = tw_sys() 311 | trace = tw_traceback() 312 | 313 | #tools = [twkeyword, twmethod, twexception, twzhpy, twsys] 314 | #trace = [twkeyword, twmethod, twexception, twtrace, twsys] 315 | trans = dict(keyword.keyword, **method.keyword) 316 | trans = dict(trans, **exception.keyword) 317 | trans = dict(trans, **zhpy.keyword) 318 | trans = dict(trans, **sys.keyword) 319 | trans = dict(trans, **trace.keyword) 320 | -------------------------------------------------------------------------------- /zhpy3/release.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | """Release information""" 4 | 5 | 6 | version = "3.0.0a1" 7 | author = "Fred Lin" 8 | email = "gasolin+zhpy@gmail.com" 9 | copyright = "Copyright 2007~ Fred Lin and contributors" 10 | license = "MIT " 11 | url = "http://zhpy.googlecode.com/" 12 | download_url="http://code.google.com/p/zhpy/" 13 | description="Write python(3) language in chinese" 14 | long_description = """ 15 | .. contents:: 16 | :depth: 2 17 | 18 | Introduction 19 | -------------- 20 | 21 | "If it walks like a duck and quacks like a duck, I would call it a duck." 22 | 23 | Zhpy3 on python 3 is good for non-native-english beginners to learn python 3 in our native language (Currently support Traditional and Simplified chinese). 24 | 25 | Zhpy3 acts like python 3 and play like python 3, user 26 | could use it as python 3 to educate yourself the program skills 27 | plus with your native language. 28 | 29 | Check examples here. 30 | 31 | * http://code.google.com/p/zhpy/source/browse/#hg%2Fzhpy3%2Fexamples 32 | 33 | Install 34 | ---------- 35 | 36 | If you'd like to play zhpy3 with full features, you should install zhpy3. 37 | 38 | You could use easy_install command to install or upgrade zhpy3:: 39 | 40 | $ easy_install -U zhpy3 41 | 42 | to use easy_install command, you should install distribute module for python 3 first: 43 | 44 | http://pypi.python.org/pypi/distribute/ 45 | 46 | And check your system path params if it contains python3.x/bin path. 47 | 48 | ex: edit .bashrc to include "/Library/Frameworks/Python.framework/Versions/3.x/bin" in your PATH parameter. 49 | 50 | What is Zhpy3 51 | --------------- 52 | 53 | Zhpy3 is the successor of zhpy, to provide the python 3 language translator with fully tested chinese keywords, variables, and parameters support. Zhpy is INDEPENDENT on python 3 versions(3.x….). 54 | 55 | The core of zhpy3 is a lightweight python module and a language 56 | source convertor based on python3, which provides 57 | command line tool to translate zhpy3 code to python 3. 58 | 59 | See http://www.flickr.com/photos/gasolin/2064120327 60 | 61 | You could invoke interpreter with 'twpy', 'cnpy' command instead of "python3" in command line to execute source code wrote in either Traditional/Simplified Chinese or English. 62 | 63 | The framework is not hard to extend to another languages such as japenese or korean. 64 | 65 | 66 | Change Log 67 | ------------- 68 | 69 | You could view the ChangeLog to see what's new in these version. 70 | 71 | * http://code.google.com/p/zhpy/source/browse/CHANGELOG.txt 72 | 73 | """ 74 | -------------------------------------------------------------------------------- /zhpy3/setup.py: -------------------------------------------------------------------------------- 1 | try: 2 | from setuptools import setup, find_packages 3 | except ImportError: 4 | from ez_setup import use_setuptools 5 | use_setuptools() 6 | from setuptools import setup, find_packages 7 | 8 | from pkg_resources import DistributionNotFound 9 | 10 | import sys 11 | import os 12 | import glob 13 | import release 14 | #execfile('release.py') 15 | 16 | # setup params 17 | required_modules = ["setuptools"] 18 | #if mac, install readline 19 | #if(sys.platform=="darwin"): 20 | # required_modules.append("readline >= 2.6.4") 21 | 22 | # nose is used for test 23 | extra_modules = {} 24 | 25 | setup( 26 | name="zhpy3", 27 | version=release.version, 28 | author=release.author, 29 | author_email=release.email, 30 | download_url=release.download_url, 31 | license=license, 32 | keywords = "traditional, simplified, chinese, language, tokenize", 33 | description=release.description, 34 | long_description=release.long_description, 35 | url=release.url, 36 | zip_safe=False, 37 | install_requires = required_modules, 38 | extras_require = extra_modules, 39 | include_package_data = True, 40 | packages=find_packages(exclude=["ez_setup", 'examples', 'apidocs', "tests"]), 41 | entry_points = """ 42 | [console_scripts] 43 | twpy = twpy:commandline 44 | cnpy = cnpy:commandline 45 | """, 46 | classifiers = [ 47 | 'Development Status :: 3 - Alpha', 48 | 'Environment :: Console', 49 | 'Intended Audience :: Education', 50 | 'Intended Audience :: Developers', 51 | 'Intended Audience :: System Administrators', 52 | 'License :: OSI Approved :: MIT License', 53 | 'Natural Language :: Chinese (Traditional)', 54 | 'Natural Language :: Chinese (Simplified)', 55 | 'Operating System :: OS Independent', 56 | 'Programming Language :: Python', 57 | 'Topic :: Software Development :: Libraries :: Python Modules', 58 | 'Topic :: Software Development :: Code Generators'], 59 | #test_suite = 'nose.collector', 60 | ) 61 | 62 | -------------------------------------------------------------------------------- /zhpy3/twpy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | import os 6 | import tokenize 7 | import plugtw 8 | import runpy 9 | from core import translate_code 10 | 11 | translations = plugtw.trans 12 | 13 | def commandline(): 14 | """zhpy3, the python language in Traditional Chinese 15 | 16 | usage: twpy file.twpy 17 | """ 18 | if len(sys.argv) != 2: 19 | print(commandline.__doc__) 20 | sys.exit(1) 21 | 22 | file_path = sys.argv[1] 23 | 24 | if not os.path.exists(file_path): 25 | print("twpy: file '%s' does not exists" % file_path) 26 | sys.exit(1) 27 | 28 | #sys.meta_path = [ImportHook()] 29 | 30 | sys.path[0] = os.path.dirname(os.path.join(os.getcwd(), file_path)) 31 | 32 | source = tokenize.untokenize( 33 | list(translate_code(open(file_path).readline, translations))) 34 | 35 | #translate_module(__builtins__) 36 | 37 | code = compile(source, file_path, "exec") 38 | 39 | runpy._run_module_code(code, mod_name="__main__") 40 | 41 | if __name__=="__main__": 42 | commandline() -------------------------------------------------------------------------------- /zhpy3/zhdc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | """zhpy keywords convertion library 5 | 6 | This is the MIT license: 7 | http://www.opensource.org/licenses/mit-license.php 8 | 9 | Copyright (c) 2007~ Fred Lin and contributors. zhpy is a trademark of Fred Lin. 10 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to 13 | deal in the Software without restriction, including without limitation the 14 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 15 | sell copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | 18 | The above copyright notice and this permission notice shall be included in 19 | all copies or substantial portions of the Software. 20 | 21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 27 | THE SOFTWARE. 28 | """ 29 | 30 | 31 | # Universal keywords repository 32 | #: always run annotator before access worddict 33 | worddict = {} 34 | #: Traditional Chinese keywords repository 35 | twdict = {} 36 | #: Simplified Chinese keywords repository 37 | cndict = {} 38 | 39 | class ZhpyPlugin(object): 40 | """ 41 | basic plugin class 42 | """ 43 | pass 44 | 45 | 46 | def revert_dict(lang_dict): 47 | """make a reverse dictionary from the input dictionary 48 | 49 | >>> revert_dict({'a':'1', 'b':'2'}) 50 | {'1': 'a', '2': 'b'} 51 | """ 52 | rev_dict = {} 53 | dict_keys = lang_dict.keys() 54 | dict_keys.reverse() 55 | #map(rev_dict.update, map(lambda i: {lang_dict[i]:i}, dict_keys)) 56 | for i in dict_keys: 57 | rev_dict.update({lang_dict[i]:i}) 58 | return rev_dict 59 | --------------------------------------------------------------------------------