
    )Jf                     "    d Z d Zd Zd Zd ZdS )znFunctions for generating and parsing HTTP Accept: headers for
supporting server-directed content negotiation.
c                     g }| D ]l}t          |          t          u rd}|}n8|\  }}t          |          }|dk    s|dk    rt          d|z            d|fz  }|                    ||f           m|                                 g }|D ];\  }}|dk    r|                    |           !|                    |d|           <d                    |          S )zFGenerate an accept header value

    [str or (str, float)] -> str
    z1.0       zInvalid preference factor: %rz%0.1fz; q=z, )typestrfloat
ValueErrorappendsortjoin)elementspartselementqsmtypeqchunkss          V/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/accept.pygenerateAcceptHeaderr      s   
 E " "==CBEEHE1aA1uuQ !@1!DEEEA5Bb%[!!!!	JJLLLF 3 35::MM%    MMqq1222299V    c                 "   d |                      d          D             }g }|D ]}d |                     d          D             }|                    d          }d|vr;|                     dd          \  }}|D ]G}d|v rA|                     dd          \  }	}
|	d	k    r"	 t          |
          } n# t          $ r Y Cw xY wHd
}|                    |||f           |                                 |                                 d |D             S )zParse an accept header, ignoring any accept-extensions

    returns a list of tuples containing main MIME type, MIME subtype,
    and quality markdown.

    str -> [(str, str, float)]
    c                 6    g | ]}|                                 S  strip).0chunks     r   
<listcomp>z%parseAcceptHeader.<locals>.<listcomp>-   s     :::ekkmm:::r   ,c                 6    g | ]}|                                 S r   r   )r   ss     r   r   z%parseAcceptHeader.<locals>.<listcomp>0   s     555q555r   ;r   /r   =r   g      ?c                      g | ]\  }}}|||fS r   r   )r   r   mainsubs       r   r   z%parseAcceptHeader.<locals>.<listcomp>J   s$    888~4T3N888r   )splitpopr   r   r	   r
   reverse)valuer   acceptr   r   r   r%   r&   extkvr   s               r   parseAcceptHeaderr/   %   sK    ;:S)9)9:::FF & &55EKK$4$4555		!eKKQ''	c 	 	Cczzyya((188!!HH%    Aq$n%%%%
KKMMM
NN888888s    B11
B>=B>c                     | sd}nd}i }i }| D ]v\  }}}|dk    rt          ||          }|dk    r(t          |                    |d          |          ||<   Kt          |                    ||fd          |          |||f<   wg }d}	|D ]d}
|
                    d          \  }}||f|v r|||f         }n|                    ||          }|r!|                    d|z
  |	||
f           |	dz  }	e|                                 d |D             S )a  Given the result of parsing an Accept: header, and the
    available MIME types, return the acceptable types with their
    quality markdowns.

    For example:

    >>> acceptable = parseAcceptHeader('text/html, text/plain; q=0.5')
    >>> matchTypes(acceptable, ['text/plain', 'text/html', 'image/jpeg'])
    [('text/html', 1.0), ('text/plain', 0.5)]


    Type signature: ([(str, str, float)], [str]) -> [(str, float)]
    r   r   *r"   c                      g | ]\  }}}}||fS r   r   )r   _r   r   s       r   r   zmatchTypes.<locals>.<listcomp>z   s%    ===+Aq!UUAJ===r   )maxgetr'   r	   r
   )accept_types
have_typesdefault
match_main	match_subr%   r&   r   accepted_listorder_maintainerr   s              r   
matchTypesr=   M   sj     JI& K KsA3;;'1ooGCZZ":>>$#:#:A>>Jt%(c{A)F)F%J%JItSk""M 	" 	"KK$$	c#;)##4+&AAtW--A 	"  !a%)91e!DEEE!==}====r   c                 X    t          |           }t          ||          }d |D             S )a	  Parse the accept header and return a list of available types in
    preferred order. If a type is unacceptable, it will not be in the
    resulting list.

    This is a convenience wrapper around matchTypes and
    parseAcceptHeader.

    (str, [str]) -> [str]
    c                     g | ]\  }}|S r   r   )r   r   r3   s      r   r   z!getAcceptable.<locals>.<listcomp>   s    ...juaE...r   )r/   r=   )accept_headerr7   accepted	preferreds       r   getAcceptablerC   }   s4     !//H8Z00I..I....r   N)__doc__r   r/   r=   rC   r   r   r   <module>rE      sW    
  >%9 %9 %9P-> -> ->`/ / / / /r   