def parse_rfc1738_args(name):
    """Parse the given database URI and return a dictionary of database
    connection values.

    Eg: parse_rfc1738_args('postgres://user:pass@host:5432/dbname')
        -> { 
            'username': 'user', 
            'password': 'pass', 
            'host': 'host',
            'port': '5432',
            'database': 'dbname'
           }
    """
    if name is None:
        raise RuntimeError("MORESQL_DATABASE_URI needs to be specified")

    pattern = re.compile(r'''
        (?P<name>[\w\+]+)://
        (?:
        (?P<username>[^:/]*)
        (?::(?P<password>[^/]*))?
        @)?
        (?:
        (?P<host>[^/:]*)
        (?::(?P<port>[^/]*))?
        )?
        (?:/(?P<database>.*))?
        ''', re.X)

    match = pattern.match(name)
    if match is None:
        raise RuntimeError("Wrong DB URI string '%s'" % name)

    components = match.groupdict()

    if components['name'] != 'postgres':
        raise RuntimeError("MoreSQL only supports postgres databases")

    if components['password'] is not None:
        components['password'] = urllib.unquote_plus(components['password'])

    del components['name']
    return components
dataset/ETHPy150Open ema/flask-moresql/flask_moresql.py/parse_rfc1738_args/original