[Repoze-dev] Repoze CVS: obob_helper.py tests.py
Chris McDonough
chrism at agendaless.com
Wed Sep 12 23:38:22 UTC 2007
Update of /home/repoze/cvs/repoze.zope2/repoze/zope2
In directory laguna.palladion.com:/tmp/cvs-serv17144/repoze/zope2
Added Files:
obob_helper.py
Removed Files:
tests.py
Log Message:
Add obob_helper and tests.
--- NEW FILE: obob_helper.py ---
from zope.security.management import newInteraction
from zope.security.management import endInteraction
from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.Publish import call_object
from ZPublisher.Publish import missing_name
from ZPublisher.Publish import dont_publish_class
from ZPublisher.mapply import mapply
db = None
def _setconfig(configfile):
""" Configure a Zope instance based on ZopeOptions. Optionally
accept a configfile argument (string path) in order to specify
where the configuration file exists. """
from Zope2.Startup import options, handlers
from App import config
opts = options.ZopeOptions()
opts.configfile = configfile
opts.realize(doc="Sorry, no option docs yet.", raise_getopt_errs=0)
handlers.handleConfig(opts.configroot, opts.confighandlers)
import App.config
App.config.setConfiguration(opts.configroot)
return opts
def configure():
from Zope2 import Startup
starter = Startup.get_starter()
conf = environ['zope.conf']
opts = _setconfig(conf)
starter.setConfiguration(opts.configroot)
starter.setupInitialLogging()
#starter.setupLocale() # this is rude
starter.setupSecurityOptions()
starter.setupPublisher()
starter.makeLockFile()
starter.makePidFile()
starter.startZope() # this sets up Globals
starter.setupFinalLogging()
import Globals
return Globals.DB
def get_connection(environ, configure):
# we pass in configure to make testing this function a little easier
global db
if not db:
db = configure()
conn = db.open()
closer = Closer(conn)
cleanup = environ.setdefault('tm.cleanup', {})
cleanup['closeconn'] = closer # close the connection when the txn ends
conn.setDebugInfo(environ)
return conn
class Closer:
def __init__(self, jar):
self._jar = jar
def __del__(self):
try:
self._jar.close()
except:
import traceback
traceback.print_exc()
raise
def makeRequest(environ):
response = HTTPResponse()
stdin = environ['wsgi.input']
request = HTTPRequest(stdin, environ, response)
return request
class Zope2ObobHelper:
def __init__(self, environ):
self.environ = environ
self.request = None
def setup(self):
self.request = makeRequest(self.environ)
newInteraction()
self.request.processInputs()
def invoke(self, published):
return mapply(published,
positional = self.request.args,
keyword = self.request,
debug = call_object,
maybe = 1,
missing_name = missing_name,
handle_class = dont_publish_class,
context = self.request,
bind=1)
def teardown(self):
endInteraction()
def before_traverse(self, current, name):
# XXX implement
pass
def traverse(self, current, name):
# XXX implement
pass
def before_invoke(self, published):
# XXX implement
pass
def map_result(self, request, result):
# XXX implement
pass
def get_root(environ, configure=configure):
# we allow the override of configure here to make testing a bit easier,
# not because it's used by the API
conn = get_connection(environ, configure)
root = conn.root()
app = root['Application']
return app
--- tests.py DELETED ---
_______________________________________________
Repoze-dev mailing list
Repoze-dev at lists.repoze.org
http://lists.repoze.org/mailman/listinfo/repoze-dev
More information about the Repoze-dev
mailing list