Skip to content
This repository was archived by the owner on Nov 5, 2023. It is now read-only.

Commit 4640d29

Browse files
Add warnings for breaking changes
1 parent 496eee0 commit 4640d29

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pubproxpy/fetcher.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
from time import sleep
77
from urllib.parse import urlencode
8+
from warnings import warn
89

910
from pubproxpy._singleton import Singleton
1011
from pubproxpy.errors import ProxyError, API_ERROR_MAP
@@ -74,11 +75,19 @@ def __init__(self, *, exclude_used=True, **params):
7475
self._shared = _FetcherShared()
7576

7677
def _setup_params(self, params):
77-
"""Checks all of the params and renames to acutally work with the API
78-
"""
78+
"""Checks all of the params and renames to acutally work with the API"""
7979

8080
self._verify_params(params)
8181

82+
if "api_key" in params and "PUBPROXY_API_KEY" in os.environ:
83+
warn(
84+
"The library will be changing the precendence on overriding the API key"
85+
" when it's present as both a parameter and env var. This involves a"
86+
" breaking change (hence the warning) More information is available in"
87+
" this issue"
88+
" https://github.com/LovecraftianHorror/pubproxpy/issues/11"
89+
)
90+
8291
# Try to read api key from environment if not provided
8392
if "api_key" not in params and "PUBPROXY_API_KEY" in os.environ:
8493
params["api_key"] = os.environ["PUBPROXY_API_KEY"]
@@ -174,13 +183,11 @@ def _format_params(self, params):
174183
return params
175184

176185
def drain(self):
177-
"""Returns any proxies remaining in the current list
178-
"""
186+
"""Returns any proxies remaining in the current list"""
179187
return self.get(len(self._proxies))
180188

181189
def get(self, amount=1):
182-
"""Attempts to get `amount` proxies matching the specified params
183-
"""
190+
"""Attempts to get `amount` proxies matching the specified params"""
184191
# Remove any blacklisted proxies from the internal list
185192
# Note: this needs to be done since reused proxies can sit in the
186193
# internal list of separate `ProxyFetcher`s
@@ -219,6 +226,15 @@ def _fetch(self):
219226

220227
# Query the api
221228
resp = requests.get(self._query)
229+
230+
if not resp.ok:
231+
warn(
232+
"The library will be changing how API errors are exposed, so that the"
233+
" different conditions are expressed with different error classes. This"
234+
" will be a breaking change (hence the warning). More information is"
235+
" available in this issue"
236+
" https://github.com/LovecraftianHorror/pubproxpy/issues/11"
237+
)
222238
# And ensure the response is ok
223239
resp.raise_for_status()
224240

tests/test_fetcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class _mock_resp:
1414
def __init__(self, text):
15+
self.ok = True
1516
self.text = text
1617

1718
def raise_for_status(self):

0 commit comments

Comments
 (0)