dummy-link

URLParse

Parse URL strings into components and re-create the URL string back from components.

Readme

URLParse.jl

This package has been deprecated in favour of JuliaWeb/URIParser.jl.

As of Julia 0.4 this package will no longer be installable through Pkg.add. Please convert your code according.


A parser to parse URL string representation into components and re-create the URL string back from components. Modeled after the python urlparse library. A URL can be of the form:

scheme://netloc/path;parameters?query#fragment

Also has methods to escape and unescape strings for URLs and form data. (source: https://github.com/dirk/HTTP.jl/blob/master/src/HTTP/Util.jl)

Build Status

URLComponents

The parsed URL components are stored and returned in an instance of URLComponents.

Component fields and accessor methods:

  • scheme
  • netloc
  • url
  • params
  • query
  • fragment
  • username(u::URLComponents) : Extracts username from the netloc field. Returns a string if present or nothing otherwise.
  • password(u::URLComponents) : Extracts password from the netloc field. Returns a string if present or nothing otherwise.
  • hostname(u::URLComponents) : Extracts hostname from the netloc field. Returns a string if present or nothing otherwise.
  • port(u::URLComponents) : Extracts port from the netloc field. Returns an int if present or nothing otherwise.

There is an internal cache of URLComponents maintained as an optimization for repeated use of same URL string. Therefore, the URLComponents instance returned from urlparse must not be modified. A copy may be created to be modified instrad.

APIs

urlparse(url::String)
Parse a URL into 6 components: scheme://netloc/path;params?query#fragment. Returns an instance of URLComponents.
urlunparse(u::URLComponents)
Join back 6 components of the URL back to recreate a URL string.
urldefrag(url::String)
Removes any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment (empty string if none were there).
escape(str::String)
Returns an escaped form of the string that can be used as a URL parameter
unescape(str::String)
Performs the reverse operation of escape
escape_form(str::String)
Returns an escaped string that can be used in a HTML form submit
unescape_form(str::String)
Performs the reverse operation of escape_form

TODO

  • parse_query_string: to create a list/dict of name-value pairs
  • urljoin: to overlay a relative url on a base url
  • is_valid: validate URL string to be conforming to scheme rules

NOTE

In addition to the methods documented above, the following are also exported, in anticipation of being useful elsewhere.

  • urlsplit and urlunsplit: Similar to urlparse and urlunparse, but ignores the 'parameters' part of the url. That is, assumes URLs of form scheme://netloc/path?query#fragment.

First Commit

05/01/2013

Last Touched

over 6 years ago

Commits

25 commits

Requires:

Used By: