[Zope3-checkins] CVS: Zope3/lib/python/Zope/App - _app.py:1.1.2.2

Jim Fulton jim@zope.com
Thu, 24 Oct 2002 11:02:32 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App
In directory cvs.zope.org:/tmp/cvs-serv24845/lib/python/Zope/App

Modified Files:
      Tag: FileSystemSync-branch
	_app.py 
Log Message:
Got debugging working in the new Application access objects. 


=== Zope3/lib/python/Zope/App/_app.py 1.1.2.1 => 1.1.2.2 ===
--- Zope3/lib/python/Zope/App/_app.py:1.1.2.1	Thu Oct 10 00:43:25 2002
+++ Zope3/lib/python/Zope/App/_app.py	Thu Oct 24 11:02:01 2002
@@ -17,6 +17,7 @@
 """
 __metaclass__ = type
 
+import base64
 from cStringIO import StringIO
 from Zope.Publisher.Publish import publish as _publish
 
@@ -62,6 +63,17 @@
             from ZODB.DB import DB
             storage = FileStorage(db)
             db = DB(storage)
+            
+    # Make sure we have an application object
+    connection = db.open()
+    if 'Application' not in connection.root():
+        from Zope.App.OFS.Content.Folder.RootFolder import RootFolder
+        import Transaction
+        connection.root()['Application'] = RootFolder()
+        Transaction.get_transaction().commit()
+
+    connection.close()
+
     return db
 
 class Application:
@@ -76,11 +88,18 @@
 
     __browser_pub = None
     __TestRequest = None
-    def debug(path='/', stdin='', basic=None, **kw):
-        out = StringIO()
+    def debug(self, path='/', stdin='', stdout=None, basic=None, pm=0,
+              environment = None, **kw):
+        
+        if stdout is None:
+            stdout = StringIO()
+
         if type(stdin) is str:
             stdin = StringIO(stdin)
+
         env = {'PATH_INFO': path}
+        if environment is not None:
+            env.update(environment)
         env.update(kw)
 
         if basic:
@@ -93,11 +112,11 @@
             self.__TestRequest = TestRequest
             self.__browser_pub = BrowserPublication(self.db)
 
-        request = self.__TestRequest(StringIO(''), StringIO(), env)
+        request = self.__TestRequest(stdin, stdout, env)
         request.setPublication(self.__browser_pub)
 
-        _publish(request, 0)
+        _publish(request, handle_errors = not pm)
 
-        out.seek(0)
-        print out.read()
+        stdout.seek(0)
+        print stdout.read()