Pyzotero: a Python client for the Zotero API pyzotero.readthedocs.io
zotero

Merge pull request #252 from urschrei/shugel/push-opoqnovulwwr

Replace manual URL building

authored by urschrei.eurosky.social and committed by

GitHub 4b57669a ad912326

+6 -7
+5 -6
src/pyzotero/zotero.py
··· 51 51 def build_url(base_url, path, args_dict=None): 52 52 """Build a valid URL so we don't have to worry about string concatenation errors and 53 53 leading / trailing slashes etc. 54 - Returns a list in the structure of urlparse.ParseResult 55 54 """ 56 55 base_url = base_url.removesuffix("/") 57 - url_parts = list(urlparse(base_url)) 58 - url_parts[2] += path 56 + parsed = urlparse(base_url) 57 + new_path = str(PurePosixPath(parsed.path) / path.removeprefix("/")) 59 58 if args_dict: 60 - url_parts[4] = urlencode(args_dict) 61 - return urlunparse(url_parts) 59 + return urlunparse(parsed._replace(path=new_path, query=urlencode(args_dict))) 60 + return urlunparse(parsed._replace(path=new_path)) 62 61 63 62 64 63 def merge_params(url, params): ··· 513 512 try: 514 513 for key, value in self.request.links.items(): 515 514 parsed = urlparse(value["url"]) 516 - fragment = f"{parsed[2]}?{parsed[4]}" 515 + fragment = urlunparse(("", "", parsed.path, "", parsed.query, "")) 517 516 extracted[key] = fragment 518 517 # add a 'self' link 519 518 parsed = urlparse(str(self.self_link))
+1 -1
tests/test_zotero.py
··· 413 413 zot.tags() 414 414 self.assertEqual(zot.links["next"], "/users/436/items/top?limit=1&start=1") 415 415 self.assertEqual(zot.links["last"], "/users/436/items/top?limit=1&start=2319") 416 - self.assertEqual(zot.links["alternate"], "/users/436/items/top?") 416 + self.assertEqual(zot.links["alternate"], "/users/436/items/top") 417 417 418 418 @httpretty.activate 419 419 def testParseLinkHeadersPreservesAllParameters(self):