[TurboGears] master.kidをいじると、"TypeError: 'NoneType' object is not callable"が発生する、ことがある。その2
環境
この現象は、TurboGears 1.0.1で確認しました。
はじめに
この記事は、id:SumiTomohiko:20070214:1171449131の続きです。そこで取り上げられている問題が再発しました。
現象
id:SumiTomohiko:20070214:1171449131の現象と同じです。
原因
やはり、分かりません。
対策
これまで、master.kidを参照するテンプレートでは、
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'car/templates/master.kid'">
というように、カレントディレクトリからの相対パスで指定していました。これを、テンプレートからの相対パスで指定するようにしました。例えば、car/template/article/list/index.kidだと、
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="'../../master.kid'">
としました。
この上で、次のRubyスクリプトで、エラーが発生しないか、検査しました(前の記事のスクリプトは間違いで、期待通りに動作しません)。
# ruby require "open-uri" url = [ "/article/edit/", "/article/search/", "/article/list/", "/article/show/?id=1"] count = 0 error_url = [] 1000.times do begin address = nil url.each do |s| address = "http://127.0.0.1:8080#{s}" open(address) end rescue error_url.push(address) count += 1 end end puts error_url puts count # vim: tabstop=2 shiftwidth=2 expandtab
これを実行した結果、エラーの発生回数は0回でした。
もしかしたらブラウザから送信されるヘッダなども関係しているのではないかと思い、LiveHTTPHeadersでFirefoxが送信しているヘッダを調べ、それをwgetに設定してリクエストを送信する実験もやってみました。以下が、そのスクリプトです。
# ruby url = [ "/article/edit/", "/article/search/", "/article/list/", "/article/show/?id=1"] count = 0 error_command = [] 1000.times do url.each do |s| command = "/usr/bin/wget --user-agent=\"User-Agent: Mozilla/5.0 (X11; U; Linux i686; ja; rv:1.8.1.1) Gecko/20060601 Firefox/2.0.0.1 (Ubuntu-edgy)\" --referer=\"Referer: http://127.0.0.1:8080/article/list/\" --header=\"Host: 127.0.0.1:8080\" --header=\"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\" --header=\"Accept-Language: ja,en-us;q=0.7,en;q=0.3\" --header=\"Accept-Encoding: gzip,deflate\" --header=\"Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\" --header=\"Keep-Alive: 300\" --header=\"Connection: keep-alive\" --header=\"Cookie: session_id=60eb30419bdb808382d4a47829b70e3905845391\" http://127.0.0.1:8080#{s} > /dev/null 2>&1" `#{command}` if $? >> 8 != 0 error_command.push(command) count += 1 end end end puts error_command puts count # vim: tabstop=2 shiftwidth=2 expandtab
こちらも、エラーの発生回数は0でした。