1 \section{\module{urlparse
} ---
2 Parse URLs into components.
}
3 \declaremodule{standard
}{urlparse
}
5 \modulesynopsis{Parse URLs into components.
}
10 \indexii{URL
}{parsing
}
11 \indexii{relative
}{URL
}
14 This module defines a standard interface to break URL strings up in
15 components (addessing scheme, network location, path etc.), to combine
16 the components back into a URL string, and to convert a ``relative
17 URL'' to an absolute URL given a ``base URL.''
19 The module has been designed to match the Internet RFC on Relative
20 Uniform Resource Locators (and discovered a bug in an earlier
21 draft!). Refer to
\rfc{1808} for details on relative
22 URLs and
\rfc{1738} for information on basic URL syntax.
24 It defines the following functions:
26 \begin{funcdesc
}{urlparse
}{urlstring
\optional{, default_scheme
\optional{, allow_fragments
}}}
27 Parse a URL into
6 components, returning a
6-tuple: (addressing
28 scheme, network location, path, parameters, query, fragment
29 identifier). This corresponds to the general structure of a URL:
30 \code{\var{scheme
}://
\var{netloc
}/
\var{path
};
\var{parameters
}?
\var{query
}\#
\var{fragment
}}.
31 Each tuple item is a string, possibly empty.
32 The components are not broken up in smaller parts (e.g. the network
33 location is a single string), and \% escapes are not expanded.
34 The delimiters as shown above are not part of the tuple items,
35 except for a leading slash in the
\var{path
} component, which is
41 urlparse('http://www.cwi.nl:
80/
%7Eguido/Python.html')
47 ('http', 'www.cwi.nl:
80', '/
%7Eguido/Python.html', '', '', '')
50 If the
\var{default_scheme
} argument is specified, it gives the
51 default addressing scheme, to be used only if the URL string does not
52 specify one. The default value for this argument is the empty string.
54 If the
\var{allow_fragments
} argument is zero, fragment identifiers
55 are not allowed, even if the URL's addressing scheme normally does
56 support them. The default value for this argument is
\code{1}.
59 \begin{funcdesc
}{urlunparse
}{tuple
}
60 Construct a URL string from a tuple as returned by
\code{urlparse()
}.
61 This may result in a slightly different, but equivalent URL, if the
62 URL that was parsed originally had redundant delimiters, e.g. a ? with
63 an empty query (the draft states that these are equivalent).
66 \begin{funcdesc
}{urljoin
}{base, url
\optional{, allow_fragments
}}
67 Construct a full (``absolute'') URL by combining a ``base URL''
68 (
\var{base
}) with a ``relative URL'' (
\var{url
}). Informally, this
69 uses components of the base URL, in particular the addressing scheme,
70 the network location and (part of) the path, to provide missing
71 components in the relative URL.
76 urljoin('http://www.cwi.nl/
%7Eguido/Python.html', 'FAQ.html')
82 'http://www.cwi.nl/
%7Eguido/FAQ.html'
85 The
\var{allow_fragments
} argument has the same meaning as for