Skip to content

Commit ce242ad

Browse files
committed
cherrypick commit 755dfdc upstream to allow bind before connect
Related: rhbz#1378008
1 parent c3f291b commit ce242ad

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
From 755dfdc2e16f2f7f5fa6669cb81d0ec3118ec203 Mon Sep 17 00:00:00 2001
2+
From: Damien Ciabrini <damien.ciabrini@gmail.com>
3+
Date: Wed, 16 Nov 2016 13:11:03 +0100
4+
Subject: [PATCH] Add bind_address option (#529)
5+
6+
Allow connecting to the DB from a specific network interface
7+
---
8+
pymysql/connections.py | 14 ++++++++++++--
9+
1 file changed, 12 insertions(+), 2 deletions(-)
10+
11+
diff --git a/pymysql/connections.py b/pymysql/connections.py
12+
index d5e39a1..2884cdc 100644
13+
--- a/pymysql/connections.py
14+
+++ b/pymysql/connections.py
15+
@@ -534,7 +534,8 @@ class Connection(object):
16+
compress=None, named_pipe=None, no_delay=None,
17+
autocommit=False, db=None, passwd=None, local_infile=False,
18+
max_allowed_packet=16*1024*1024, defer_connect=False,
19+
- auth_plugin_map={}, read_timeout=None, write_timeout=None):
20+
+ auth_plugin_map={}, read_timeout=None, write_timeout=None,
21+
+ bind_address=None):
22+
"""
23+
Establish a connection to the MySQL database. Accepts several
24+
arguments:
25+
@@ -544,6 +545,9 @@ class Connection(object):
26+
password: Password to use.
27+
database: Database to use, None to not use a particular one.
28+
port: MySQL port to use, default is usually OK. (default: 3306)
29+
+ bind_address: When the client has multiple network interfaces, specify
30+
+ the interface from which to connect to the host. Argument can be
31+
+ a hostname or an IP address.
32+
unix_socket: Optionally, you can use a unix socket rather than TCP/IP.
33+
charset: Charset you want to use.
34+
sql_mode: Default SQL_MODE to use.
35+
@@ -632,6 +636,7 @@ class Connection(object):
36+
database = _config("database", database)
37+
unix_socket = _config("socket", unix_socket)
38+
port = int(_config("port", port))
39+
+ bind_address = _config("bind-address", bind_address)
40+
charset = _config("default-character-set", charset)
41+
42+
self.host = host or "localhost"
43+
@@ -640,6 +645,7 @@ class Connection(object):
44+
self.password = password or ""
45+
self.db = database
46+
self.unix_socket = unix_socket
47+
+ self.bind_address = bind_address
48+
if read_timeout is not None and read_timeout <= 0:
49+
raise ValueError("read_timeout should be >= 0")
50+
self._read_timeout = read_timeout
51+
@@ -884,10 +890,14 @@ class Connection(object):
52+
self.host_info = "Localhost via UNIX socket"
53+
if DEBUG: print('connected using unix_socket')
54+
else:
55+
+ kwargs = {}
56+
+ if self.bind_address is not None:
57+
+ kwargs['source_address'] = (self.bind_address, 0)
58+
while True:
59+
try:
60+
sock = socket.create_connection(
61+
- (self.host, self.port), self.connect_timeout)
62+
+ (self.host, self.port), self.connect_timeout,
63+
+ **kwargs)
64+
break
65+
except (OSError, IOError) as e:
66+
if e.errno == errno.EINTR:
67+
--
68+
2.5.5
69+

python-PyMySQL.spec

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
Name: python-%{pypi_name}
77
Version: 0.7.9
8-
Release: 1%{?dist}
8+
Release: 2%{?dist}
99
Summary: Pure-Python MySQL client library
1010

1111
License: MIT
1212
URL: https://pypi.python.org/pypi/%{pypi_name}/
1313
Source0: https://pypi.python.org/packages/a4/c4/c15457f261fda9839637de044eca9b6da8f55503183fe887523801b85701/PyMySQL-0.7.9.tar.gz
1414

15+
Patch1: bz1378008-add-bind-address-option.patch
16+
1517
BuildArch: noarch
1618
BuildRequires: python2-devel
1719
BuildRequires: python-setuptools
@@ -49,6 +51,8 @@ and Jython.
4951
%setup -qn %{pypi_name}-%{version}
5052
rm -rf %{pypi_name}.egg-info
5153

54+
%patch1 -p1
55+
5256
%build
5357
%py2_build
5458
%if 0%{?with_python3}
@@ -89,6 +93,10 @@ done
8993
%endif
9094

9195
%changelog
96+
* Wed Nov 23 2016 Damien Ciabrini <dciabrin@redhat.com> - 0.7.9-2
97+
- cherrypick commit 755dfdc upstream to allow bind before connect
98+
Related: rhbz#1378008
99+
92100
* Sun Sep 18 2016 Julien Enselme <jujens@jujens.eu> - 0.7.9-1
93101
- Update to 0.7.9
94102

0 commit comments

Comments
 (0)