Using Routes with TurboGears

http://trac.turbogears.org/turbogears/wiki/RoutesIntegration

いわゆる RESTful とか PrettyURL ってやつですか。現状はこんな風に強引にやってるんですけど、もっとフレキシブルに書けるようになるみたい。TurboGears 1.0までには公式に取り込んでくれるといいなぁ。

class UsersDir():
    @expose()
    def default(self, *args, **fields):
        try:
            # 要求されたユーザーが存在するか確認
            user = User.by_user_name(args[0])
            # 動的にディレクトリオブジェクトを生成
            setattr(self, user.user_name, UserDir(user))
            raise cherrypy.InternalRedirect(cherrypy.request.path)
        except SQLObjectNotFound:
            raise cherrypy.NotFound

今気付いたけど、この方法はユーザー数が増えてくるとメモリ消費がヤバいことになりそう。