a [•ºffã@shddlZdZdZdZdZdZGdd„deƒZd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„ZdS)éNz1.6.0z Joe Gregoriozjoe@bitworking.orgz MIT LicenseÚc@s eZdZdS)ÚMimeTypeParseExceptionN)Ú__name__Ú __module__Ú __qualname__©rrúm/sparta/input/_build_configuration/image_build+validate/lib/bmcenv/lib64/python3.9/site-packages/mimeparse.pyr srcCsht |¡\}}|dkrd}d|vr,| d¡nd}|r@t|ƒdkrNtd |¡ƒ‚|\}}| ¡| ¡|fS)anParses 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'}) :rtype: (str,str,dict) Ú*z*/*ú/NézCan't parse type "{}")ÚcgiÚ parse_headerÚsplitÚlenrÚformatÚstrip)Ú mime_typeÚ full_typeÚparamsÚ type_partsÚtypeÚsubtyperrrÚparse_mime_types ÿrcCszt|ƒ\}}}| d| dd¡¡z2|drJdt|dƒkrHdksRnd|d<Wntynd|d<Yn0|||fS)a 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. :rtype: (str,str,dict) ÚqÚQNréÚ1)rÚ setdefaultÚpopÚfloatÚ ValueError)ÚrangerrrrrrÚparse_media_range*s&  r"c sÐd}d}t|ƒ\}}}|D]¨\}}‰||dfvp6|dk} ||dfvpJ|dk} | r| r||kr`dpbd} | ||krrdptd7} t‡fdd„| ¡Dƒƒ} | | 7} | t| dd ¡ƒ7} | |kr| }ˆd}qt|ƒ|fS) aÌ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. :rtype: (float,int) éÿÿÿÿrr édé cs0g|](\}}|dkr|ˆvr|ˆ|krd‘qS)rrr)Ú.0ÚkeyÚvalue©rrrÚ ksÿz.quality_and_fitness_parsed..rr)r"ÚsumÚitemsrÚget) rÚ parsed_rangesÚ best_fitnessÚ best_fit_qÚ target_typeÚtarget_subtypeÚ target_paramsrrÚ type_matchÚ subtype_matchÚfitnessÚ param_matchesrr)rÚquality_and_fitness_parsedEs. ÿ þ þ ÿ r8cCst||ƒdS)a©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 behaves the same as quality() except that 'parsed_ranges' must be a list of parsed media ranges. :rtype: float r)r8)rr.rrrÚquality_parsed{s r9cCsdd„| d¡Dƒ}t||ƒS)a]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 :rtype: float cSsg|] }t|ƒ‘qSr©r"©r&Úrrrrr*–ózquality..ú,)rr9)rÚrangesr.rrrÚqualityŠs r@cCstt| d¡ƒ}dd„|Dƒ}g}d}|D]"}| t||ƒ||f¡|d7}q(| ¡|dddrp|ddprdS) ajReturn 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' :rtype: str r>cSsg|] }t|ƒ‘qSrr:r;rrrr*¬r=zbest_match..rrr#r r)Ú _filter_blankrÚappendr8Úsort)Ú supportedÚheaderÚ split_headerÚ parsed_headerÚweighted_matchesÚposrrrrÚ best_match›sý rJccs|D]}| ¡r|VqdS)z'Return all non-empty items in the list.N)r)ÚiÚsrrrrA»srA)r Ú __version__Ú __author__Ú __email__Ú __license__Ú __credits__r rrr"r8r9r@rJrArrrrÚs6