From 4fe1476bbd895efff0daf711ad76a8ae687c9ce5 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Wed, 7 Jun 2023 13:56:44 -0600 Subject: [PATCH] Handle exact path matches. --- pdpyras.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pdpyras.py b/pdpyras.py index bd7e7c7..910e80e 100644 --- a/pdpyras.py +++ b/pdpyras.py @@ -421,10 +421,16 @@ def canonical_path(base_url: str, url: str): patterns )) # Don't break early if len(patterns) == 1, but require an exact match... + if len(patterns) == 0: raise URLError(f"URL {url} does not match any canonical API path " \ 'supported by this client.') elif len(patterns) > 1: + # If there's multiple matches but one matches exactly, return that. + if url_path in patterns: + return url_path + + # ...otherwise this is ambiguous. raise Exception(f"Ambiguous URL {url} matches more than one " \ "canonical path pattern: "+', '.join(patterns)+'; this is likely ' \ 'a bug.')