File: __init__.py

package info (click to toggle)
mariadb-connector-python 1.1.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 812 kB
  • sloc: python: 6,246; ansic: 4,971; sh: 23; makefile: 14
file content (156 lines) | stat: -rw-r--r-- 6,542 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'''
MariaDB Connector/Python module enables python programs to access MariaDB and
MySQL databases, using an API which is compliant with the Python DB API 2.0
(PEP-249).
'''
import mariadb
from ._mariadb import (
    DataError,
    DatabaseError,
    Error,
    IntegrityError,
    InterfaceError,
    InternalError,
    NotSupportedError,
    OperationalError,
    PoolError,
    ProgrammingError,
    Warning,
    mariadbapi_version,
    _have_asan,
)

from .field import fieldinfo
from mariadb.dbapi20 import *   # noqa: F401,F403
from mariadb.connectionpool import *   # noqa: F401,F403
from mariadb.cursors import Cursor
from mariadb.release_info import __version__ as __version__
from mariadb.release_info import __version_info__ as __version_info__
from mariadb.release_info import __author__ as __author__
from mariadb.connections import Connection
# disable for now, until tests are in place
# from mariadb.pooling import *

_POOLS = _CONNECTION_POOLS = {}

__all__ = ["DataError", "DatabaseError", "Error", "IntegrityError",
           "InterfaceError", "InternalError", "NotSupportedError",
           "OperationalError", "PoolError", "ProgrammingError",
           "Warning", "Connection", "__version__", "__version_info__",
           "__author__", "Cursor", "fieldinfo", "_have_asan"]


def connect(*args, connectionclass=mariadb.connections.Connection, **kwargs):
    """
    Creates a MariaDB Connection object.

    By default the standard connectionclass mariadb.connections.Connection
    will be created.

    Parameter connectionclass specifies a subclass of
    mariadb.Connection object. If not specified default will be used.
    This optional parameter was added in version 1.1.0.

    Connection parameters are provided as a set of keyword arguments:
        - host:
            The host name or IP address of the database server.
            If MariaDB Connector/Python was built with MariaDB Connector/C 3.3
            it is also possible to provide a comma separated list of hosts for
            simple fail over in case of one or more hosts are not available.
        - user, username:
            The username used to authenticate with the database server
        - password, passwd:
            The password of the given user
        - database, db:
            database (schema) name to use when connecting with the database
            server
        - unix_socket:
            The location of the unix socket file to use instead of using an IP
            port to connect. If socket authentication is enabled, this can also
            be used in place of a password.
        - port:
            port number of the database server. If not specified the default
            value of 3306 will be used.
        - connect_timeout:
            connect timeout in seconds
        - read_timeout:
            read timeout in seconds
        - write_timeout:
            write timeout in seconds
        - local_infile:
            Enables or disables the use of LOAD DATA LOCAL INFILE statements.
        - compress= False:
            Uses the compressed protocol for client server communication. If
            the server doesn't support compressed protocol, the default
            protocol will be used.
        - init_command:
            Command(s) which will be executed when connecting and reconnecting
            to the database server
        - default_file:
            Read options from the specified option file. If the file is an
            empty string, default configuration file(s) will be used
        - default_group:
            Read options from the specified group
        - plugin_dir:
            Directory which contains MariaDB client plugins.
        - reconnect:
            Enables or disables automatic reconnect. Available since
            version 1.1.4
        - ssl_key:
            Defines a path to a private key file to use for TLS. This option
            requires that you use the absolute path, not a relative path. The
            specified key must be in PEM format
        - ssl_cert:
            Defines a path to the X509 certificate file to use for TLS.
            This option requires that you use the absolute path, not a relative
            path. The X609 certificate must be in PEM format.
        - ssl_ca:
            Defines a path to a PEM file that should contain one or more X509
            certificates for trusted Certificate Authorities (CAs) to use for
            TLS.  This option requires that you use the absolute path, not a
            relative path.
        - ssl_capath:
            Defines a path to a directory that contains one or more PEM files
            that contains one X509 certificate for a trusted Certificate
            Authority (CA)
        - ssl_cipher:
            Defines a list of permitted cipher suites to use for TLS
        - ssl_crlpath:
            Defines a path to a PEM file that should contain one or more
            revoked X509 certificates to use for TLS. This option requires
            that you use the absolute path, not a relative path.
        - ssl_verify_cert:
            Enables server certificate verification.
        - ssl:
            The connection must use TLS security or it will fail.
        - tls_version:
            A comma-separated list (without whitespaces) of TLS versions.
            Valid versions are TLSv1.0, TLSv1.1,TLSv1.2 and TLSv1.3.
            Added in version 1.1.7.
        - autocommit=False:
            Specifies the autocommit settings.
            True will enable autocommit, False will disable it (default).
        - converter:
            Specifies a conversion dictionary, where keys are FIELD_TYPE
            values and values are conversion functions

    """
    if kwargs:
        if "pool_name" in kwargs:
            if not kwargs["pool_name"] in mariadb._CONNECTION_POOLS:
                pool = mariadb.ConnectionPool(**kwargs)
            else:
                pool = mariadb._CONNECTION_POOLS[kwargs["pool_name"]]
            c = pool.get_connection()
            return c

    connection = connectionclass(*args, **kwargs)
    if not isinstance(connection, mariadb.connections.Connection):
        raise mariadb.ProgrammingError("%s is not an instance of "
                                       "mariadb.Connection" % connection)
    return connection


client_version_info = tuple(int(x, 10) for x in mariadbapi_version.split('.'))
client_version = client_version_info[0] * 10000 +\
    client_version_info[1] * 1000 + client_version_info[2]