aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/url_patterns.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-10-18 17:18:32 +0200
committerWojtek Kosior <koszko@koszko.org>2022-10-18 20:13:45 +0200
commit14eeee3fbc0a839d918149765d2134d05cd14601 (patch)
treedec1ca7dbc8668120e53e8ea45328246313199d1 /src/hydrilla/url_patterns.py
parent76f4b6769d0acaeffbd8e8a003fcbb3e2fbea107 (diff)
downloadhaketilo-hydrilla-14eeee3fbc0a839d918149765d2134d05cd14601.tar.gz
haketilo-hydrilla-14eeee3fbc0a839d918149765d2134d05cd14601.zip
[proxy] upon Haketilo launch automatically open Haketilo landing page in user's default web browser
* The landing page instructs user to configure browser's proxy settings. * It is now possible to choose the IP address to listen on via command line parameter. * The browser launching behavior can be switched off via command line parameter.
Diffstat (limited to 'src/hydrilla/url_patterns.py')
-rw-r--r--src/hydrilla/url_patterns.py24
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