-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path__init__.py
More file actions
84 lines (71 loc) · 2.16 KB
/
Copy path__init__.py
File metadata and controls
84 lines (71 loc) · 2.16 KB
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
81
82
83
84
##
# copyright 2009, James William Pye
# http://python.projects.postgresql.org
##
"""
py-postgresql is a Python package for using PostgreSQL. This includes low-level
protocol tools, a driver(PG-API and DB-API), and cluster management tools.
If it's not documented in the narratives, `postgresql.documentation.index`, then
the stability of the APIs should *not* be trusted.
"""
__all__ = [
'__author__',
'__date__',
'__project__',
'__project_id__',
'__docformat__',
'__version__',
'version_info',
'open',
]
__author__ = "James William Pye <x@jwp.name>"
__date__ = "2009-06-13 17:19:00-07"
__project__ = 'py-postgresql'
__project_id__ = 'http://python.projects.postgresql.org'
version_info = (0, 8, 2, 'final', 0)
__version__ = '.'.join(map(str, version_info[:3])) + (
version_info[3] if version_info[3] != 'final' else ''
)
pg_iri = pg_driver = pg_param = None
def open(iri = None):
"""
Create a `postgresql.api.Connection` to the server referenced by the given
`iri`::
>>> import postgresql
# General Format:
>>> db = postgresql.open('pq://user:password@host:port/database')
# Connect to 'postgres' at localhost.
>>> db = postgresql.open('localhost/postgres')
If the URL starts with an '&', a connector will be returned instead of a
connection.
(Note: "pq" is the name of the protocol used to communicate with PostgreSQL)
"""
global pg_iri, pg_driver, pg_param
if None in (pg_iri, pg_driver, pg_param):
from . import iri as pg_iri
from . import driver as pg_driver
from . import clientparameters as pg_param
return_connector = False
if iri is not None:
if iri.startswith('&'):
return_connector = True
iri = iri[1:]
iri_params = pg_iri.parse(iri)
iri_params.pop('path', None)
else:
iri_params = {}
std_params = pg_param.collect(prompt_title = None)
params = pg_param.normalize(
list(pg_param.denormalize_parameters(std_params)) + \
list(pg_param.denormalize_parameters(iri_params))
)
# Resolve the password, but never prompt.
pg_param.resolve_password(params, prompt_title = None)
C = pg_driver.default.fit(**params)
if return_connector is True:
return C
else:
c = C()
c.connect()
return c
__docformat__ = 'reStructuredText'