What's the pythonic way of using a source url to create a new url with different path and scheme?
<p>Say I have a url that or may not be HTTPS, and who's host name I don't control, but follows a format like:
  <a href="http://example.com/special/content" rel="nofollow">http://example.com/special/content</a>    [OR]
  <a href="https://example.com/special/content" rel="nofollow">https://example.com/special/content</a></p>

<p>Using Python what would be the pythonic way of changing scheme to https and path to /something/else</p>

<p>My current approach is:</p>

<pre><code>from urlparse import urlsplit, urljoin, urlunsplit
currenturl = "http://example.com/some/content"
parts = list(urlsplit(urljoin(currenturl, "/something/else")))
parts[0]="https"
newurl = urlunsplit(parts)
</code></pre>

<p>Any suggestions ?</p>

<hr>

<p>Suggestion (from @ignacio-vazquez-abrams)</p>

<pre><code>from urlparse import urlparse, urljoin, urlunparse
currenturl = "http://example.com/some/content"
parts = list(urlparse(currenturl))
parts[0]="https"
parts[2]="/something/else"  # If only path needed changing (or see bellow...)
newurl = urlunparse(parts)
newurl = urljoin(newurl, "/something/else") # If we need to rewrite everything
                                            # after network loc
</code></pre>
