Use py_resource module
[python/dscho.git] / Doc / lib / liburlparse.tex
blob36ca949ba63a3b579179a4f29e82fef50f0b4e4e
1 \section{Standard Module \sectcode{urlparse}}
2 \stmodindex{urlparse}
3 \index{WWW}
4 \index{World-Wide Web}
5 \index{URL}
6 \indexii{URL}{parsing}
7 \indexii{relative}{URL}
9 \renewcommand{\indexsubitem}{(in module urlparse)}
11 This module defines a standard interface to break URL strings up in
12 components (addessing scheme, network location, path etc.), to combine
13 the components back into a URL string, and to convert a ``relative
14 URL'' to an absolute URL given a ``base URL''.
16 The module has been designed to match the current Internet draft on
17 Relative Uniform Resource Locators (and discovered a bug in an earlier
18 draft!).
20 It defines the following functions:
22 \begin{funcdesc}{urlparse}{urlstring\optional{\,
23 default_scheme\optional{\, allow_fragments}}}
24 Parse a URL into 6 components, returning a 6-tuple: (addressing
25 scheme, network location, path, parameters, query, fragment
26 identifier). This corresponds to the general structure of a URL:
27 \code{\var{scheme}://\var{netloc}/\var{path};\var{parameters}?\var{query}\#\var{fragment}}.
28 Each tuple item is a string, possibly empty.
29 The components are not broken up in smaller parts (e.g. the network
30 location is a single string), and \% escapes are not expanded.
31 The delimiters as shown above are not part of the tuple items,
32 except for a leading slash in the \var{path} component, which is
33 retained if present.
35 Example:
37 \begin{verbatim}
38 urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
39 \end{verbatim}
41 yields the tuple
43 \begin{verbatim}
44 ('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')
45 \end{verbatim}
47 If the \var{default_scheme} argument is specified, it gives the
48 default addressing scheme, to be used only if the URL string does not
49 specify one. The default value for this argument is the empty string.
51 If the \var{allow_fragments} argument is zero, fragment identifiers
52 are not allowed, even if the URL's addressing scheme normally does
53 support them. The default value for this argument is \code{1}.
54 \end{funcdesc}
56 \begin{funcdesc}{urlunparse}{tuple}
57 Construct a URL string from a tuple as returned by \code{urlparse}.
58 This may result in a slightly different, but equivalent URL, if the
59 URL that was parsed originally had redundant delimiters, e.g. a ? with
60 an empty query (the draft states that these are equivalent).
61 \end{funcdesc}
63 \begin{funcdesc}{urljoin}{base\, url\optional{\, allow_fragments}}
64 Construct a full (``absolute'') URL by combining a ``base URL''
65 (\var{base}) with a ``relative URL'' (\var{url}). Informally, this
66 uses components of the base URL, in particular the addressing scheme,
67 the network location and (part of) the path, to provide missing
68 components in the relative URL.
70 Example:
72 \begin{verbatim}
73 urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')
74 \end{verbatim}
76 yields the string
78 \begin{verbatim}
79 'http://www.cwi.nl/%7Eguido/FAQ.html'
80 \end{verbatim}
82 The \var{allow_fragments} argument has the same meaning as for
83 \code{urlparse}.
84 \end{funcdesc}