You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
513 lines
19 KiB
513 lines
19 KiB
<?xml version="1.0" encoding="ascii"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<title>googleapiclient.mimeparse</title>
|
|
<link rel="stylesheet" href="epydoc.css" type="text/css" />
|
|
<script type="text/javascript" src="epydoc.js"></script>
|
|
</head>
|
|
|
|
<body bgcolor="white" text="black" link="blue" vlink="#204080"
|
|
alink="#204080">
|
|
<!-- ==================== NAVIGATION BAR ==================== -->
|
|
<table class="navbar" border="0" width="100%" cellpadding="0"
|
|
bgcolor="#a0c0ff" cellspacing="0">
|
|
<tr valign="middle">
|
|
<!-- Home link -->
|
|
<th> <a
|
|
href="googleapiclient-module.html">Home</a> </th>
|
|
|
|
<!-- Tree link -->
|
|
<th> <a
|
|
href="module-tree.html">Trees</a> </th>
|
|
|
|
<!-- Index link -->
|
|
<th> <a
|
|
href="identifier-index.html">Indices</a> </th>
|
|
|
|
<!-- Help link -->
|
|
<th> <a
|
|
href="help.html">Help</a> </th>
|
|
|
|
<th class="navbar" width="100%"></th>
|
|
</tr>
|
|
</table>
|
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
<tr valign="top">
|
|
<td width="100%">
|
|
<span class="breadcrumbs">
|
|
<a href="googleapiclient-module.html">Package googleapiclient</a> ::
|
|
Module mimeparse
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<table cellpadding="0" cellspacing="0">
|
|
<!-- hide/show private -->
|
|
<tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
|
|
onclick="toggle_private();">hide private</a>]</span></td></tr>
|
|
<tr><td align="right"><span class="options"
|
|
>[<a href="frames.html" target="_top">frames</a
|
|
>] | <a href="googleapiclient.mimeparse-module.html"
|
|
target="_top">no frames</a>]</span></td></tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<!-- ==================== MODULE DESCRIPTION ==================== -->
|
|
<h1 class="epydoc">Module mimeparse</h1><p class="nomargin-top"><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html">source code</a></span></p>
|
|
<pre class="literalblock">
|
|
MIME-Type Parser
|
|
|
|
This module provides basic functions for handling mime-types. It can handle
|
|
matching mime-types against a list of media-ranges. See section 14.1 of the
|
|
HTTP specification [RFC 2616] for a complete explanation.
|
|
|
|
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
|
|
|
|
Contents:
|
|
- parse_mime_type(): Parses a mime-type into its component parts.
|
|
- parse_media_range(): Media-ranges are mime-types with wild-cards and a 'q'
|
|
quality parameter.
|
|
- quality(): Determines the quality ('q') of a mime-type when
|
|
compared against a list of media-ranges.
|
|
- quality_parsed(): Just like quality() except the second parameter must be
|
|
pre-parsed.
|
|
- best_match(): Choose the mime-type with the highest quality ('q')
|
|
from a list of candidates.
|
|
|
|
</pre>
|
|
|
|
<hr />
|
|
<div class="fields"> <p><strong>Version:</strong>
|
|
0.1.3
|
|
</p>
|
|
<p><strong>Author:</strong>
|
|
Joe Gregorio
|
|
</p>
|
|
<p><strong>License:</strong>
|
|
MIT License
|
|
</p>
|
|
</div><!-- ==================== FUNCTIONS ==================== -->
|
|
<a name="section-Functions"></a>
|
|
<table class="summary" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr bgcolor="#70b0f0" class="table-header">
|
|
<td colspan="2" class="table-header">
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr valign="top">
|
|
<td align="left"><span class="table-header">Functions</span></td>
|
|
<td align="right" valign="top"
|
|
><span class="options">[<a href="#section-Functions"
|
|
class="privatelink" onclick="toggle_private();"
|
|
>hide private</a>]</span></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#parse_mime_type" class="summary-sig-name">parse_mime_type</a>(<span class="summary-sig-arg">mime_type</span>)</span><br />
|
|
Parses a mime-type into its component parts.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_mime_type">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#parse_media_range" class="summary-sig-name">parse_media_range</a>(<span class="summary-sig-arg">range</span>)</span><br />
|
|
Parse a media-range into its component parts.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_media_range">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#fitness_and_quality_parsed" class="summary-sig-name">fitness_and_quality_parsed</a>(<span class="summary-sig-arg">mime_type</span>,
|
|
<span class="summary-sig-arg">parsed_ranges</span>)</span><br />
|
|
Find the best match for a mime-type amongst parsed media-ranges.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#fitness_and_quality_parsed">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#quality_parsed" class="summary-sig-name">quality_parsed</a>(<span class="summary-sig-arg">mime_type</span>,
|
|
<span class="summary-sig-arg">parsed_ranges</span>)</span><br />
|
|
Find the best match for a mime-type amongst parsed media-ranges.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality_parsed">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#quality" class="summary-sig-name">quality</a>(<span class="summary-sig-arg">mime_type</span>,
|
|
<span class="summary-sig-arg">ranges</span>)</span><br />
|
|
Return the quality ('q') of a mime-type against a list of media-ranges.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a href="googleapiclient.mimeparse-module.html#best_match" class="summary-sig-name">best_match</a>(<span class="summary-sig-arg">supported</span>,
|
|
<span class="summary-sig-arg">header</span>)</span><br />
|
|
Return mime-type with the highest quality ('q') from list of candidates.</td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#best_match">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
<tr class="private">
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr>
|
|
<td><span class="summary-sig"><a name="_filter_blank"></a><span class="summary-sig-name">_filter_blank</span>(<span class="summary-sig-arg">i</span>)</span></td>
|
|
<td align="right" valign="top">
|
|
<span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#_filter_blank">source code</a></span>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<!-- ==================== VARIABLES ==================== -->
|
|
<a name="section-Variables"></a>
|
|
<table class="summary" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr bgcolor="#70b0f0" class="table-header">
|
|
<td colspan="2" class="table-header">
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr valign="top">
|
|
<td align="left"><span class="table-header">Variables</span></td>
|
|
<td align="right" valign="top"
|
|
><span class="options">[<a href="#section-Variables"
|
|
class="privatelink" onclick="toggle_private();"
|
|
>hide private</a>]</span></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<a name="__email__"></a><span class="summary-name">__email__</span> = <code title="'joe@bitworking.org'">'joe@bitworking.org'</code>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="15%" align="right" valign="top" class="summary">
|
|
<span class="summary-type"> </span>
|
|
</td><td class="summary">
|
|
<a name="__credits__"></a><span class="summary-name">__credits__</span> = <code title="''">''</code>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<!-- ==================== FUNCTION DETAILS ==================== -->
|
|
<a name="section-FunctionDetails"></a>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr bgcolor="#70b0f0" class="table-header">
|
|
<td colspan="2" class="table-header">
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr valign="top">
|
|
<td align="left"><span class="table-header">Function Details</span></td>
|
|
<td align="right" valign="top"
|
|
><span class="options">[<a href="#section-FunctionDetails"
|
|
class="privatelink" onclick="toggle_private();"
|
|
>hide private</a>]</span></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<a name="parse_mime_type"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">parse_mime_type</span>(<span class="sig-arg">mime_type</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_mime_type">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Parses a mime-type into its component parts.
|
|
|
|
Carves up a mime-type and returns a tuple of the (type, subtype, params)
|
|
where 'params' is a dictionary of all the parameters for the media range.
|
|
For example, the media range 'application/xhtml;q=0.5' would get parsed
|
|
into:
|
|
|
|
('application', 'xhtml', {'q', '0.5'})
|
|
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<a name="parse_media_range"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">parse_media_range</span>(<span class="sig-arg">range</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_media_range">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Parse a media-range into its component parts.
|
|
|
|
Carves up a media range and returns a tuple of the (type, subtype,
|
|
params) where 'params' is a dictionary of all the parameters for the media
|
|
range. For example, the media range 'application/*;q=0.5' would get parsed
|
|
into:
|
|
|
|
('application', '*', {'q', '0.5'})
|
|
|
|
In addition this function also guarantees that there is a value for 'q'
|
|
in the params dictionary, filling it in with a proper default if
|
|
necessary.
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<a name="fitness_and_quality_parsed"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">fitness_and_quality_parsed</span>(<span class="sig-arg">mime_type</span>,
|
|
<span class="sig-arg">parsed_ranges</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#fitness_and_quality_parsed">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Find the best match for a mime-type amongst parsed media-ranges.
|
|
|
|
Find the best match for a given mime-type against a list of media_ranges
|
|
that have already been parsed by parse_media_range(). Returns a tuple of
|
|
the fitness value and the value of the 'q' quality parameter of the best
|
|
match, or (-1, 0) if no match was found. Just as for quality_parsed(),
|
|
'parsed_ranges' must be a list of parsed media ranges.
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<a name="quality_parsed"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">quality_parsed</span>(<span class="sig-arg">mime_type</span>,
|
|
<span class="sig-arg">parsed_ranges</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality_parsed">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Find the best match for a mime-type amongst parsed media-ranges.
|
|
|
|
Find the best match for a given mime-type against a list of media_ranges
|
|
that have already been parsed by parse_media_range(). Returns the 'q'
|
|
quality parameter of the best match, 0 if no match was found. This function
|
|
bahaves the same as quality() except that 'parsed_ranges' must be a list of
|
|
parsed media ranges.
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<a name="quality"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">quality</span>(<span class="sig-arg">mime_type</span>,
|
|
<span class="sig-arg">ranges</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Return the quality ('q') of a mime-type against a list of media-ranges.
|
|
|
|
Returns the quality 'q' of a mime-type when compared against the
|
|
media-ranges in ranges. For example:
|
|
|
|
>>> quality('text/html','text/*;q=0.3, text/html;q=0.7,
|
|
text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5')
|
|
0.7
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<a name="best_match"></a>
|
|
<div>
|
|
<table class="details" border="1" cellpadding="3"
|
|
cellspacing="0" width="100%" bgcolor="white">
|
|
<tr><td>
|
|
<table width="100%" cellpadding="0" cellspacing="0" border="0">
|
|
<tr valign="top"><td>
|
|
<h3 class="epydoc"><span class="sig"><span class="sig-name">best_match</span>(<span class="sig-arg">supported</span>,
|
|
<span class="sig-arg">header</span>)</span>
|
|
</h3>
|
|
</td><td align="right" valign="top"
|
|
><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#best_match">source code</a></span>
|
|
</td>
|
|
</tr></table>
|
|
|
|
<pre class="literalblock">
|
|
Return mime-type with the highest quality ('q') from list of candidates.
|
|
|
|
Takes a list of supported mime-types and finds the best match for all the
|
|
media-ranges listed in header. The value of header must be a string that
|
|
conforms to the format of the HTTP Accept: header. The value of 'supported'
|
|
is a list of mime-types. The list of supported mime-types should be sorted
|
|
in order of increasing desirability, in case of a situation where there is
|
|
a tie.
|
|
|
|
>>> best_match(['application/xbel+xml', 'text/xml'],
|
|
'text/*;q=0.5,*/*; q=0.1')
|
|
'text/xml'
|
|
|
|
</pre>
|
|
<dl class="fields">
|
|
</dl>
|
|
</td></tr></table>
|
|
</div>
|
|
<br />
|
|
<!-- ==================== NAVIGATION BAR ==================== -->
|
|
<table class="navbar" border="0" width="100%" cellpadding="0"
|
|
bgcolor="#a0c0ff" cellspacing="0">
|
|
<tr valign="middle">
|
|
<!-- Home link -->
|
|
<th> <a
|
|
href="googleapiclient-module.html">Home</a> </th>
|
|
|
|
<!-- Tree link -->
|
|
<th> <a
|
|
href="module-tree.html">Trees</a> </th>
|
|
|
|
<!-- Index link -->
|
|
<th> <a
|
|
href="identifier-index.html">Indices</a> </th>
|
|
|
|
<!-- Help link -->
|
|
<th> <a
|
|
href="help.html">Help</a> </th>
|
|
|
|
<th class="navbar" width="100%"></th>
|
|
</tr>
|
|
</table>
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
|
|
<tr>
|
|
<td align="left" class="footer">
|
|
Generated by Epydoc 3.0.1 on Fri Jun 14 15:57:27 2019
|
|
</td>
|
|
<td align="right" class="footer">
|
|
<a target="mainFrame" href="http://epydoc.sourceforge.net"
|
|
>http://epydoc.sourceforge.net</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<script type="text/javascript">
|
|
<!--
|
|
// Private objects are initially displayed (because if
|
|
// javascript is turned off then we want them to be
|
|
// visible); but by default, we want to hide them. So hide
|
|
// them unless we have a cookie that says to show them.
|
|
checkCookie();
|
|
// -->
|
|
</script>
|
|
</body>
|
|
</html>
|