Skip to content

Commit 4214f9e

Browse files
committed
Clean-up existing functionality
Expand docstring. Clean-up code logic.
1 parent b414108 commit 4214f9e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

domain_utils/domain_utils.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,21 @@ def hostname_subparts(url, include_ps=False, **kwargs):
117117

118118

119119
def get_stripped_url(url, scheme=False):
120-
"""Returns a url stripped to (scheme)?+hostname+path"""
120+
"""
121+
Returns a url stripped to (scheme)?+hostname+path
122+
123+
URL parsing is done using std lib urllib.parse.urlparse
124+
125+
:param url: URL to be parsed
126+
:type url: str
127+
:param scheme: If True, scheme will be prepended in returned result, defaults to False
128+
:type scheme: bool, optional
129+
130+
:return: Returns a url stripped to (scheme)?+hostname+path. Returns empty string if appropriate.
131+
:rtype: str
132+
"""
121133
purl = urlparse(url)
122-
surl = ''
134+
scheme_out = ''
123135
if scheme:
124-
surl += purl.scheme + '://'
125-
try:
126-
surl += purl.hostname + purl.path
127-
except TypeError:
128-
surl += purl.hostname
129-
return surl
136+
scheme_out = f'{purl.scheme}://'
137+
return f'{scheme_out}{purl.hostname}{purl.path}'

0 commit comments

Comments
 (0)