def connection_info_for(db_or_uri):
 if db_or_uri.startswith(('postgresql://', 'postgres://')):
  us = urlparse.urlsplit(db_or_uri)
  if (len(us.path) > 1):
   db_name = us.path[1:]
  elif us.username:
   db_name = us.username
  else:
   db_name = us.hostname
  return (db_name, {'dsn': db_or_uri})
 connection_info = {'database': db_or_uri}
 for p in ('host', 'port', 'user', 'password'):
  cfg = tools.config[('db_' + p)]
  if cfg:
   connection_info[p] = cfg
 return (db_or_uri, connection_info)

def connection_info_for ( db_or_uri ) : if db_or_uri . startswith ( ( 'postgresql://' , 'postgres://' ) ) : us = urlparse . urlsplit ( db_or_uri ) if ( len ( us . path ) > 1 ) : db_name = us . path [ 1 : ] elif us . username : db_name = us . username else : db_name = us . hostname return ( db_name , { 'dsn' : db_or_uri } ) connection_info = { 'database' : db_or_uri } for p in ( 'host' , 'port' , 'user' , 'password' ) : cfg = tools . config [ ( 'db_' + p ) ] if cfg : connection_info [ p ] = cfg return ( db_or_uri , connection_info )
parse the given db_or_uri and return a 2-tuple connection params are either a dictionary with a single key dsn containing a connection uri .