import asyncio

from chilero.web import Application as BaseApplication

from .connection import get_pool


class Application(BaseApplication):

    def __init__(self, *args, **kwargs):
        self.settings = kwargs.pop('settings') or {}
        super(Application, self).__init__(*args, **kwargs)

    @asyncio.coroutine
    def get_pool(self):
        if not hasattr(self, 'db_pool'):
            self.db_pool = yield from get_pool(
                db_url=self.settings.get('db_url'),
                minsize=self.settings.get('db_pool_min') or 0,
                maxsize=self.settings.get('db_pool_max') or 10
            )

        return self.db_pool

    @asyncio.coroutine
    def close_pool(self):
        yield from self.db_pool.finish()

    @asyncio.coroutine
    def finish(self):
        yield from self.close_pool()

        yield from super(Application, self).finish()

@@ -137,16 +137,35 @@
 tion):%0A%0A
+    settings = %7B%7D%0A%0A
     def 
@@ -197,16 +197,53 @@
 wargs):%0A
+        if 'settings' in kwargs:%0A    
         
@@ -284,14 +284,9 @@
 gs')
- or %7B%7D
+%0A
 %0A   

set default settings to {}