Commit ccfbfcbc authored by Julien Muchembled's avatar Julien Muchembled

ZMySQLDA: accept 'db@unix_socket ...' syntax for connection strings

This deprecates the old syntax, which uselessly requires to specify credentials.
parent 406b1c68
......@@ -49,7 +49,7 @@
The connection string used for Z MySQL Database Connection
is of the form:
<pre>
[~] [*lock] [+/-][database][@host[:port]] [user [password [unix_socket]]]
[~] [*lock] [+|-][database][@unix_socket|@host[:port]] [user [password]]
</pre>
or typically:
<pre>
......@@ -61,10 +61,8 @@
port on the local system, use 127.0.0.1 for the host instead of
localhost.
<p>
Either a database or a host or both must be specified.
<p>
If the UNIX socket is in a non-standard location, you can specify
the full path to it after the password.
IPv6 are supported and must be surrounded with brackets.
A UNIX socket absolute path can be specified in place of a TCP address.
<p>
A '-' in front of the database tells ZMySQLDA to not use Zope's
Transaction Manager, even if the server supports transactions. A
......
......@@ -86,8 +86,10 @@
'''$Id: db.py,v 1.20 2002/03/14 20:24:54 adustman Exp $'''
__version__='$Revision: 1.20 $'[11:-2]
import os
import _mysql
import MySQLdb
import warnings
from _mysql_exceptions import OperationalError, NotSupportedError, ProgrammingError
MySQLdb_version_required = (0,9,2)
......@@ -205,14 +207,17 @@ class DB(TM):
db = items.pop(0)
if '@' in db:
db, host = db.split('@', 1)
if host.startswith('['):
host, port = host[1:].split(']', 1)
if port.startswith(':'):
kwargs['port'] = int(port[1:])
elif ':' in host:
host, port = host.split(':', 1)
kwargs['port'] = int(port)
kwargs['host'] = host
if os.path.isabs(host):
kwargs['unix_socket'] = host
else:
if host.startswith('['):
host, port = host[1:].split(']', 1)
if port.startswith(':'):
kwargs['port'] = int(port[1:])
elif ':' in host:
host, port = host.split(':', 1)
kwargs['port'] = int(port)
kwargs['host'] = host
if db:
if db[0] in '+-':
self._try_transactions = db[0]
......@@ -223,7 +228,10 @@ class DB(TM):
kwargs['user'] = items.pop(0)
if items:
kwargs['passwd'] = items.pop(0)
if items:
if items: # BBB
assert 'unix_socket' not in kwargs
warnings.warn("use '<db>@<unix_socket> ...' syntax instead",
DeprecationWarning)
kwargs['unix_socket'] = items.pop(0)
defs={
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment