Skip to content
This repository was archived by the owner on Mar 9, 2024. It is now read-only.

Commit 83e3f2a

Browse files
author
/dev/null
committed
Re-use requests.auth.HTTPDigestAuth between requests
Fixes: #104
1 parent 59953f6 commit 83e3f2a

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install:
1818
- pip install dist/*.tar.gz # install dependencies as specified in setup.py
1919
- pip install -r test_requirements_py`echo $TRAVIS_PYTHON_VERSION | cut -f 1 -d .`.txt
2020
script:
21+
- black --check .
2122
- pytest
2223
after_success:
2324
- coveralls

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,9 @@ Development
9191
.. code-block:: bash
9292
9393
.venv/bin/pytest
94+
95+
6. Format your code with black
96+
97+
.. code-block:: bash
98+
99+
.venv/bin/black .

monero/backends/jsonrpc/daemon.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def __init__(
106106
protocol=protocol, host=host, port=port
107107
)
108108
_log.debug("JSONRPC daemon backend URL: {url}".format(url=self.url))
109-
self.user = user
110-
self.password = password
109+
self.auth = requests.auth.HTTPDigestAuth(user, password)
111110
self.timeout = timeout
112111
self.verify_ssl_certs = verify_ssl_certs
113112
self.proxies = {protocol: proxy_url}
@@ -222,12 +221,11 @@ def raw_request(self, path, data=None):
222221
path=path, data=json.dumps(data, indent=2, sort_keys=True)
223222
)
224223
)
225-
auth = requests.auth.HTTPDigestAuth(self.user, self.password)
226224
rsp = requests.post(
227225
self.url + path,
228226
headers=hdr,
229227
data=json.dumps(data) if data else None,
230-
auth=auth,
228+
auth=self.auth,
231229
timeout=self.timeout,
232230
verify=self.verify_ssl_certs,
233231
proxies=self.proxies,
@@ -251,12 +249,11 @@ def raw_jsonrpc_request(self, method, params=None):
251249
method=method, params=json.dumps(params, indent=2, sort_keys=True)
252250
)
253251
)
254-
auth = requests.auth.HTTPDigestAuth(self.user, self.password)
255252
rsp = requests.post(
256253
self.url + "/json_rpc",
257254
headers=hdr,
258255
data=json.dumps(data),
259-
auth=auth,
256+
auth=self.auth,
260257
timeout=self.timeout,
261258
verify=self.verify_ssl_certs,
262259
proxies=self.proxies,

monero/backends/jsonrpc/wallet.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ def __init__(
5050
protocol=protocol, host=host, port=port
5151
)
5252
_log.debug("JSONRPC wallet backend URL: {url}".format(url=self.url))
53-
self.user = user
54-
self.password = password
53+
self.auth = requests.auth.HTTPDigestAuth(user, password)
5554
self.timeout = timeout
5655
self.verify_ssl_certs = verify_ssl_certs
5756
self.proxies = {protocol: proxy_url}
@@ -386,12 +385,11 @@ def raw_request(self, method, params=None, squelch_error_logging=False):
386385
method=method, params=json.dumps(params, indent=2, sort_keys=True)
387386
)
388387
)
389-
auth = requests.auth.HTTPDigestAuth(self.user, self.password)
390388
rsp = requests.post(
391389
self.url,
392390
headers=hdr,
393391
data=json.dumps(data),
394-
auth=auth,
392+
auth=self.auth,
395393
timeout=self.timeout,
396394
verify=self.verify_ssl_certs,
397395
proxies=self.proxies,

test_requirements_py3.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
black==21.11b1
12
coverage~=5.3
23
coveralls~=2.1
34
pip>=9

0 commit comments

Comments
 (0)