Skip to content

Commit 8082966

Browse files
manojbalaji1mistercrunch
authored andcommitted
Update connect function in api.py to accept proxies (#185)
* Update api.py added proxies as input parameter for connection * fix issues raised from flake8 * modify testcase test_context to expect proxies=None as one of the paramters being sent * resolve rebase merge conflicts and add trailing comma
1 parent ab5b059 commit 8082966

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

pydruid/db/api.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def connect(
3030
context=None,
3131
header=False,
3232
ssl_verify_cert=True,
33+
proxies=None,
3334
): # noqa: E125
3435
"""
3536
Constructor for creating a connection to the database.
@@ -39,17 +40,19 @@ def connect(
3940
4041
"""
4142
context = context or {}
43+
4244
return Connection(
43-
host,
44-
port,
45-
path,
46-
scheme,
47-
user,
48-
password,
49-
context,
50-
header,
51-
ssl_verify_cert,
52-
)
45+
host,
46+
port,
47+
path,
48+
scheme,
49+
user,
50+
password,
51+
context,
52+
header,
53+
ssl_verify_cert,
54+
proxies,
55+
)
5356

5457

5558
def check_closed(f):
@@ -116,7 +119,6 @@ def get_type(value):
116119

117120

118121
class Connection(object):
119-
120122
"""Connection to a Druid database."""
121123

122124
def __init__(
@@ -130,6 +132,7 @@ def __init__(
130132
context=None,
131133
header=False,
132134
ssl_verify_cert=True,
135+
proxies=None,
133136
):
134137
netloc = "{host}:{port}".format(host=host, port=port)
135138
self.url = parse.urlunparse((scheme, netloc, path, None, None, None))
@@ -140,6 +143,7 @@ def __init__(
140143
self.user = user
141144
self.password = password
142145
self.ssl_verify_cert = ssl_verify_cert
146+
self.proxies = proxies
143147

144148
@check_closed
145149
def close(self):
@@ -163,14 +167,17 @@ def commit(self):
163167
@check_closed
164168
def cursor(self):
165169
"""Return a new Cursor Object using the connection."""
170+
166171
cursor = Cursor(
167-
self.url,
168-
self.user,
169-
self.password,
170-
self.context,
171-
self.header,
172-
self.ssl_verify_cert,
173-
)
172+
self.url,
173+
self.user,
174+
self.password,
175+
self.context,
176+
self.header,
177+
self.ssl_verify_cert,
178+
self.proxies,
179+
)
180+
174181
self.cursors.append(cursor)
175182

176183
return cursor
@@ -188,7 +195,6 @@ def __exit__(self, *exc):
188195

189196

190197
class Cursor(object):
191-
192198
"""Connection cursor."""
193199

194200
def __init__(
@@ -199,13 +205,15 @@ def __init__(
199205
context=None,
200206
header=False,
201207
ssl_verify_cert=True,
208+
proxies=None,
202209
):
203210
self.url = url
204211
self.context = context or {}
205212
self.header = header
206213
self.user = user
207214
self.password = password
208215
self.ssl_verify_cert = ssl_verify_cert
216+
self.proxies = proxies
209217

210218
# This read/write attribute specifies the number of rows to fetch at a
211219
# time with .fetchmany(). It defaults to 1 meaning to fetch a single
@@ -335,6 +343,7 @@ def _stream_query(self, query):
335343
json=payload,
336344
auth=auth,
337345
verify=self.ssl_verify_cert,
346+
proxies=self.proxies,
338347
)
339348
if r.encoding is None:
340349
r.encoding = "utf-8"

tests/db/test_cursor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def test_context(self, requests_post_mock):
6363
stream=True,
6464
headers={'Content-Type': 'application/json'},
6565
json={'query': query, 'context': context, 'header': False},
66-
verify=True
66+
verify=True,
67+
proxies=None,
6768
)
6869

6970
@patch('requests.post')

0 commit comments

Comments
 (0)