home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / u / urlparse < prev    next >
Encoding:
Text File  |  1996-11-14  |  3.2 KB  |  70 lines

  1. <TITLE>urlparse -- Python library reference</TITLE>
  2. Next: <A HREF="../s/sgmllib" TYPE="Next">sgmllib</A>  
  3. Prev: <A HREF="../n/nntplib" TYPE="Prev">nntplib</A>  
  4. Up: <A HREF="../i/internet_and_www" TYPE="Up">Internet and WWW</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>10.7. Standard Module <CODE>urlparse</CODE></H1>
  7. This module defines a standard interface to break URL strings up in
  8. components (addessing scheme, network location, path etc.), to combine
  9. the components back into a URL string, and to convert a ``relative
  10. URL'' to an absolute URL given a ``base URL''.
  11. <P>
  12. The module has been designed to match the current Internet draft on
  13. Relative Uniform Resource Locators (and discovered a bug in an earlier
  14. draft!).
  15. <P>
  16. It defines the following functions:
  17. <P>
  18. <DL><DT><B>urlparse</B> (<VAR>urlstring</VAR>[, <VAR>default_scheme</VAR>[, <VAR>allow_fragments</VAR>]]) -- function of module urlparse<DD>
  19. Parse a URL into 6 components, returning a 6-tuple: (addressing
  20. scheme, network location, path, parameters, query, fragment
  21. identifier).  This corresponds to the general structure of a URL:
  22. <CODE><VAR>scheme</VAR>://<VAR>netloc</VAR>/<VAR>path</VAR>;<VAR>parameters</VAR>?<VAR>query</VAR>#<VAR>fragment</VAR></CODE>.
  23. Each tuple item is a string, possibly empty.
  24. The components are not broken up in smaller parts (e.g. the network
  25. location is a single string), and % escapes are not expanded.
  26. The delimiters as shown above are not part of the tuple items,
  27. except for a leading slash in the <VAR>path</VAR> component, which is
  28. retained if present.
  29. <P>
  30. Example:
  31. <P>
  32. <UL COMPACT><CODE>urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')<P>
  33. </CODE></UL>
  34. yields the tuple
  35. <P>
  36. <UL COMPACT><CODE>('http', 'www.cwi.nl:80', '/%7Eguido/Python.html', '', '', '')<P>
  37. </CODE></UL>
  38. If the <VAR>default_scheme</VAR> argument is specified, it gives the
  39. default addressing scheme, to be used only if the URL string does not
  40. specify one.  The default value for this argument is the empty string.
  41. <P>
  42. If the <VAR>allow_fragments</VAR> argument is zero, fragment identifiers
  43. are not allowed, even if the URL's addressing scheme normally does
  44. support them.  The default value for this argument is <CODE>1</CODE>.
  45. </DL>
  46. <DL><DT><B>urlunparse</B> (<VAR>tuple</VAR>) -- function of module urlparse<DD>
  47. Construct a URL string from a tuple as returned by <CODE>urlparse</CODE>.
  48. This may result in a slightly different, but equivalent URL, if the
  49. URL that was parsed originally had redundant delimiters, e.g. a ? with
  50. an empty query (the draft states that these are equivalent).
  51. </DL>
  52. <DL><DT><B>urljoin</B> (<VAR>base</VAR>, <VAR>url</VAR>[, <VAR>allow_fragments</VAR>]) -- function of module urlparse<DD>
  53. Construct a full (``absolute'') URL by combining a ``base URL''
  54. (<VAR>base</VAR>) with a ``relative URL'' (<VAR>url</VAR>).  Informally, this
  55. uses components of the base URL, in particular the addressing scheme,
  56. the network location and (part of) the path, to provide missing
  57. components in the relative URL.
  58. <P>
  59. Example:
  60. <P>
  61. <UL COMPACT><CODE>urljoin('http://www.cwi.nl/%7Eguido/Python.html', 'FAQ.html')<P>
  62. </CODE></UL>
  63. yields the string
  64. <P>
  65. <UL COMPACT><CODE>'http://www.cwi.nl/%7Eguido/FAQ.html'<P>
  66. </CODE></UL>
  67. The <VAR>allow_fragments</VAR> argument has the same meaning as for
  68. <CODE>urlparse</CODE>.
  69. </DL>
  70.