
    \
j!                         d Z ddlZddlZddlZd Zd Zd Zd ZddZ G d	 d
          Z	 G d d          Z
 G d d          Z G d de          Z G d de          ZdS )z4Various utility functions used internally by pyglet
    Nc                     t          | t                    r| S t          | t                    rt          d | D                       S t          |           S )Nc              3   4   K   | ]}t          |          V  d S N)ord).0cs     E/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/util.py	<genexpr>zasbytes.<locals>.<genexpr>1   s(      ''SVV''''''    )
isinstancebytesstrss    r	   asbytesr   -   sS    !U 	As		 ''Q''''''Qxxr   c                     t          | t                    r| S t          | t                    r'|                     t	          j                              S d S )N)encoding)r   r   r   encodesysgetfilesystemencodingr   s    r	   asbytes_filenamer   6   sR    !U >	As		 >xx!:!<!<x===> >r   c                 b    | dS t          | t                    r| S |                     d          S )N zutf-8)r   r   decoder   s    r	   asstrr   =   s5    yr!S 88Gr   c                 B      G  fdd           } |ddi           S )a  
    Function from jinja2/_compat.py. License: BSD.
    Use it like this::
        class BaseForm:
            pass
        class FormType(type):
            pass
        class Form(with_metaclass(FormType, BaseForm)):
            pass
    This requires a bit of explanation: the basic idea is to make a
    dummy metaclass for one level of class instantiation that replaces
    itself with the actual metaclass.  Because of internal type checks
    we also need to make sure that we downgrade the custom metaclass
    for one level to something closer to type (that's why __call__ and
    __init__ comes back from type etc.).
    This has the advantage over six.with_metaclass of not introducing
    dummy classes into the final MRO.
    c                   8    e Zd Zej        Zej        Z fdZdS )!with_metaclass.<locals>.MetaClassc                 \    |t                               | |d|          S  ||          S )N )type__new__)clsname
this_basesdbasesmetas       r	   r"   z)with_metaclass.<locals>.MetaClass.__new__\   s5    !||Cr15554eQ'''r   N)__name__
__module____qualname__r!   __call____init__r"   )r'   r(   s   r	   	MetaClassr   X   sA        ==	( 	( 	( 	( 	( 	( 	( 	(r   r.   temporary_classNr    )r(   r'   r.   s   `` r	   with_metaclassr0   E   sT    &( ( ( ( ( ( ( (D ( ( ( 9&b111r   debugc                     t          | t                    r| }n t          j                            | d          }|rd }nd }|S )a  Get a debug printer that is enabled based on a boolean input or a pyglet option.
    The debug print function returned should be used in an assert. This way it can be
    optimized out when running python with the -O flag.

    Usage example::

        from pyglet.debug import debug_print
        _debug_media = debug_print('debug_media')

        def some_func():
            assert _debug_media('My debug statement')

    :parameters:
        `enabled_or_options` : bool or str
            If a bool is passed, debug printing is enabled if it is True. If str is passed
            debug printing is enabled if the pyglet option with that name is True.

    :returns: Function for debug printing.
    Fc                      t          | i | dS NT)printargskwargss     r	   _debug_printz!debug_print.<locals>._debug_print~   s    4"6"""4r   c                      dS r4   r    r6   s     r	   r9   z!debug_print.<locals>._debug_print   s    4r   )r   boolpygletoptionsget)enabled_or_optionenabledr9   s      r	   debug_printrA   d   si    ( #T** ?#.$$%6>> 	 	 	 	
	 	 	 r   c                   4    e Zd ZdZd ZddZddZd Zd ZdS )	Codecsz9Utility class for handling adding and querying of codecs.c                 >    g | _         g | _        i | _        i | _        d S r   )	_decoders	_encoders_decoder_extensions_encoder_extensionsselfs    r	   r-   zCodecs.__init__   s&    #% #%   r   Nc                     |rRt           j                            |          d                                         }| j                            |g           S | j        S )zGet a list of all encoders. If a `filename` is provided, only
        encoders supporting that extension will be returned. An empty list
        will be return if no encoders for that extension are available.
           )ospathsplitextlowerrH   r>   rF   )rJ   filename	extensions      r	   get_encoderszCodecs.get_encoders   sS    
  	?((2215;;==I+//	2>>>~r   c                     g |rUt           j                            |          d                                         }| j                            |g           z  fd| j        D             z  S )zGet an ordered list of all decoders. If a `filename` is provided,
        decoders supporting that extension will be ordered first in the list.
        rL   c                     g | ]}|v|	S r    r    )r   edecoderss     r	   
