On 06/25/2010 01:16 PM, Chris McDonough wrote:
> We've addressed this in repoze.who by giving r.who's middleware a mode
> which injects only a factory into the environ instead of more eagerly
> constructing identity information.  We can't really do that for
> repoze.zodbconn#connector, or at least it doesn't make much sense to do
> so, given that the entire purpose of opening it early is to be able to
> close it easily.

You brought up a good point.  Why couldn't we apply the same pattern 
here?  The connector middleware could look something like this:

class ConnectionFactory:

     def __init__(self, db):
         self.db = db
         self.connection = None

     def __call__(self):
         if self.connection is None:
             self.connection = self.db.open()
         return self.connection

     def close(self):
         if self.connection is not None:
             self.connection.close()


class ConnectionMiddleware:

     def __init__(self, next_app, db):
         self.next_app = next_app
         self.db = db

     def __call__(self, environ, start_response):
         factory = ConnectionFactory(self.db)
         self.environ['repoze.zodbconn.connection_factory'] = factory
         try:
             return self.next_app(environ, start_response)
         finally:
             factory.close()

Then we could make PersistentApplicationFinder use 
'repoze.zodbconn.connection_factory' from the environment.

Shane
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to