1- import asyncio
2- from urllib .parse import urlsplit , urlunsplit
1+ from typing import Optional , Union
2+ from urllib .parse import parse_qsl , urlsplit , urlunsplit
33
4- from aiohttp .client import ClientSession
4+ from aiohttp .client import ClientSession , ClientTimeout
55
66from .client import Client
77
@@ -22,9 +22,10 @@ def dsn_to_params(dsn):
2222 if not database :
2323 database = 'default'
2424
25- # XXX Parse parameters from query?
25+ params = dict ( parse_qsl ( parsed . query ))
2626
2727 return {
28+ ** params ,
2829 'url' : urlunsplit (('http' , netloc , '' , '' , '' )),
2930 'database' : database ,
3031 'user' : parsed .username ,
@@ -34,9 +35,26 @@ def dsn_to_params(dsn):
3435
3536class Pool :
3637
37- def __init__ (self , dsn , client_class = Client , ** params ):
38- # TODO Session and connector parameters
39- self ._session = ClientSession ()
38+ DEFAULT_TIMEOUT = {
39+ 'total' : 5 * 60 ,
40+ 'connect' : None ,
41+ 'sock_read' : 10 ,
42+ 'sock_connect' : 10 ,
43+ }
44+
45+ def __init__ (
46+ self , dsn , session_class = ClientSession ,
47+ session_timeout : Optional [Union [float , int , dict ]] = None ,
48+ client_class = Client , ** params ,
49+ ):
50+ timeout_params = self .DEFAULT_TIMEOUT .copy ()
51+ if isinstance (session_timeout , dict ):
52+ timeout_params .update (session_timeout )
53+ else :
54+ timeout_params ['total' ] = session_timeout
55+ self ._session = session_class (
56+ timeout = ClientTimeout (** timeout_params )
57+ )
4058 params .update (dsn_to_params (dsn ))
4159 self ._client = client_class (self ._session , ** params )
4260
0 commit comments