Skip to content

Commit

Permalink
Gut the old WebWare-servlet code from Cheetah.Servlet
Browse files Browse the repository at this point in the history
Apparently the attempted import might be to blame for some
slowness when importing on Mac OS X which has a (large-ish)
WebKit python module available.
  • Loading branch information
R. Tyler Ballance committed Jan 28, 2010
1 parent 5d93154 commit 0eead16
Showing 1 changed file with 8 additions and 72 deletions.
80 changes: 8 additions & 72 deletions cheetah/Servlet.py
@@ -1,83 +1,21 @@
#!/usr/bin/env python
'''
Provides an abstract Servlet baseclass for Cheetah's Template class
'''

import sys
import os.path

isWebwareInstalled = False
try:
try:
from ds.appserver.Servlet import Servlet as BaseServlet
except:
from WebKit.Servlet import Servlet as BaseServlet
isWebwareInstalled = True

if not issubclass(BaseServlet, object):
class NewStyleBaseServlet(BaseServlet, object):
pass
BaseServlet = NewStyleBaseServlet
except:
class BaseServlet(object):
_reusable = 1
_threadSafe = 0

def awake(self, transaction):
pass

def sleep(self, transaction):
pass

def shutdown(self):
pass

##################################################
## CLASSES

class Servlet(BaseServlet):

"""This class is an abstract baseclass for Cheetah.Template.Template.
It wraps WebKit.Servlet and provides a few extra convenience methods that
are also found in WebKit.Page. It doesn't do any of the HTTP method
resolution that is done in WebKit.HTTPServlet
class Servlet(object):
"""

This class is an abstract baseclass for Cheetah.Template.Template.
"""

transaction = None
application = None
request = None
session = None

def __init__(self, *args, **kwargs):
super(Servlet, self).__init__(*args, **kwargs)

# this default will be changed by the .awake() method
self._CHEETAH__isControlledByWebKit = False

## methods called by Webware during the request-response

def awake(self, transaction):
super(Servlet, self).awake(transaction)

# a hack to signify that the servlet is being run directly from WebKit
self._CHEETAH__isControlledByWebKit = True

self.transaction = transaction
#self.application = transaction.application
self.response = response = transaction.response
self.request = transaction.request

# Temporary hack to accomodate bug in
# WebKit.Servlet.Servlet.serverSidePath: it uses
# self._request even though this attribute does not exist.
# This attribute WILL disappear in the future.
self._request = transaction.request()


self.session = transaction.session
self.write = response().write
#self.writeln = response.writeln

def respond(self, trans=None):
raise NotImplementedError("""\
couldn't find the template's main method. If you are using #extends
Expand All @@ -88,7 +26,7 @@ def sleep(self, transaction):
super(Servlet, self).sleep(transaction)
self.session = None
self.request = None
self._request = None
self._request = None
self.response = None
self.transaction = None

Expand All @@ -99,10 +37,8 @@ def serverSidePath(self, path=None,
normpath=os.path.normpath,
abspath=os.path.abspath
):

if self._CHEETAH__isControlledByWebKit:
return super(Servlet, self).serverSidePath(path)
elif path:

if path:
return normpath(abspath(path.replace("\\", '/')))
elif hasattr(self, '_filePath') and self._filePath:
return normpath(abspath(self._filePath))
Expand Down

0 comments on commit 0eead16

Please sign in to comment.