Skip to content

Commit

Permalink
Make class gc3libs.url.Url fully compatible with Python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardomurri committed Jan 11, 2018
1 parent 1a6dea7 commit 2be4826
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gc3libs/url.py
Expand Up @@ -168,6 +168,14 @@ def __new__(cls, urlstring=None, force_abs=True,
try:
urldata = urlparse.urlsplit(
urlstring, scheme=scheme, allow_fragments=True)
# Python 2.6 parses fragments only for http(s),
# for any other scheme, the fragment is returned as
# part of the path...
if '#' in urldata.path:
path_, fragment_ = urldata.path.split('#')
urldata = urlparse.SplitResult(
urldata.scheme, urldata.netloc,
path_, urldata.query, fragment_)
if urldata.scheme == 'file' and not os.path.isabs(
urldata.path) and force_abs:
urldata = urlparse.urlsplit(
Expand All @@ -183,10 +191,10 @@ def __new__(cls, urlstring=None, force_abs=True,
urldata.password or password,
urldata.fragment or fragment,
))
except (ValueError, TypeError, AttributeError) as ex:
except (ValueError, TypeError, AttributeError) as err:
raise ValueError(
"Cannot parse string '%s' as a URL: %s: %s" %
(urlstring, ex.__class__.__name__, str(ex)))
"Cannot parse string '%s' as a URL: %s: %s"
% (urlstring, err.__class__.__name__, err))
else:
# no `urlstring`, use kwd arguments
return tuple.__new__(cls, (
Expand Down

0 comments on commit 2be4826

Please sign in to comment.