Kill mmpeg on linux
[pyTivo/krkeegan.git] / Cheetah / Servlet.py
blob5295d30cf80d0093a131c6f5c36fd2e057e41565
1 #!/usr/bin/env python
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
5 Meta-Data
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 $
13 """
14 __author__ = "Tavis Rudd <tavis@damnsimple.com>"
15 __revision__ = "$Revision: 1.40 $"[11:-2]
17 import sys
18 import os.path
20 isWebwareInstalled = False
21 try:
22 if 'ds.appserver' in sys.modules.keys():
23 from ds.appserver.Servlet import Servlet as BaseServlet
24 else:
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
31 except:
32 class BaseServlet(object):
33 _reusable = 1
34 _threadSafe = 0
36 def __init__(self):
37 pass
39 def awake(self, transaction):
40 pass
42 def sleep(self, transaction):
43 pass
45 def shutdown(self):
46 pass
48 ##################################################
49 ## CLASSES
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
58 """
60 transaction = None
61 application = None
62 request = None
63 session = None
65 def __init__(self):
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
99 definition.""")
101 def sleep(self, transaction):
102 BaseServlet.sleep(self, transaction)
103 self.session = None
104 self.request = None
105 self._request = None
106 self.response = None
107 self.transaction = None
109 def shutdown(self):
110 pass
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)
119 elif path:
120 return normpath(abspath(path.replace("\\",'/')))
121 elif hasattr(self, '_filePath') and self._filePath:
122 return normpath(abspath(self._filePath))
123 else:
124 return None
126 # vim: shiftwidth=4 tabstop=4 expandtab