def parse_db_config(config_key='sqlalchemy.url'):
 from ckan.common import config
 url = config[config_key]
 regex = ['^\\s*(?P<db_type>\\w*)', '://', '(?P<db_user>[^:]*)', ':?', '(?P<db_pass>[^@]*)', '@', '(?P<db_host>[^/:]*)', ':?', '(?P<db_port>[^/]*)', '/', '(?P<db_name>[\\w.-]*)']
 db_details_match = re.match(''.join(regex), url)
 if (not db_details_match):
  raise Exception(('Could not extract db details from url: %r' % url))
 db_details = db_details_match.groupdict()
 return db_details

def parse_db_config ( config_key = 'sqlalchemy.url' ) : from ckan . common import config url = config [ config_key ] regex = [ '^\\s*(?P<db_type>\\w*)' , '://' , '(?P<db_user>[^:]*)' , ':?' , '(?P<db_pass>[^@]*)' , '@' , '(?P<db_host>[^/:]*)' , ':?' , '(?P<db_port>[^/]*)' , '/' , '(?P<db_name>[\\w.-]*)' ] db_details_match = re . match ( '' . join ( regex ) , url ) if ( not db_details_match ) : raise Exception ( ( 'Could not extract db details from url: %r' % url ) ) db_details = db_details_match . groupdict ( ) return db_details
takes a config key for a database connection url and parses it into a dictionary .