<listcomp>z'Codecs.get_decoders.<locals>.<listcomp>   s#    DDD1!82C2CQ2C2C2Cr   )rM   rN   rO   rP   rG   r>   rE   )rJ   rQ   rR   rW   s      @r	   get_decoderszCodecs.get_decoders   s|      	D((2215;;==I044YCCCHDDDDDDDDr   c                     |                                 D ]f}| j                            |           |                                D ]5}|| j        vr
g | j        |<   | j        |                             |           6gdS )zAdd a decoder module.  The module must define `get_decoders`.  Once
        added, the appropriate decoders defined in the codec will be returned by
        Codecs.get_decoders.
        N)rY   rE   appendget_file_extensionsrG   )rJ   moduledecoderrR   s       r	   add_decoderszCodecs.add_decoders       
 **,, 	D 	DGN!!'***$88:: D D	D$<<<:<D,Y7(3::7CCCCD	D 	Dr   c                     |                                 D ]f}| j                            |           |                                D ]5}|| j        vr
g | j        |<   | j        |                             |           6gdS )zAdd an encoder module.  The module must define `get_encoders`.  Once
        added, the appropriate encoders defined in the codec will be returned by
        Codecs.get_encoders.
        N)rS   rF   r[   r\   rH   )rJ   r]   encoderrR   s       r	   add_encoderszCodecs.add_encoders   r`   r   r   )	r)   r*   r+   __doc__r-   rS   rY   r_   rc   r    r   r	   rC   rC      sw        CC& & &   	 	 	 	
D 
D 
D
D 
D 
D 
D 
Dr   rC   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )Decoderc                     t                      zkReturn a list or tuple of accepted file extensions, e.g. ['.wav', '.ogg']
        Lower-case only.
        NotImplementedErrorrI   s    r	   r\   zDecoder.get_file_extensions        "###r   c                     t                      )zRead and decode the given file object and return an approprite
        pyglet object. Throws DecodeException if there is an error.
        `filename` can be a file type hint.
        ri   )rJ   r7   r8   s      r	   r   zDecoder.decode   s    
 "###r   c                 4    t          | j        j                  S r   hash	__class__r)   rI   s    r	   __hash__zDecoder.__hash__       DN+,,,r   c                 6    | j         j        |j         j        k    S r   rp   r)   rJ   others     r	   __eq__zDecoder.__eq__       ~&%/*BBBr   c                 f    d                     | j        j        |                                           S Nz{0}{1}formatrp   r)   r\   rI   s    r	   __repr__zDecoder.__repr__   '    t~68P8P8R8RSSSr   N)r)   r*   r+   r\   r   rq   rw   r}   r    r   r	   rf   rf      sg        $ $ $$ $ $- - -C C CT T T T Tr   rf   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )Encoderc                     t                      rh   ri   rI   s    r	   r\   zEncoder.get_file_extensions   rk   r   c                     t                      )zEncode the given media type to the given file.  `filename`
        provides a hint to the file format desired.  options are
        encoder-specific, and unknown options should be ignored or
        issue warnings.
        ri   )rJ   mediafilerQ   s       r	   r   zEncoder.encode   s     "###r   c                 4    t          | j        j                  S r   rn   rI   s    r	   rq   zEncoder.__hash__   rr   r   c                 6    | j         j        |j         j        k    S r   rt   ru   s     r	   rw   zEncoder.__eq__   rx   r   c                 f    d                     | j        j        |                                           S rz   r{   rI   s    r	   r}   zEncoder.__repr__   r~   r   N)r)   r*   r+   r\   r   rq   rw   r}   r    r   r	   r   r      sg        $ $ $$ $ $- - -C C CT T T T Tr   r   c                       e Zd ZdZdS )DecodeException
   N)r)   r*   r+   exception_priorityr    r   r	   r   r      s        r   r   c                       e Zd ZdS )EncodeExceptionN)r)   r*   r+   r    r   r	   r   r      s        Dr   r   )r1   )rd   rM   r   r<   r   r   r   r0   rA   rC   rf   r   	Exceptionr   r   r    r   r	   <module>r      sm  H  
			 



   > > >  2 2 2>" " " "J4D 4D 4D 4D 4D 4D 4D 4DnT T T T T T T T0T T T T T T T T2    i   	 	 	 	 	i 	 	 	 	 	r   