Implement URL parsing/unparsing per RFC 3986.

- Section 5.3 Component Recomposition in RFC 3986 makes a
  differentiation between undefined components and empty
  components that the built-in urlparse in python does not. This
  patch deals with that issue and preserves empty queries and
  fragments (despite them being semantically equivalent).