def specifier_to_db(db_spec):
local_match = LOCAL_RE.match(db_spec)<EOL>remote_match = REMOTE_RE.match(db_spec)<EOL>plain_match = PLAIN_RE.match(db_spec)<EOL>if local_match:<EOL><INDENT>return local_match.groupdict()['<STR_LIT>']<EOL><DEDENT>elif remote_match:<EOL><INDENT>hostname, portnum, database = map(remote_match.groupdict().get,<EOL>('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'))<EOL>local_url = settings._('<STR_LIT>', '<STR_LIT>')<EOL>localhost, localport = urlparse.urlparse(local_url)[<NUM_LIT:1>].split('<STR_LIT::>')<EOL>if (localhost == hostname) and (localport == portnum):<EOL><INDENT>return database<EOL><DEDENT>return '<STR_LIT>' % (hostname, portnum, database)<EOL><DEDENT>elif plain_match:<EOL><INDENT>return plain_match.groupdict()['<STR_LIT>']<EOL><DEDENT>raise ValueError('<STR_LIT>' % (db_spec,))<EOL>
Return the database string for a database specifier.

The database specifier takes a custom format for specifying local and remote
databases. A local database is specified by the following format:

    local:<db_name>

For example, a database called 'sessions' would be specified by the string
``'local:sessions'``. Remote databases are specified like this:

    remote:<host>:<port_num>:<db_name>

For example, a database called 'log' on the server 'dev.example.com' at port
number 5984 would be specified by ``'remote:dev.example.com:5984:log'``.

These specifiers are translated into strings acceptable to CouchDB; local
specs are turned into the database name alone, and remote specs are turned
into ``'http://host:port/db_name'`` URLs.