1<?xml version="1.0" encoding="ascii"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3 "DTD/xhtml1-transitional.dtd"> 4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 5<head> 6 <title>googleapiclient.mimeparse</title> 7 <link rel="stylesheet" href="epydoc.css" type="text/css" /> 8 <script type="text/javascript" src="epydoc.js"></script> 9</head> 10 11<body bgcolor="white" text="black" link="blue" vlink="#204080" 12 alink="#204080"> 13<!-- ==================== NAVIGATION BAR ==================== --> 14<table class="navbar" border="0" width="100%" cellpadding="0" 15 bgcolor="#a0c0ff" cellspacing="0"> 16 <tr valign="middle"> 17 <!-- Home link --> 18 <th> <a 19 href="googleapiclient-module.html">Home</a> </th> 20 21 <!-- Tree link --> 22 <th> <a 23 href="module-tree.html">Trees</a> </th> 24 25 <!-- Index link --> 26 <th> <a 27 href="identifier-index.html">Indices</a> </th> 28 29 <!-- Help link --> 30 <th> <a 31 href="help.html">Help</a> </th> 32 33 <th class="navbar" width="100%"></th> 34 </tr> 35</table> 36<table width="100%" cellpadding="0" cellspacing="0"> 37 <tr valign="top"> 38 <td width="100%"> 39 <span class="breadcrumbs"> 40 <a href="googleapiclient-module.html">Package googleapiclient</a> :: 41 Module mimeparse 42 </span> 43 </td> 44 <td> 45 <table cellpadding="0" cellspacing="0"> 46 <!-- hide/show private --> 47 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" 48 onclick="toggle_private();">hide private</a>]</span></td></tr> 49 <tr><td align="right"><span class="options" 50 >[<a href="frames.html" target="_top">frames</a 51 >] | <a href="googleapiclient.mimeparse-module.html" 52 target="_top">no frames</a>]</span></td></tr> 53 </table> 54 </td> 55 </tr> 56</table> 57<!-- ==================== MODULE DESCRIPTION ==================== --> 58<h1 class="epydoc">Module mimeparse</h1><p class="nomargin-top"><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html">source code</a></span></p> 59<pre class="literalblock"> 60MIME-Type Parser 61 62This module provides basic functions for handling mime-types. It can handle 63matching mime-types against a list of media-ranges. See section 14.1 of the 64HTTP specification [RFC 2616] for a complete explanation. 65 66 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 67 68Contents: 69 - parse_mime_type(): Parses a mime-type into its component parts. 70 - parse_media_range(): Media-ranges are mime-types with wild-cards and a 'q' 71 quality parameter. 72 - quality(): Determines the quality ('q') of a mime-type when 73 compared against a list of media-ranges. 74 - quality_parsed(): Just like quality() except the second parameter must be 75 pre-parsed. 76 - best_match(): Choose the mime-type with the highest quality ('q') 77 from a list of candidates. 78 79</pre> 80 81<hr /> 82<div class="fields"> <p><strong>Version:</strong> 83 0.1.3 84 </p> 85 <p><strong>Author:</strong> 86 Joe Gregorio 87 </p> 88 <p><strong>License:</strong> 89 MIT License 90 </p> 91</div><!-- ==================== FUNCTIONS ==================== --> 92<a name="section-Functions"></a> 93<table class="summary" border="1" cellpadding="3" 94 cellspacing="0" width="100%" bgcolor="white"> 95<tr bgcolor="#70b0f0" class="table-header"> 96 <td colspan="2" class="table-header"> 97 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 98 <tr valign="top"> 99 <td align="left"><span class="table-header">Functions</span></td> 100 <td align="right" valign="top" 101 ><span class="options">[<a href="#section-Functions" 102 class="privatelink" onclick="toggle_private();" 103 >hide private</a>]</span></td> 104 </tr> 105 </table> 106 </td> 107</tr> 108<tr> 109 <td width="15%" align="right" valign="top" class="summary"> 110 <span class="summary-type"> </span> 111 </td><td class="summary"> 112 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 113 <tr> 114 <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 /> 115 Parses a mime-type into its component parts.</td> 116 <td align="right" valign="top"> 117 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_mime_type">source code</a></span> 118 119 </td> 120 </tr> 121 </table> 122 123 </td> 124 </tr> 125<tr> 126 <td width="15%" align="right" valign="top" class="summary"> 127 <span class="summary-type"> </span> 128 </td><td class="summary"> 129 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 130 <tr> 131 <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 /> 132 Parse a media-range into its component parts.</td> 133 <td align="right" valign="top"> 134 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_media_range">source code</a></span> 135 136 </td> 137 </tr> 138 </table> 139 140 </td> 141 </tr> 142<tr> 143 <td width="15%" align="right" valign="top" class="summary"> 144 <span class="summary-type"> </span> 145 </td><td class="summary"> 146 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 147 <tr> 148 <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>, 149 <span class="summary-sig-arg">parsed_ranges</span>)</span><br /> 150 Find the best match for a mime-type amongst parsed media-ranges.</td> 151 <td align="right" valign="top"> 152 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#fitness_and_quality_parsed">source code</a></span> 153 154 </td> 155 </tr> 156 </table> 157 158 </td> 159 </tr> 160<tr> 161 <td width="15%" align="right" valign="top" class="summary"> 162 <span class="summary-type"> </span> 163 </td><td class="summary"> 164 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 165 <tr> 166 <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>, 167 <span class="summary-sig-arg">parsed_ranges</span>)</span><br /> 168 Find the best match for a mime-type amongst parsed media-ranges.</td> 169 <td align="right" valign="top"> 170 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality_parsed">source code</a></span> 171 172 </td> 173 </tr> 174 </table> 175 176 </td> 177 </tr> 178<tr> 179 <td width="15%" align="right" valign="top" class="summary"> 180 <span class="summary-type"> </span> 181 </td><td class="summary"> 182 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 183 <tr> 184 <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>, 185 <span class="summary-sig-arg">ranges</span>)</span><br /> 186 Return the quality ('q') of a mime-type against a list of media-ranges.</td> 187 <td align="right" valign="top"> 188 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality">source code</a></span> 189 190 </td> 191 </tr> 192 </table> 193 194 </td> 195 </tr> 196<tr> 197 <td width="15%" align="right" valign="top" class="summary"> 198 <span class="summary-type"> </span> 199 </td><td class="summary"> 200 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 201 <tr> 202 <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>, 203 <span class="summary-sig-arg">header</span>)</span><br /> 204 Return mime-type with the highest quality ('q') from list of candidates.</td> 205 <td align="right" valign="top"> 206 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#best_match">source code</a></span> 207 208 </td> 209 </tr> 210 </table> 211 212 </td> 213 </tr> 214<tr class="private"> 215 <td width="15%" align="right" valign="top" class="summary"> 216 <span class="summary-type"> </span> 217 </td><td class="summary"> 218 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 219 <tr> 220 <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> 221 <td align="right" valign="top"> 222 <span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#_filter_blank">source code</a></span> 223 224 </td> 225 </tr> 226 </table> 227 228 </td> 229 </tr> 230</table> 231<!-- ==================== VARIABLES ==================== --> 232<a name="section-Variables"></a> 233<table class="summary" border="1" cellpadding="3" 234 cellspacing="0" width="100%" bgcolor="white"> 235<tr bgcolor="#70b0f0" class="table-header"> 236 <td colspan="2" class="table-header"> 237 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 238 <tr valign="top"> 239 <td align="left"><span class="table-header">Variables</span></td> 240 <td align="right" valign="top" 241 ><span class="options">[<a href="#section-Variables" 242 class="privatelink" onclick="toggle_private();" 243 >hide private</a>]</span></td> 244 </tr> 245 </table> 246 </td> 247</tr> 248<tr> 249 <td width="15%" align="right" valign="top" class="summary"> 250 <span class="summary-type"> </span> 251 </td><td class="summary"> 252 <a name="__email__"></a><span class="summary-name">__email__</span> = <code title="'joe@bitworking.org'">'joe@bitworking.org'</code> 253 </td> 254 </tr> 255<tr> 256 <td width="15%" align="right" valign="top" class="summary"> 257 <span class="summary-type"> </span> 258 </td><td class="summary"> 259 <a name="__credits__"></a><span class="summary-name">__credits__</span> = <code title="''">''</code> 260 </td> 261 </tr> 262</table> 263<!-- ==================== FUNCTION DETAILS ==================== --> 264<a name="section-FunctionDetails"></a> 265<table class="details" border="1" cellpadding="3" 266 cellspacing="0" width="100%" bgcolor="white"> 267<tr bgcolor="#70b0f0" class="table-header"> 268 <td colspan="2" class="table-header"> 269 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 270 <tr valign="top"> 271 <td align="left"><span class="table-header">Function Details</span></td> 272 <td align="right" valign="top" 273 ><span class="options">[<a href="#section-FunctionDetails" 274 class="privatelink" onclick="toggle_private();" 275 >hide private</a>]</span></td> 276 </tr> 277 </table> 278 </td> 279</tr> 280</table> 281<a name="parse_mime_type"></a> 282<div> 283<table class="details" border="1" cellpadding="3" 284 cellspacing="0" width="100%" bgcolor="white"> 285<tr><td> 286 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 287 <tr valign="top"><td> 288 <h3 class="epydoc"><span class="sig"><span class="sig-name">parse_mime_type</span>(<span class="sig-arg">mime_type</span>)</span> 289 </h3> 290 </td><td align="right" valign="top" 291 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_mime_type">source code</a></span> 292 </td> 293 </tr></table> 294 295 <pre class="literalblock"> 296Parses a mime-type into its component parts. 297 298Carves up a mime-type and returns a tuple of the (type, subtype, params) 299where 'params' is a dictionary of all the parameters for the media range. 300For example, the media range 'application/xhtml;q=0.5' would get parsed 301into: 302 303 ('application', 'xhtml', {'q', '0.5'}) 304 305 306</pre> 307 <dl class="fields"> 308 </dl> 309</td></tr></table> 310</div> 311<a name="parse_media_range"></a> 312<div> 313<table class="details" border="1" cellpadding="3" 314 cellspacing="0" width="100%" bgcolor="white"> 315<tr><td> 316 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 317 <tr valign="top"><td> 318 <h3 class="epydoc"><span class="sig"><span class="sig-name">parse_media_range</span>(<span class="sig-arg">range</span>)</span> 319 </h3> 320 </td><td align="right" valign="top" 321 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#parse_media_range">source code</a></span> 322 </td> 323 </tr></table> 324 325 <pre class="literalblock"> 326Parse a media-range into its component parts. 327 328Carves up a media range and returns a tuple of the (type, subtype, 329params) where 'params' is a dictionary of all the parameters for the media 330range. For example, the media range 'application/*;q=0.5' would get parsed 331into: 332 333 ('application', '*', {'q', '0.5'}) 334 335In addition this function also guarantees that there is a value for 'q' 336in the params dictionary, filling it in with a proper default if 337necessary. 338 339</pre> 340 <dl class="fields"> 341 </dl> 342</td></tr></table> 343</div> 344<a name="fitness_and_quality_parsed"></a> 345<div> 346<table class="details" border="1" cellpadding="3" 347 cellspacing="0" width="100%" bgcolor="white"> 348<tr><td> 349 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 350 <tr valign="top"><td> 351 <h3 class="epydoc"><span class="sig"><span class="sig-name">fitness_and_quality_parsed</span>(<span class="sig-arg">mime_type</span>, 352 <span class="sig-arg">parsed_ranges</span>)</span> 353 </h3> 354 </td><td align="right" valign="top" 355 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#fitness_and_quality_parsed">source code</a></span> 356 </td> 357 </tr></table> 358 359 <pre class="literalblock"> 360Find the best match for a mime-type amongst parsed media-ranges. 361 362Find the best match for a given mime-type against a list of media_ranges 363that have already been parsed by parse_media_range(). Returns a tuple of 364the fitness value and the value of the 'q' quality parameter of the best 365match, or (-1, 0) if no match was found. Just as for quality_parsed(), 366'parsed_ranges' must be a list of parsed media ranges. 367 368</pre> 369 <dl class="fields"> 370 </dl> 371</td></tr></table> 372</div> 373<a name="quality_parsed"></a> 374<div> 375<table class="details" border="1" cellpadding="3" 376 cellspacing="0" width="100%" bgcolor="white"> 377<tr><td> 378 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 379 <tr valign="top"><td> 380 <h3 class="epydoc"><span class="sig"><span class="sig-name">quality_parsed</span>(<span class="sig-arg">mime_type</span>, 381 <span class="sig-arg">parsed_ranges</span>)</span> 382 </h3> 383 </td><td align="right" valign="top" 384 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality_parsed">source code</a></span> 385 </td> 386 </tr></table> 387 388 <pre class="literalblock"> 389Find the best match for a mime-type amongst parsed media-ranges. 390 391Find the best match for a given mime-type against a list of media_ranges 392that have already been parsed by parse_media_range(). Returns the 'q' 393quality parameter of the best match, 0 if no match was found. This function 394bahaves the same as quality() except that 'parsed_ranges' must be a list of 395parsed media ranges. 396 397</pre> 398 <dl class="fields"> 399 </dl> 400</td></tr></table> 401</div> 402<a name="quality"></a> 403<div> 404<table class="details" border="1" cellpadding="3" 405 cellspacing="0" width="100%" bgcolor="white"> 406<tr><td> 407 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 408 <tr valign="top"><td> 409 <h3 class="epydoc"><span class="sig"><span class="sig-name">quality</span>(<span class="sig-arg">mime_type</span>, 410 <span class="sig-arg">ranges</span>)</span> 411 </h3> 412 </td><td align="right" valign="top" 413 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#quality">source code</a></span> 414 </td> 415 </tr></table> 416 417 <pre class="literalblock"> 418Return the quality ('q') of a mime-type against a list of media-ranges. 419 420Returns the quality 'q' of a mime-type when compared against the 421media-ranges in ranges. For example: 422 423>>> quality('text/html','text/*;q=0.3, text/html;q=0.7, 424 text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5') 4250.7 426 427</pre> 428 <dl class="fields"> 429 </dl> 430</td></tr></table> 431</div> 432<a name="best_match"></a> 433<div> 434<table class="details" border="1" cellpadding="3" 435 cellspacing="0" width="100%" bgcolor="white"> 436<tr><td> 437 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 438 <tr valign="top"><td> 439 <h3 class="epydoc"><span class="sig"><span class="sig-name">best_match</span>(<span class="sig-arg">supported</span>, 440 <span class="sig-arg">header</span>)</span> 441 </h3> 442 </td><td align="right" valign="top" 443 ><span class="codelink"><a href="googleapiclient.mimeparse-pysrc.html#best_match">source code</a></span> 444 </td> 445 </tr></table> 446 447 <pre class="literalblock"> 448Return mime-type with the highest quality ('q') from list of candidates. 449 450Takes a list of supported mime-types and finds the best match for all the 451media-ranges listed in header. The value of header must be a string that 452conforms to the format of the HTTP Accept: header. The value of 'supported' 453is a list of mime-types. The list of supported mime-types should be sorted 454in order of increasing desirability, in case of a situation where there is 455a tie. 456 457>>> best_match(['application/xbel+xml', 'text/xml'], 458 'text/*;q=0.5,*/*; q=0.1') 459'text/xml' 460 461</pre> 462 <dl class="fields"> 463 </dl> 464</td></tr></table> 465</div> 466<br /> 467<!-- ==================== NAVIGATION BAR ==================== --> 468<table class="navbar" border="0" width="100%" cellpadding="0" 469 bgcolor="#a0c0ff" cellspacing="0"> 470 <tr valign="middle"> 471 <!-- Home link --> 472 <th> <a 473 href="googleapiclient-module.html">Home</a> </th> 474 475 <!-- Tree link --> 476 <th> <a 477 href="module-tree.html">Trees</a> </th> 478 479 <!-- Index link --> 480 <th> <a 481 href="identifier-index.html">Indices</a> </th> 482 483 <!-- Help link --> 484 <th> <a 485 href="help.html">Help</a> </th> 486 487 <th class="navbar" width="100%"></th> 488 </tr> 489</table> 490<table border="0" cellpadding="0" cellspacing="0" width="100%%"> 491 <tr> 492 <td align="left" class="footer"> 493 Generated by Epydoc 3.0.1 on Fri Jun 14 15:57:27 2019 494 </td> 495 <td align="right" class="footer"> 496 <a target="mainFrame" href="http://epydoc.sourceforge.net" 497 >http://epydoc.sourceforge.net</a> 498 </td> 499 </tr> 500</table> 501 502<script type="text/javascript"> 503 <!-- 504 // Private objects are initially displayed (because if 505 // javascript is turned off then we want them to be 506 // visible); but by default, we want to hide them. So hide 507 // them unless we have a cookie that says to show them. 508 checkCookie(); 509 // --> 510</script> 511</body> 512</html> 513