Complete worked example
python
from urllib.parse import urlencode
def catalogue_url(country, cursor=None):
if not isinstance(country, str) or country.strip().upper() not in {"US", "IL", "UA", "CA"}:
raise ValueError("country required")
query = {"country": country.strip().upper()}
if cursor is not None:
if not isinstance(cursor, str) or not 1 <= len(cursor) <= 80:
raise ValueError("bounded cursor required")
query["cursor"] = cursor
return "https://jobs.example.test/v1/jobs?" + urlencode(query)- Reasoning
- Build one fixed-origin URL while preserving the boundary between query syntax and caller-supplied values. Compare the stated values and failure boundary before changing the implementation.