I don't think you need the two cases, now. Couldn't you just take the loc_url, and then `urljoin` the rest of `url_parse` (minus the `path`) onto it? Then, if query is empty, it should work the same as the old code, and if query isn't empty, it'll do the right thing.