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