2 # $Id: Servlet.py,v 1.40 2006/02/04 23:06:15 tavis_rudd Exp $
3 """Provides an abstract Servlet baseclass for Cheetah's Template class
6 ================================================================================
7 Author: Tavis Rudd <tavis@damnsimple.com>
8 License: This software is released for unlimited distribution under the
9 terms of the MIT license. See the LICENSE file.
10 Version: $Revision: 1.40 $
11 Start Date: 2001/10/03
12 Last Revision Date: $Date: 2006/02/04 23:06:15 $
14 __author__
= "Tavis Rudd <tavis@damnsimple.com>"
15 __revision__
= "$Revision: 1.40 $"[11:-2]
20 isWebwareInstalled
= False
22 if 'ds.appserver' in sys
.modules
.keys():
23 from ds
.appserver
.Servlet
import Servlet
as BaseServlet
25 from WebKit
.Servlet
import Servlet
as BaseServlet
26 isWebwareInstalled
= True
28 if not issubclass(BaseServlet
, object):
29 class NewStyleBaseServlet(BaseServlet
, object): pass
30 BaseServlet
= NewStyleBaseServlet
32 class BaseServlet(object):
39 def awake(self
, transaction
):
42 def sleep(self
, transaction
):
48 ##################################################
51 class Servlet(BaseServlet
):
53 """This class is an abstract baseclass for Cheetah.Template.Template.
55 It wraps WebKit.Servlet and provides a few extra convenience methods that
56 are also found in WebKit.Page. It doesn't do any of the HTTP method
57 resolution that is done in WebKit.HTTPServlet
66 BaseServlet
.__init
__(self
)
68 # this default will be changed by the .awake() method
69 self
._CHEETAH
__isControlledByWebKit
= False
71 ## methods called by Webware during the request-response
73 def awake(self
, transaction
):
74 BaseServlet
.awake(self
, transaction
)
76 # a hack to signify that the servlet is being run directly from WebKit
77 self
._CHEETAH
__isControlledByWebKit
= True
79 self
.transaction
= transaction
80 #self.application = transaction.application
81 self
.response
= response
= transaction
.response
82 self
.request
= transaction
.request
84 # Temporary hack to accomodate bug in
85 # WebKit.Servlet.Servlet.serverSidePath: it uses
86 # self._request even though this attribute does not exist.
87 # This attribute WILL disappear in the future.
88 self
._request
= transaction
.request()
91 self
.session
= transaction
.session
92 self
.write
= response().write
93 #self.writeln = response.writeln
95 def respond(self
, trans
=None):
96 raise NotImplementedError("""\
97 couldn't find the template's main method. If you are using #extends
98 without #implements, try adding '#implements respond' to your template
101 def sleep(self
, transaction
):
102 BaseServlet
.sleep(self
, transaction
)
107 self
.transaction
= None
112 def serverSidePath(self
, path
=None,
113 normpath
=os
.path
.normpath
,
114 abspath
=os
.path
.abspath
117 if self
._CHEETAH
__isControlledByWebKit
:
118 return BaseServlet
.serverSidePath(self
, path
)
120 return normpath(abspath(path
.replace("\\",'/')))
121 elif hasattr(self
, '_filePath') and self
._filePath
:
122 return normpath(abspath(self
._filePath
))
126 # vim: shiftwidth=4 tabstop=4 expandtab