/usr/lib/python2.7/dist-packages/imposm/db/config.py is in python-imposm 2.6.0+ds-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | # Copyright 2011 Omniscale (http://omniscale.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import cgi
import urllib
from . postgis import PostGISDB
from .. mapping import Options
def DB(db_conf):
if db_conf.get('name', 'postgis') == 'postgis':
# default and backwards compat
return PostGISDB(db_conf)
raise ValueError('unknown db: %s' % (db_conf.name,))
def check_connection(db_conf):
try:
db = DB(db_conf)
db.connection
except Exception, e:
return e
def db_conf_from_string(conf, base_db_conf):
db_conf = _parse_rfc1738_args(conf)
if 'proj' not in db_conf:
db_conf.proj = base_db_conf.proj
if 'prefix' not in db_conf:
db_conf.prefix = base_db_conf.prefix
return db_conf
def _parse_rfc1738_args(name):
# from SQLAlchemy lib/sqlalchemy/engine/url.py
# MIT licensed
pattern = re.compile(r'''
(?P<name>\w+)://
(?:
(?P<user>[^:/]*)
(?::(?P<password>[^/]*))?
@)?
(?:
(?P<host>[^/:]*)
(?::(?P<port>[^/]*))?
)?
(?:/(?P<db>.*))?
'''
, re.X)
m = pattern.match(name)
if m is not None:
components = m.groupdict()
if components['db'] is not None:
tokens = components['db'].split('?', 2)
components['db'] = tokens[0]
query = (len(tokens) > 1 and dict(cgi.parse_qsl(tokens[1]))) or None
if query is not None:
query = dict((k.encode('ascii'), query[k]) for k in query)
else:
query = None
components['query'] = query
if components['password'] is not None:
components['password'] = urllib.unquote_plus(components['password'])
return Options(**components)
else:
raise ValueError(
"Could not parse rfc1738 URL from string '%s'" % name)
|