home *** CD-ROM | disk | FTP | other *** search
- <TITLE>urlparse -- Python library reference</TITLE>
- Next: <A HREF="../s/sgmllib" TYPE="Next">sgmllib</A>
- Prev: <A HREF="../n/nntplib" TYPE="Prev">nntplib</A>
- Up: <A HREF="../i/internet_and_www" TYPE="Up">Internet and WWW</A>
- Top: <A HREF="../t/top" TYPE="Top">Top</A>
- <H1>10.7. Standard Module <CODE>urlparse</CODE></H1>
- This module defines a standard interface to break URL strings up in
- components (addessing scheme, network location, path etc.), to combine
- the components back into a URL string, and to convert a ``relative
- URL'' to an absolute URL given a ``base URL''.
- <P>
- The module has been designed to match the current Internet draft on
- Relative Uniform Resource Locators (and discovered a bug in an earlier
- draft!).
- <P>
- It defines the following functions:
- <P>
- <DL><DT><B>urlparse</B> (<VAR>urlstring</VAR>[, <VAR>default_scheme</VAR>[, <VAR>allow_fragments</VAR>]]) -- function of module urlparse<DD>
- Parse a URL into 6 components, returning a 6-tuple: (addressing
- scheme, network location, path, parameters, query, fragment
- identifier). This corresponds to the general structure of a URL:
- <CODE><VAR>scheme</VAR>://<VAR>netloc</VAR>/<VAR>path</VAR>;<VAR>parameters</VAR>?<VAR>query</VAR>#<VAR>fragment</VAR></CODE>.
- Each tuple item is a string, possibly empty.
- The components are not broken up in smaller parts (e.g. the network
- location is a single string), and % escapes are not expanded.
- The delimiters as shown above are not part of the tuple items,
- except for a leading slash in the <VAR>path</VAR> component, which is
- retained if present.
- <P>
- Example:
- <P>
- <UL COMPACT><CODE>urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')<P>
- </CODE></UL>
- yields the tuple
- <P>
- <UL COMPACT><CODE>('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')<P>
- </CODE></UL>
- If the <VAR>default_scheme</VAR> argument is specified, it gives the
- default addressing scheme, to be used only if the URL string does not
- specify one. The default value for this argument is the empty string.
- <P>
- If the <VAR>allow_fragments</VAR> argument is zero, fragment identifiers
- are not allowed, even if the URL's addressing scheme normally does
- support them. The default value for this argument is <CODE>1</CODE>.
- </DL>
- <DL><DT><B>urlunparse</B> (<VAR>tuple</VAR>) -- function of module urlparse<DD>
- Construct a URL string from a tuple as returned by <CODE>urlparse</CODE>.
- This may result in a slightly different, but equivalent URL, if the
- URL that was parsed originally had redundant delimiters, e.g. a ? with
- an empty query (the draft states that these are equivalent).
- </DL>
- <DL><DT><B>urljoin</B> (<VAR>base</VAR>, <VAR>url</VAR>[, <VAR>allow_fragments</VAR>]) -- function of module urlparse<DD>
- Construct a full (``absolute'') URL by combining a ``base URL''
- (<VAR>base</VAR>) with a ``relative URL'' (<VAR>url</VAR>). Informally, this
- uses components of the base URL, in particular the addressing scheme,
- the network location and (part of) the path, to provide missing
- components in the relative URL.
- <P>
- Example:
- <P>
- <UL COMPACT><CODE>urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')<P>
- </CODE></UL>
- yields the string
- <P>
- <UL COMPACT><CODE>'http://www.cwi.nl/%7Eguido/FAQ.html'<P>
- </CODE></UL>
- The <VAR>allow_fragments</VAR> argument has the same meaning as for
- <CODE>urlparse</CODE>.
- </DL>
-