1
- from .core import (
2
- Warning , Bytea , DataError , DatabaseError , InterfaceError , ProgrammingError ,
1
+ from pg8000 .core import (
2
+ Warning , DataError , DatabaseError , InterfaceError , ProgrammingError ,
3
3
Error , OperationalError , IntegrityError , InternalError , NotSupportedError ,
4
- ArrayContentNotHomogenousError , ArrayContentEmptyError ,
5
- ArrayDimensionsNotConsistentError , ArrayContentNotSupportedError , utc ,
6
- Connection , Cursor , Binary , Date , DateFromTicks , Time , TimeFromTicks ,
7
- Timestamp , TimestampFromTicks , BINARY , Interval )
4
+ ArrayContentNotHomogenousError , ArrayDimensionsNotConsistentError ,
5
+ ArrayContentNotSupportedError , Connection , Cursor , Binary , Date ,
6
+ DateFromTicks , Time , TimeFromTicks , Timestamp , TimestampFromTicks , BINARY ,
7
+ Interval , PGEnum , PGJson , PGJsonb , PGTsvector , PGText , PGVarchar )
8
+ from ._version import get_versions
9
+ __version__ = get_versions ()['version' ]
10
+ del get_versions
8
11
9
12
# Copyright (c) 2007-2009, Mathieu Fenniak
13
+ # Copyright (c) The Contributors
10
14
# All rights reserved.
11
15
#
12
16
# Redistribution and use in source and binary forms, with or without
37
41
38
42
39
43
def connect (
40
- user = None , host = 'localhost' , unix_sock = None , port = 5432 , database = None ,
41
- password = None , ssl = False , timeout = None ,
42
- application_name = None , ** kwargs ):
43
- """Creates a connection to a PostgreSQL database.
44
-
45
- This function is part of the `DBAPI 2.0 specification
46
- <http://www.python.org/dev/peps/pep-0249/>`_; however, the arguments of the
47
- function are not defined by the specification.
48
-
49
- :param user:
50
- The username to connect to the PostgreSQL server with. If this is not
51
- provided, pg8000 looks first for the PGUSER then the USER environment
52
- variables.
53
-
54
- If your server character encoding is not ``ascii`` or ``utf8``, then
55
- you need to provide ``user`` as bytes, eg.
56
- ``"my_name".encode('EUC-JP')``.
57
-
58
- :keyword host:
59
- The hostname of the PostgreSQL server to connect with. Providing this
60
- parameter is necessary for TCP/IP connections. One of either ``host``
61
- or ``unix_sock`` must be provided. The default is ``localhost``.
62
-
63
- :keyword unix_sock:
64
- The path to the UNIX socket to access the database through, for
65
- example, ``'/tmp/.s.PGSQL.5432'``. One of either ``host`` or
66
- ``unix_sock`` must be provided.
67
-
68
- :keyword port:
69
- The TCP/IP port of the PostgreSQL server instance. This parameter
70
- defaults to ``5432``, the registered common port of PostgreSQL TCP/IP
71
- servers.
72
-
73
- :keyword database:
74
- The name of the database instance to connect with. This parameter is
75
- optional; if omitted, the PostgreSQL server will assume the database
76
- name is the same as the username.
77
-
78
- If your server character encoding is not ``ascii`` or ``utf8``, then
79
- you need to provide ``database`` as bytes, eg.
80
- ``"my_db".encode('EUC-JP')``.
81
-
82
- :keyword password:
83
- The user password to connect to the server with. This parameter is
84
- optional; if omitted and the database server requests password-based
85
- authentication, the connection will fail to open. If this parameter
86
- is provided but not requested by the server, no error will occur.
87
-
88
- :keyword ssl:
89
- Use SSL encryption for TCP/IP sockets if ``True``. Defaults to
90
- ``False``.
91
-
92
- :keyword timeout:
93
- Only used with Python 3, this is the time in seconds before the
94
- connection to the database will time out. The default is ``None`` which
95
- means no timeout.
96
-
97
- :rtype:
98
- A :class:`Connection` object.
99
- """
44
+ user , host = 'localhost' , database = None , port = 5432 , password = None ,
45
+ source_address = None , unix_sock = None , ssl_context = None , timeout = None ,
46
+ max_prepared_statements = 1000 , tcp_keepalive = True ,
47
+ application_name = None , replication = None ):
48
+
100
49
return Connection (
101
- user , host , unix_sock , port , database ,
102
- password , ssl , timeout , application_name )
50
+ user , host = host , database = database , port = port , password = password ,
51
+ source_address = source_address , unix_sock = unix_sock ,
52
+ ssl_context = ssl_context , timeout = timeout ,
53
+ max_prepared_statements = max_prepared_statements ,
54
+ tcp_keepalive = tcp_keepalive , application_name = application_name ,
55
+ replication = replication )
56
+
103
57
104
58
apilevel = "2.0"
105
59
"""The DBAPI level supported, currently "2.0".
@@ -108,37 +62,17 @@ def connect(
108
62
<http://www.python.org/dev/peps/pep-0249/>`_.
109
63
"""
110
64
111
- threadsafety = 3
65
+ threadsafety = 1
112
66
"""Integer constant stating the level of thread safety the DBAPI interface
113
- supports. This DBAPI module supports sharing the module, connections, and
114
- cursors, resulting in a threadsafety value of 3.
67
+ supports. This DBAPI module supports sharing of the module only. Connections
68
+ and cursors my not be shared between threads. This gives pg8000 a threadsafety
69
+ value of 1.
115
70
116
71
This property is part of the `DBAPI 2.0 specification
117
72
<http://www.python.org/dev/peps/pep-0249/>`_.
118
73
"""
119
74
120
75
paramstyle = 'format'
121
- """String property stating the type of parameter marker formatting expected by
122
- the interface. This value defaults to "format", in which parameters are
123
- marked in this format: "WHERE name=%s".
124
-
125
- This property is part of the `DBAPI 2.0 specification
126
- <http://www.python.org/dev/peps/pep-0249/>`_.
127
-
128
- As an extension to the DBAPI specification, this value is not constant; it
129
- can be changed to any of the following values:
130
-
131
- qmark
132
- Question mark style, eg. ``WHERE name=?``
133
- numeric
134
- Numeric positional style, eg. ``WHERE name=:1``
135
- named
136
- Named style, eg. ``WHERE name=:paramname``
137
- format
138
- printf format codes, eg. ``WHERE name=%s``
139
- pyformat
140
- Python format codes, eg. ``WHERE name=%(paramname)s``
141
- """
142
76
143
77
# I have no idea what this would be used for by a client app. Should it be
144
78
# TEXT, VARCHAR, CHAR? It will only compare against row_description's
@@ -159,12 +93,13 @@ def connect(
159
93
"""ROWID type oid"""
160
94
161
95
__all__ = [
162
- Warning , Bytea , DataError , DatabaseError , connect , InterfaceError ,
96
+ Warning , DataError , DatabaseError , connect , InterfaceError ,
163
97
ProgrammingError , Error , OperationalError , IntegrityError , InternalError ,
164
- NotSupportedError , ArrayContentNotHomogenousError , ArrayContentEmptyError ,
165
- ArrayDimensionsNotConsistentError , ArrayContentNotSupportedError , utc ,
98
+ NotSupportedError , ArrayContentNotHomogenousError ,
99
+ ArrayDimensionsNotConsistentError , ArrayContentNotSupportedError ,
166
100
Connection , Cursor , Binary , Date , DateFromTicks , Time , TimeFromTicks ,
167
- Timestamp , TimestampFromTicks , BINARY , Interval ]
101
+ Timestamp , TimestampFromTicks , BINARY , Interval , PGEnum , PGJson , PGJsonb ,
102
+ PGTsvector , PGText , PGVarchar ]
168
103
169
104
"""Version string for pg8000.
170
105
0 commit comments