Log message for revision 67146:
  Twisted working with new publisher and old Request and Response objects.
  

Changed:
  U   Zope/branches/publication-refactor/lib/python/OFS/Application.py
  U   Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py
  U   Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py
  U   Zope/branches/publication-refactor/lib/python/Zope2/Startup/__init__.py

-=-
Modified: Zope/branches/publication-refactor/lib/python/OFS/Application.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/OFS/Application.py    
2006-04-19 16:21:42 UTC (rev 67145)
+++ Zope/branches/publication-refactor/lib/python/OFS/Application.py    
2006-04-19 16:31:45 UTC (rev 67146)
@@ -117,7 +117,6 @@
     Redirect = ZopeRedirect = PrincipiaRedirect
 
     def __bobo_traverse__(self, REQUEST, name=None):
-
         try: return getattr(self, name)
         except AttributeError: pass
         try: return self[name]

Modified: 
Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py     
2006-04-19 16:21:42 UTC (rev 67145)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py     
2006-04-19 16:31:45 UTC (rev 67146)
@@ -1072,6 +1072,8 @@
         clone['PARENTS']=[self['PARENTS'][-1]]
         return clone
 
+    # XXX This is called getHeader in Response, and in Zope3 request.
+    # We should probably rename this getHeader and deprecate this.
     def get_header(self, name, default=None):
         """Return the named HTTP header, or an optional default
         argument or None if the header is not found. Note that

Modified: 
Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py     
2006-04-19 16:21:42 UTC (rev 67145)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py     
2006-04-19 16:31:45 UTC (rev 67146)
@@ -92,8 +92,11 @@
         # Now, some code from ZPublisher.BaseRequest:
         # If the top object has a __bobo_traverse__ method, then use it
         # to possibly traverse to an alternate top-level object.
-        if hasattr(ob, '__bobo_traverse__'):
-            ob = ob.__bobo_traverse__(request)
+        try:
+            if hasattr(ob, '__bobo_traverse__'):
+                ob = ob.__bobo_traverse__(request)
+        except:
+            pass
 
         if hasattr(ob, '__of__'):
             # Try to bind the top-level object to the request
@@ -170,6 +173,8 @@
                                      sys.exc_info()[1],
                                      sys.exc_info()[2],
                                      )
+            except:
+                return request.response.exception()
         finally:
             self._abort()
 
@@ -255,6 +260,10 @@
 
 class Zope2BrowserRequest(BrowserRequest):
 
+    # Zope 2 compatibility XXX Deprecate!
+    def get_header(self, name, default=None):
+        return self.getHeader(name, default)
+
     def __init__(self, *args, **kw):
         self.other = {'PARENTS':[]}
         self._lazies = {}
@@ -283,7 +292,7 @@
         return v
 
     def traverse(self, object):
-        ob = super(BrowserRequest, self).traverse(object)
+        ob = super(Zope2BrowserRequest, self).traverse(object)
         self.other['PARENTS'].append(ob)
         return ob
 
@@ -326,7 +335,7 @@
                 if pathonly:
                     path = [''] + path[:n]
                 else:
-                    path = [other['SERVER_URL']] + path[:n]
+                    path = [self['SERVER_URL']] + path[:n]
                 URL = '/'.join(path)
                 if other.has_key('PUBLISHED'):
                     # Don't cache URLs until publishing traversal is done.
@@ -390,8 +399,76 @@
         if v is not _marker: return v
 
         return default
+    
+from ZPublisher.HTTPRequest import HTTPRequest
+from ZPublisher.HTTPResponse import HTTPResponse
+from cStringIO import StringIO
+import traceback
+from zope.publisher.http import status_reasons, DirectResult
 
+class Zope2HTTPResponse(HTTPResponse):
+    
+    def setResult(self, result):
+        """Sets the response result value.
+        """
+        self.setBody(result)
 
+    def handleException(self, exc_info):
+        """Handles an otherwise unhandled exception.
+
+        The publication object gets the first chance to handle an exception,
+        and if it doesn't have a good way to do it, it defers to the
+        response.  Implementations should set the reponse body.
+        """
+        f = StringIO()
+        traceback.print_exception(
+            exc_info[0]. exc_info[1], exc_info[2], 100, f)
+        self.setResult(f.getvalue())
+
+    def internalError(self):
+        'See IPublisherResponse'
+        self.setStatus(500, u"The engines can't take any more, Jim!")
+
+    def reset(self):
+        """Reset the output result.
+
+        Reset the response by nullifying already set variables.
+        """
+        raise Exception
+
+    def retry(self):
+        """Returns a retry response
+
+        Returns a response suitable for repeating the publication attempt.
+        """
+        raise Exception
+
+    def getStatusString(self):
+        'See IHTTPResponse'
+        return '%i %s' % (self.status, status_reasons[self.status])
+
+    def getHeaders(self):
+        return self.headers.items()    
+    
+    def consumeBodyIter(self):
+        return (self.body,)
+    
+
+class Zope2HTTPRequest(HTTPRequest):
+    
+    def supportsRetry(self):
+        return False
+    
+    def traverse(self, object):
+        path = self.get('PATH_INFO')
+        self['PARENTS'] = [self.publication.root]
+        return HTTPRequest.traverse(self, path)
+
+
+def Zope2RequestFactory(sin, env):
+    response=Zope2HTTPResponse() 
+    return Zope2HTTPRequest(sin, env, response)
+
 class Zope2HTTPFactory(object):
 
     implements(IRequestPublicationFactory)
@@ -400,4 +477,5 @@
         return True
 
     def __call__(self):
-        return Zope2BrowserRequest, ZopePublication
+
+        return Zope2RequestFactory, ZopePublication

Modified: 
Zope/branches/publication-refactor/lib/python/Zope2/Startup/__init__.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/Zope2/Startup/__init__.py     
2006-04-19 16:21:42 UTC (rev 67145)
+++ Zope/branches/publication-refactor/lib/python/Zope2/Startup/__init__.py     
2006-04-19 16:31:45 UTC (rev 67146)
@@ -95,7 +95,10 @@
         self.makePidFile()
         self.setupInterpreter()
         self.startZope()
-        self.registerSignals()
+        from App.config import getConfiguration
+        config = getConfiguration()
+        if not config.twisted_servers:
+            self.registerSignals()
         # emit a "ready" message in order to prevent the kinds of emails
         # to the Zope maillist in which people claim that Zope has "frozen"
         # after it has emitted ZServer messages.
@@ -105,11 +108,15 @@
     def run(self):
         # the mainloop.
         try:
-            #import ZServer
-            #import Lifetime
-            #Lifetime.loop()
-            #sys.exit(ZServer.exit_code)
-            twisted.internet.reactor.run()
+            from App.config import getConfiguration
+            config = getConfiguration()
+            if config.twisted_servers:
+                twisted.internet.reactor.run()
+            else:
+                import ZServer
+                import Lifetime
+                Lifetime.loop()
+                sys.exit(ZServer.exit_code)
         finally:
             self.shutdown()
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to