ãã£ãã¨å¿ãã¦ãããã
ãCatyã¹ã¯ãªããï¼ã¾ã åºæ¥ã¦ãªããã©ãã¥ã¼ããªã¢ã«ãï¼
ã½ããã¦ã§ã¢ãå ¬éãã¦ãªãä»ã®æ®µéã§è§£èª¬ãæ¸ãã¦ããå®æããªãã¦ããã³ãã¤ã§ãããããå¾ã§ã¾ã¨ãã¦æ¸ããã¨ãè² æ ãªã®ã§ãæ¸ãããã¨ã¯æ¸ãã¦ãããã¨ã«ãã¾ãã
ä¸å¿ã½ããã¦ã§ã¢ãå ¬éããã®ã§ãåãå®ç©ãå¼ç¨ãã¦èª¬æã§ããã®ã ã£ãã
Caty/Python Prototype-1 version 0.1.1 ãã¤ã³ã¹ãã¼ã«ãã¦ãcaty.py ãå®è¡ãã¦ãã ãããcaty.pyã¯Catyã¹ã¯ãªããã®ã³ãã³ãã©ã¤ã³ã»ã¤ã³ã¿ããªã¿ãèµ·åãã¾ãã以ä¸ã§ã¯ãå®éã®æä½ä¾ã§èª¬æãã¾ããåºæ¬çæ¦å¿µã¯ãCatyã¹ã¯ãªããï¼ã¾ã åºæ¥ã¦ãªããã©ãã¥ã¼ããªã¢ã«ããåç §ãã¦ãã ããã
å 容ï¼
- JSONãã¼ã¿ã¯ãã®ã¾ã¾ä½¿ããã
- ã³ãã³ããå®è¡ãã¦ã¿ãã
- ã³ãã³ãããã¤ãã©ã¤ã³ã§ã¤ãªãã§ã¿ã
- ã³ãã³ããä½ã£ã¦ã¿ãã
- ãããªã³ãã³ããããã¾ã
JSONãã¼ã¿ã¯ãã®ã¾ã¾ä½¿ããã
ãã¹ã¦ã®JSONãã¼ã¿ã¯ãCatyã¹ã¯ãªããã®ãªãã©ã«ã«ãªã£ã¦ãã¾ããä¾ãã°ã次ã®ãã¼ã¿ã¯ãã®ã¾ã¾Catyã¹ã¯ãªããã®å¼ã§ãã
- 3.14
- "hello"
- [3.14, "hello"]
- {"PI":3.14, "greeting":"hello"}
ãªãã©ã«ãè©ä¾¡ããå¤ã¯ããèªèº«ã«ãªãã®ã§ãããã³ããã«å¯¾ãã¦JSONãã¼ã¿ãæã¡è¾¼ãã¨ã¨ã³ã¼ããã¾ãããã ãããã¼å ¥åããæååããã®ã¾ã¾ã¨ã³ã¼ãããã®ã§ã¯ãªãã¦ãå¼ãè©ä¾¡ããçµæãããªãã£ããªã³ããããã®ã§ãã
caty> 3.14
3.14
caty> "hello"
"hello"
caty> [3.14, "hello"]
[3.14, "hello"]
caty> {"PI":3.14, "greeting":"hello"}
{
"PI":3.14,
"greeting":"hello"
}caty>
ãã¼å ¥åã®éä¸ã§æ¹è¡ãã¼*1ãæã¤ã¨ãè¡ã®ç¶ç¶ãã§ãã¾ããï¼åã¯é·ãã¦ã1è¡ã§æ¸ãã¡ãã人ã ãã©ãï¼
caty> [
> 3.14,
> "hello"]
[3.14, "hello"]
caty>
ç´ç²ãªJSONã«æ¯ã¹ã¦æ¬¡ã®ç¹ã便å©ï¼ãããã¯ä¸ç´ï¼ã«ãªã£ã¦ãã¾ã*2ã
- /* ... */ 㨠// ... ã§ã³ã¡ã³ããå ¥ããããã
- é åããªãã¸ã§ã¯ãã®æå¾ã«ä½åãªã³ã³ããå ¥ãã¦ãã¨ã©ã¼ã«ãªããªãã
caty> { // start object
> "PI": /* åå¨ç */ 3.14,
> "greeting": "hello", // æ¨æ¶
> // ä½åãªã³ã³ããããã
> }
{
"PI":3.14,
"greeting":"hello"
}caty>
ã³ãã³ããå®è¡ãã¦ã¿ãã
hello, helloJaã¨ãããã決ã¾ãã®ã¤ã¾ããªãã³ãã³ããããã¾ãã
caty> hello
"hello"
caty> helloJa
"ããã«ã¡ã¯"
caty>
ã³ãã³ãã®ã½ã¼ã¹ã¯ãCATY_HOME/webapp/commands/ ã®ä¸ã«ããã¾ãã
# command hello :: void -> string class Hello(Command): def execute(self, opts): self.output = 'hello' # command helloJa :: void -> string class HelloJa(Command): def execute(self, opts): self.output = u"ããã«ã¡ã¯"
ç°¡åãªPythonã³ã¼ãã§ãããCatyã·ã§ã«ï¼caty.pyï¼ã¯ãã³ãã³ãã®ååãä»æ§ãå®è£ ãç¥ãããã«ãCATY_HOME/webapp/schema/ ã®ä¸*3ã«ããã¹ãã¼ãã¢ã¸ã¥ã¼ã«ï¼æ¡å¼µå".casm"ã®ãã¡ã¤ã«ï¼ãèªã¿ã¾ããhelloã¨helloJaã¯ãããããCATY_HOME/webapp/schema/util.casm 㨠CATY_HOME/webapp/schema/public.casm ã§å®£è¨ããã¦ãã¾ããå¥ã ãªãã¡ã¤ã«ã§å®£è¨ããã¦ãããã¨ã«æå³ã¯ããã¾ããï¼ãã¾ãã¾ãããªã£ã¦ããã ãï¼ã
command hello :: void -> string
refers python:util.Hello;
command helloJa :: void -> string
refers python:util.HelloJa;
宣è¨ã追å ã»å¤æ´ããã°ãåãã³ãã³ãï¼åä¸ã®å®è£ ãæã¤ã³ãã³ãï¼ãå¥ãªååã§å¼ã¶ãã¨ãã§ãã¾ããä¾ãã°ï¼
command kon-nichiwa :: void -> string
refers python:util.HelloJa;
ã³ãã³ãã®ã½ã¼ã¹ã宣è¨ã追å ã»å¤æ´ããã¨ãã¯caty.pyã®åèµ·åãå¿ è¦ã§ã*4ã
caty> kon-nichiwa
"ããã«ã¡ã¯"
caty>
version 0.1.1ã§ã¯ãã³ãã³ããã©ã®ã¹ãã¼ãã¢ã¸ã¥ã¼ã«ã§å®£è¨ãã¦ãå¹æã¯åããªãã§ãããããã¯å¤æ´ããã¾ããpublic.casm以å¤ã§å®£è¨ãããã³ãã³ãã¯ãã¢ã¸ã¥ã¼ã«åã§ä¿®é£¾ããªãã¨å¼ã¹ãªããªãã¾ããutil.casm ã§å®£è¨ãããhelloã¯ãutil:hello ã¨ããå½¢ã«ãªãã¾ãã
å®æ°ãæ¸ããã¨ããã«ã¯ã³ãã³ãå¼ã³åºããæ¸ããã®ã§ãã³ãã³ãã®åºåããJSONãã¼ã¿ãçµã¿ç«ã¦ããã¨ãã§ãã¾ãã
caty> [hello, helloJa]
["hello", "ããã«ã¡ã¯"]
caty> {"en":hello, "ja":helloJa}
{
"en":"hello",
"ja":"ããã«ã¡ã¯"
}caty> {"en":hello, "ja":helloJa, "en-ja":[hello, helloJa]}
{
"en":"hello",
"en-ja":["hello", "ããã«ã¡ã¯"],
"ja":"ããã«ã¡ã¯"
}caty>
ã³ãã³ãããã¤ãã©ã¤ã³ã§ã¤ãªãã§ã¿ã
æååã®å¤§æååtoupperã¨ãå°æååtolowerã¨ããã³ãã³ããããã¾ãããããã使ã£ã¦ãã¤ãã©ã¤ã³ã試ãã¦ã¿ã¾ãããã
caty> hello | toupper
"HELLO"
caty> hello | tolower
"hello"
caty> "HelloWorld" | [toupper, tolower]
["HELLOWORLD", "helloworld"]
caty>
ã³ãã³ãã®é åã«å¯¾ãã¦ã¯ãå ¥åãé ç®ï¼itemï¼åã ãã³ãã¼ããã¦æ¸¡ããã¾ããã³ãã³ãããªãã¸ã§ã¯ãã®ããããã£ã«ãªã£ã¦ããã¨ããåãã§ãã以ä¸ã§ãpassã¯ä½ãããªãã³ãã³ãã§ãã
caty> "HelloWorld" | {"orig":pass, "upper":toupper, "lower":tolower}
{
"lower":"helloworld",
"orig":"HelloWorld",
"upper":"HELLOWORLD"
}caty>
é åã®içªç®ãåãåºãã«ã¯ãnth i ã¨ããã³ãã³ãããªãã¸ã§ã¯ãã®pã¨ããååã®ããããã£ãåãåºãã«ã¯ getpv p ã¨ããã³ãã³ãã使ãã¾ãã
caty> [0, 1, 2] | nth 0
0
caty> [0, 1, 2] | nth 2
2
caty> {"a":"first", "b":"second"} | getpv a
"first"
caty> {"a":"first", "b":"second"} | getpv b
"second"
caty> {"a":["first-0", "first-1"], "b":"second"} | getpv a | nth 1
"first-1"
caty>
ãããã®åºæ¬ã³ãã³ãããcommands/util.pyã§ã¨ããããå®ç¾©ããã ãã®ã¢ããªã®ã§ãä»æ§å¤æ´ãããããããã¾ãã*5ã
ãã¤ãã©ã¤ã³ã¯ãããã§ãã¤ãªãããã¾ãã
caty> hello | [toupper, tolower] | [nth 1, nth 0]
["hello", "HELLO"]
caty> "HelloWorld" | toupper | {"a": pass, "b":tolower}
{
"a":"HELLOWORLD",
"b":"helloworld"
}caty>
ã³ãã³ããä½ã£ã¦ã¿ãã
ãCatyã¹ã¯ãªããï¼ã¾ã åºæ¥ã¦ãªããã©ãã¥ã¼ããªã¢ã«ãã«ï¼
todayã¨ããã³ãã³ãã¯ã次ã®ãããªåã®ãã¼ã¿ãè¿ãã¾ãã
object {
"year" : integer,
"month" : integer,
"day" : integer
}
å®éãtodayã¨ããã³ãã³ããããã¾ãããããããã£ãintegerãããªãã¦stringã®ãªãã¸ã§ã¯ããåºåãã¾ãã
caty> today
{
"day":"08",
"month":"10",
"year":"2009"
}caty>
ãªããtodayã¯ã·ã§ã«ã®çµã¿è¾¼ã¿ã³ãã³ãã«ãªã£ã¦ãã¾ãï¼æ¬¡ã®ãªãªã¼ã¹ã§ã¯çµã¿è¾¼ã¿ããå¤ããã¾ãï¼ãtodayã³ãã³ãã®ã½ã¼ã¹ã¯ CATY_HOME/python/caty/shell/script/builtin.py ã«ããã¾ãããããåèã«ã以åã®èª¬æã©ãããintegerãããªããªãã¸ã§ã¯ããåºåããã³ãã³ããä½ã£ã¦ã¿ã¾ãããã
ã¦ã¼ã¶ã¼å®ç¾©ã®ã³ãã³ã㯠CATY_HOME/webapp/commands/ ã®ä¸ã«ããã¾ããCATY_HOME/webapp/commands/mycmd.py ã¨ãããã¡ã¤ã«ãä½ã£ã¦æ¬¡ã®å 容ã«ãã¾ãã
# -*- coding: utf-8 -*- # mycmd.py from caty.shell.script import Command import datetime class Today(Command): def execute(self, opts): n = datetime.datetime.now() y = n.year m = n.month d = n.day self.output = {'year': y, 'month': m, 'day': d}
ããã§ã³ãã³ãå®è£ ã¯åºæ¥ä¸ããã§ããããããã³ãã³ãã¯ã©ããªååã§ã©ããªå¼æ°ã渡ãã¹ãããªã©ã®æ å ±ãå¥ã«å¿ è¦ãªã®ã§ãCATY_HOME/webapp/schema/mycmd.casm ã«æ¬¡ã®ããã«æ¸ãã¦ãã ããã
/* mycmd.casm */type YMD = object {
"year" : integer,
"month" : integer,
"day" : integer
};command mytoday :: void -> YMD
refers python:mycmd.Today;
Catyã·ã§ã«ãåèµ·åããã¨ãå®ç¾©ããã³ãã³ããæå¹ã«ãªãã¾ãã
caty> mytoday
{
"day":8,
"month":10,
"year":2009
}caty>
ãªãã次ã®ãªã¼ãªã¹ã§ã¯ãmycmd:mytoday ã¨ãã¦ã³ãã³ããæå®ããå¿ è¦ãããã¾ããã¢ã¸ã¥ã¼ã«åmycmdã§ä¿®é£¾ããã®ãã¤ã¤ãªãã°ãpublic.casmã«ã³ãã³ã宣è¨ãæ¸ãã¾ããpublic.casmã§å®£è¨ãããã³ãã³ãã¯ä¿®é£¾ãªãã®ååãæã¡ã¾ãã
ãããªã³ãã³ããããã¾ã
æå¾ã«ãCatyã·ã¹ãã ã管çããã³ãã³ããã²ã¨ã¤ç´¹ä»ãã¦ããã¾ããçµã¿è¾¼ã¿ã³ãã³ãadduserã§ããadduserã¯ãã³ãã³ãã©ã¤ã³ãã3ã¤ã®å¼æ°ãåããã¨ãã§ãã¾ãããWebããã³ãã³ããå®è¡ããã¨ãã«ã©ãããããè¦ãããã«ãæ¨æºå
¥åï¼inputï¼ããå¿
è¦ãªãã¼ã¿ãæµãè¾¼ãã§ã¿ã¾ããæµãè¾¼ãJSONãã¼ã¿ã¯ã {"username":"hiyama", "grant":"admin", "password": "foobar"}
ã§ãã
caty> {"username":"hiyama", "grant":"admin",
> "password":"foobar"} | adduser
true
caty>
ããã§ã管çè ï¼adminï¼æ¨©éãæã£ãhiyamaã¨ããã¦ã¼ã¶ã¼ã追å ããã¾ãããã¦ã¼ã¶ã¼æ å ±ã®å®ä½ã¯ CATY_HOME/webapp/admin/users.json ã«ããã¾ãï¼å ´æã¨ãã¡ã¤ã«åã¯å¤æ´ãããããããã¾ããï¼ã
HTMLãã©ã¼ã ã«ããPOSTãã¼ã¿ã¯ãCatyã¸ã®å ¥ãå£ã§JSONãã¼ã¿ã«å¤æãããã³ãã³ãã»ãã¤ãã©ã¤ã³ã«æµãããä»æãã«ãªã£ã¦ãã¾ããã·ã§ã«ãã³ãã³ãã¯ãã³ãã³ãã©ã¤ã³ããã¼ãã¼ãããæ¥ãã®ãWebããæ¥ãã®ãåºå¥ã§ãã¾ããããããã£ã¦ãWebããåºæ¥ããã¨ã¯ãã¹ã¦ãã¼ãã¼ããããã§ãã¾ãï¼éã¯æç«ãã¾ããï¼ï¼ãã³ãã³ãã©ã¤ã³ã®å®è¡çµæãå¤ã«åºã¦ããã¨ãã¯ãé常ãã³ãã¬ã¼ãã«ããæ´å½¢ããã¾ãããã³ãã¬ã¼ãã¨ã³ã¸ã³ã¯ã·ã§ã«ã«å èµããã¦ãã¾ã -- Catyã¯ãæ§é çã«ã¯å¯¾è©±çè¨èªå¦çç³»ãç¨éãWebãã¬ã¼ã ã¯ã¼ã¯ãã¨ã¯ãããããæå³ã§ãã
*1:Enter以å¤ã«ãCtrl+M ã§ãããã¯ãã§ãããWindowsã§ã¯readlineããã°ã£ã¦ããããã§ãã
*2:次ã®ãªãªã¼ã¹ã§å ¥ãã¿ã®ã³ã°æ¼ç®åãå«ããã¨ããªãã©ã«æ§æã¨ãã¦ãã ãã¶è¯ããã
*3:次ã®ãªãªã¼ã¹ã§ã¯è¤æ°å½¢ schemata/ ã«ãªãäºå®ã
*4:ãã®ãã¡ãreloadã³ãã³ãããµãã¼ããããã§ãããã
*5:nthã¯çªå·ã1ããã«ãã¦ãå¥ã«itemãè¨ããããã¨æã£ã¦ãã¾ããããã¨ãgetpvã¯é »ç¹ã«ä½¿ãã㧠pv ã«ããããã¨ã