-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Shane Hathaway wrote:
> 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.

That looks lazy enough for my taste. ;)


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tsea...@palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkwlClUACgkQ+gerLs4ltQ54ZACgmgZR+Q1qp7YeyMCsMPue40zC
bl0An06+EJMmj3XPcVrxNw7y6P2JGAbL
=8Fml
-----END PGP SIGNATURE-----
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to