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

Commit ec4e5b4

Browse files
Raise ValueError on invalid parameters for ProxyFetcher
1 parent d0c1106 commit ec4e5b4

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

pubproxpy/fetcher.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,29 +107,35 @@ def _verify_params(self, params):
107107
"""
108108

109109
# `countries` and `not_countries` are mutually exclusive
110-
assert "countries" not in params or "not_countries" not in params, (
111-
"incompatible parameters, `countries` and `not_countries` are"
112-
" mutually exclusive"
113-
)
110+
if "countries" in params and "not_countries" in params:
111+
raise ValueError(
112+
"incompatible parameters, `countries` and `not_countries` are"
113+
" mutually exclusive"
114+
)
114115

115116
# Verify all params are valid, and satisfy the valid bounds or options
116117
for param, val in params.items():
117-
assert param in self._PARAMS, (
118-
f'invalid parameter "{param}" valid parameters are'
119-
f" {[p for p in self._PARAMS]}"
120-
)
118+
if param not in self._PARAMS:
119+
raise ValueError(
120+
f'unrecognized parameter "{param}" valid parameters are'
121+
f" {[p for p in self._PARAMS]}"
122+
)
121123

122124
if param in self._PARAM_OPTS:
123125
opts = self._PARAM_OPTS[param]
124-
assert (
125-
val in opts
126-
), f'invalid value "{val}" for "{param}" options are {opts}'
126+
if val not in opts:
127+
raise ValueError(
128+
f'invalid value "{val}" for "{param}" options are'
129+
f' {opts}'
130+
)
127131

128132
if param in self._PARAM_BOUNDS:
129133
low, high = self._PARAM_BOUNDS[param]
130-
assert (
131-
low <= val <= high
132-
), f'value "{val}" for "{param}" out of bounds ({low}, {high})'
134+
if val < low or val > high:
135+
raise ValueError(
136+
f'value "{val}" for "{param}" out of bounds'
137+
f" ({low} to {high})"
138+
)
133139

134140
def _rename_params(self, params):
135141
"""Method to rename some params from the API's method to pubproxy's

0 commit comments

Comments
 (0)