Skip to content

Commit b89c89a

Browse files
committed
flake8 and clean-up docstring
1 parent 41d0d2f commit b89c89a

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

domain_utils/domain_utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,22 +119,29 @@ def hostname_subparts(url, include_ps=False, **kwargs):
119119
def get_stripped_url(url, scheme=False, non_http_scheme=None):
120120
"""
121121
Returns a url stripped to (scheme)?+netloc+path
122-
For example `https://my.domain.net/a/path/to/a/file.html#anchor?a=1
123-
becomes `my.domain.net/a/path/to/a/file.html`
122+
For example ``https://my.domain.net/a/path/to/a/file.html#anchor?a=1``
123+
becomes ``my.domain.net/a/path/to/a/file.html``
124124
125125
126126
URL parsing is done using std lib urllib.parse.urlparse
127-
Using netloc means that a port is included, for example, if it was in the path.
128-
This makes it cleaner to think about just the scheme and params being stripped.
127+
Using netloc means that a port is included, for example,
128+
if it was in the path.
129+
The method strips just the beginning and end being stripped.
129130
130131
:param url: URL to be parsed
131132
:type url: str
132-
:param scheme: If True, scheme will be prepended in returned result, defaults to False
133+
:param scheme: If True, scheme will be prepended in
134+
returned result, defaults to False
133135
:type scheme: bool, optional
134-
:param non_http_scheme: Action to take if scheme is not http or https e.g. file: or 'about:blank'. If None, return empty string. If 'self', return the original URL. Default is None.
135-
:type non_http_scheme: None or str, optional
136-
137-
:return: Returns a url stripped to (scheme)?+netloc+path. Returns empty string if appropriate.
136+
:param non_http_scheme: Action to take if scheme is not
137+
``http`` or ``https`` e.g. ``file:`` or ``about:blank``.
138+
If None, return empty string.
139+
If ``self``, return the original URL.
140+
Default is None.
141+
:type non_http_scheme: None or ``"self"``, optional
142+
143+
:return: Returns a url stripped to (scheme)?+netloc+path.
144+
Returns empty string if appropriate.
138145
:rtype: str
139146
"""
140147
if non_http_scheme not in [None, 'self']:
@@ -166,4 +173,4 @@ def get_stripped_url(url, scheme=False, non_http_scheme=None):
166173
scheme_out=scheme_out,
167174
netloc_out=netloc_out,
168175
path_out=path_out,
169-
)
176+
)

tests/test_domain_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_get_stripped_url_with_hostname_only_and_scheme():
5858
def test_get_stripped_url_non_http_scheme_none():
5959
url = 'about:blank'
6060
result = du.get_stripped_url(url, non_http_scheme=None)
61-
assert result is ''
61+
assert result == ''
6262

6363

6464
def test_get_stripped_url_non_http_scheme_return_self():
@@ -69,7 +69,7 @@ def test_get_stripped_url_non_http_scheme_return_self():
6969

7070
def test_get_stripped_url_only_accepts_correct_args_for_non_http_scheme():
7171
with pytest.raises(ValueError):
72-
result = du.get_stripped_url('', non_http_scheme='milk')
72+
du.get_stripped_url('', non_http_scheme='milk')
7373

7474

7575
def test_get_stripped_url_returns_port_if_present():

0 commit comments

Comments
 (0)