root/galaxy-central/eggs/Cheetah-2.2.2-py2.6-macosx-10.6-universal-ucs2.egg/Cheetah/Tools/CGITemplate.py @ 3

リビジョン 3, 2.2 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1# $Id: CGITemplate.py,v 1.6 2006/01/29 02:09:59 tavis_rudd Exp $
2"""A subclass of Cheetah.Template for use in CGI scripts.
3
4Usage in a template:
5    #extends Cheetah.Tools.CGITemplate
6    #implements respond
7    $cgiHeaders#slurp
8
9Usage in a template inheriting a Python class:
101. The template
11    #extends MyPythonClass
12    #implements respond
13    $cgiHeaders#slurp
14
152. The Python class
16    from Cheetah.Tools import CGITemplate
17    class MyPythonClass(CGITemplate):
18        def cgiHeadersHook(self):
19            return "Content-Type: text/html; charset=koi8-r\n\n"
20
21To read GET/POST variables, use the .webInput method defined in
22Cheetah.Utils.WebInputMixin (available in all templates without importing
23anything), use Python's 'cgi' module, or make your own arrangements.
24
25This class inherits from Cheetah.Template to make it usable in Cheetah's
26single-inheritance model. 
27
28
29Meta-Data
30================================================================================
31Author: Mike Orr <iron@mso.oz.net>
32License: This software is released for unlimited distribution under the
33         terms of the MIT license.  See the LICENSE file.
34Version: $Revision: 1.6 $
35Start Date: 2001/10/03
36Last Revision Date: $Date: 2006/01/29 02:09:59 $
37"""
38__author__ = "Mike Orr <iron@mso.oz.net>"
39__revision__ = "$Revision: 1.6 $"[11:-2]
40
41import os
42from Cheetah.Template import Template
43
44class CGITemplate(Template):
45    """Methods useful in CGI scripts.
46
47       Any class that inherits this mixin must also inherit Cheetah.Servlet.
48    """
49   
50
51    def cgiHeaders(self):
52        """Outputs the CGI headers if this is a CGI script.
53
54           Usage:  $cgiHeaders#slurp
55           Override .cgiHeadersHook() if you want to customize the headers.
56        """
57        if self.isCgi():
58            return self.cgiHeadersHook()
59
60
61
62    def cgiHeadersHook(self):
63        """Override if you want to customize the CGI headers.
64        """
65        return "Content-type: text/html\n\n"
66
67
68    def isCgi(self):
69        """Is this a CGI script?
70        """
71        env = os.environ.has_key('REQUEST_METHOD')
72        wk = self._CHEETAH__isControlledByWebKit
73        return env and not wk
74
75
76   
77# vim: shiftwidth=4 tabstop=4 expandtab
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。