Plan9のwebfsで遊んでみよう
cookieはwebcookieで管理します。
cpu% webcookies cpu% ls -l lib -lrw-rw-r-- M 4291 jun jun 0 Feb 16 16:25 lib/L.webcookies --rw-r--r-- M 4291 jun jun 0 Feb 16 16:24 lib/newstime --rw-rw-r-- M 4291 jun jun 72 Feb 16 16:25 lib/webcookies
webfsを起動します
cpu% webfs cpu% ls -l /mnt/web --rw-rw-rw- M 4303 web web 0 Feb 16 16:27 /mnt/web/clone --rw-rw-rw- M 4303 web web 0 Feb 16 16:27 /mnt/web/cookies --rw-rw-rw- M 4303 web web 0 Feb 16 16:27 /mnt/web/ctl
/mnt/web/ctlで全体の設定コントロールします。試しに読み込んでみましょう
cpu% cat /mnt/web/ctl chatty9p 0 fsdebug 0 cookiedebug 0 urldebug 0 httpdebug 0 acceptcookies on sendcookies on redirectlimit 10 useragent webfs/2.0 (plan 9)
使うには、/mnt/web/cloneをopenします。こんなプログラムを書いてみました。
cpu% cat web.py
import sys
web = open("/mnt/web/clone","rw")
t=web.read()
print t
web.close()
開いて読み込んでみるだけです。実行してみます。
cpu% python web.py
0
acceptcookies on
sendcookies on
redirectlimit 10
useragent webfs/2.0 (plan 9)
/mnt/webがどうなってるか見てみます
cpu% ls /mnt/web /mnt/web/0 /mnt/web/clone /mnt/web/cookies /mnt/web/ctl cpu% ls -l /mnt/web/0 --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/body --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/body.xxx --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/contenttype --rw-rw-rw- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/ctl d-r-xr-xr-x M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed --rw-rw-rw- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/postbody cpu% ls -l /mnt/web/0/parsed --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/fragment --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/ftptype --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/host --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/passwd --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/path --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/port --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/query --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/scheme --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/schemedata --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/url --r--r--r-- M 4303 web web 0 Feb 16 16:27 /mnt/web/0/parsed/user
では、ファイルを取ってきてみましょう。
cpu% cat web.py
import sys
import os
web = open("/mnt/web/clone","rw")
t=web.readlines()
id=int(t[0])
base=os.path.join("/mnt/web/%d" % id)
ctlfd=open(os.path.join(base,"ctl"),"w")
ctlfd.write("url http://www.moroo.com/index.html")
ctlfd.flush()
bodyfd=open(os.path.join(base,"body"),"r")
t=bodyfd.read(),
print t
web.close()
cpu% python web.py
('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">\n<html lang="ja">\n<head>\n<LINK rev="MADE" HREF="mailto:jun@moroo.com">\n
<LINK rel="INDEX" href="./index.html">\n<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-2022-JP">\n<title>Moroo.com</title>\n
</head>\n\n<body>\n<h1>Moroo.com</h1>\n\n<table summary="Contents">\n <tr>\n <td>\n
\t<a href="mail.html">\x1b$B%a!<%k%"%I%l%9>e$2$^$9\x1b(B</a>\n </td>\n </tr>\n <tr>\n <td>\n
\t<a href="http://www.moroo.com/jun/">\x1b$B=a\x1b(B</a>\n </td>\n </tr>\n <tr>\n <td>\n
\t<a href="http://www.moroo.org/">moroo.org\x1b$B<h$j$^$7$?!#\x1b(B</a>\n </td>\n </tr>\n</table>\n<hr>\n
<address><a href="mailto:jun@moroo.com">jun@moroo.com</a></address>\n<!-- hhmts start -->\nLast modified: 2002/9/29 9:58:55 PM \n
<!-- hhmts end -->\n</body>\n</html>\n',)