diff options
Diffstat (limited to 'src/hydrilla/url_patterns.py')
-rw-r--r-- | src/hydrilla/url_patterns.py | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/hydrilla/url_patterns.py b/src/hydrilla/url_patterns.py index 115a040..cc68820 100644 --- a/src/hydrilla/url_patterns.py +++ b/src/hydrilla/url_patterns.py @@ -42,6 +42,12 @@ from immutables import Map from .translations import smart_gettext as _ from .exceptions import HaketiloException + +class HaketiloURLException(HaketiloException): + """Type used for exceptions generated when parsing a URL or URL pattern.""" + pass + + default_ports: t.Mapping[str, int] = Map(http=80, https=443, ftp=21) ParsedUrlType = t.TypeVar('ParsedUrlType', bound='ParsedUrl') @@ -131,9 +137,9 @@ def _parse_pattern_or_url( (parse_result.scheme != 'file' and not has_hostname): if is_pattern: msg = _('err.url_pattern_{}.bad').format(orig_url) - raise HaketiloException(msg) + raise HaketiloURLException(msg) else: - raise HaketiloException(_('err.url_{}.bad') .format(url)) + raise HaketiloURLException(_('err.url_{}.bad') .format(url)) # Verify the URL uses a known scheme and extract it. scheme = parse_result.scheme @@ -141,15 +147,15 @@ def _parse_pattern_or_url( if parse_result.scheme not in supported_schemes: if is_pattern: msg = _('err.url_pattern_{}.bad_scheme').format(orig_url) - raise HaketiloException(msg) + raise HaketiloURLException(msg) else: - raise HaketiloException(_('err.url_{}.bad_scheme').format(url)) + raise HaketiloURLException(_('err.url_{}.bad_scheme').format(url)) # Extract and keep information about special pattern schemas used. if is_pattern and orig_url.startswith('http*:'): if parse_result.port: fmt = _('err.url_pattern_{}.special_scheme_port') - raise HaketiloException(fmt.format(orig_url)) + raise HaketiloURLException(fmt.format(orig_url)) # Extract URL's explicit port or deduce the port based on URL's protocol. try: @@ -161,9 +167,9 @@ def _parse_pattern_or_url( if port_out_of_range: if is_pattern: msg = _('err.url_pattern_{}.bad_port').format(orig_url) - raise HaketiloException(msg) + raise HaketiloURLException(msg) else: - raise HaketiloException(_('err.url_{}.bad_port').format(url)) + raise HaketiloURLException(_('err.url_{}.bad_port').format(url)) port = explicit_port or default_ports.get(parse_result.scheme) @@ -185,11 +191,11 @@ def _parse_pattern_or_url( if is_pattern: if parse_result.query: msg = _('err.url_pattern_{}.has_query').format(orig_url) - raise HaketiloException(msg) + raise HaketiloURLException(msg) if parse_result.fragment: msg = _('err.url_pattern_{}.has_frag').format(orig_url) - raise HaketiloException(msg) + raise HaketiloURLException(msg) query = parse_result.query |