
    cjh6                        d Z ddlmZ ddlZddlZddlmZmZmZ ddl	Z	ddl
mZ ddlmZmZ dZer
ed	   Zed
   Z eh d      Zedhz  Zej*                  Z G d d      Z G d de      Zy)ae  
The MIT License (MIT)

Copyright (c) 2015-2021 Rapptz
Copyright (c) 2021-present Pycord Development

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )annotationsN)TYPE_CHECKINGAnyLiteral   )utils)DiscordExceptionInvalidArgument)Asset)webpjpegjpgpng)r   r   r   r   gif>   r   r   r   r   r   c                  B    e Zd ZU ded<   ded<   d
dZdd	 	 	 	 	 ddZy	)
AssetMixinstrurlz
Any | None_statec                   K   | j                   t        d      | j                   j                  j                  | j                         d{   S 7 w)a  |coro|

        Retrieves the content of this asset as a :class:`bytes` object.

        Returns
        -------
        :class:`bytes`
            The content of the asset.

        Raises
        ------
        DiscordException
            There was no internal connection state.
        HTTPException
            Downloading the asset failed.
        NotFound
            The asset was deleted.
        Nz+Invalid state (no ConnectionState provided))r   r	   httpget_from_cdnr   selfs    @/var/www/html/venv/lib/python3.12/site-packages/discord/asset.pyreadzAssetMixin.read6   sC     & ;;"#PQQ[[%%22488<<<<s   A
AAAT)
seek_beginc               $  K   | j                          d{   }t        |t        j                        r&|j	                  |      }|r|j                  d       |S t        |d      5 }|j	                  |      cddd       S 7 k# 1 sw Y   yxY ww)a6  |coro|

        Saves this asset into a file-like object.

        Parameters
        ----------
        fp: Union[:class:`io.BufferedIOBase`, :class:`os.PathLike`]
            The file-like object to save this attachment to or the filename
            to use. If a filename is passed then a file is created with that
            filename and used instead.
        seek_begin: :class:`bool`
            Whether to seek to the beginning of the file after saving is
            successfully done.

        Returns
        -------
        :class:`int`
            The number of bytes written.

        Raises
        ------
        DiscordException
            There was no internal connection state.
        HTTPException
            Downloading the asset failed.
        NotFound
            The asset was deleted.
        Nr   wb)r   
isinstanceioBufferedIOBasewriteseekopen)r   fpr   datawrittenfs         r   savezAssetMixin.saveN   s|     F YY[ b"++,hhtnG
Nb$ %1wwt}% % !% %s(   BBAB'B8BB	BN)returnbytes)r&   z-str | bytes | os.PathLike | io.BufferedIOBaser   boolr+   int)__name__
__module____qualname____annotations__r   r*        r   r   r   2   s8    	H=8  	+%9+% 	+%
 
+%r4   r   c                     e Zd ZU dZdZded<   dZddd"dZed#d	       Z	ed$d
       Z
e	 	 	 	 	 	 d%d       Ze	 	 	 	 	 	 	 	 d&d       Zed'd       Zed(d       Zed)d       Zed*d       Zed+d       Zed,d       Ze	 	 	 	 	 	 d-d       Zd.dZd/dZd Zd Zd Zed.d       Zed.d       Zd0dZeeed	 	 	 	 	 	 	 d1dZd2dZd3dZ d4d Z!y!)5r   a  Represents a CDN asset on Discord.

    .. container:: operations

        .. describe:: str(x)

            Returns the URL of the CDN asset.

        .. describe:: len(x)

            Returns the length of the CDN asset's URL.

        .. describe:: x == y

            Checks if the asset is equal to another asset.

        .. describe:: x != y

            Checks if the asset is not equal to another asset.

        .. describe:: hash(x)

            Returns the hash of the asset.
    r   _url	_animated_keyztuple[str, ...]	__slots__zhttps://cdn.discordapp.comF)animatedc               <    || _         || _        || _        || _        y Nr6   )r   stater   keyr;   s        r   __init__zAsset.__init__   s    	!	r4   c                L     | || j                    d| dt        |      d      S )Nz/embed/avatars/.pngFr   r?   r;   BASEr   )clsr>   indexs      r   _from_default_avatarzAsset._from_default_avatar   s0    88*OE7$7E
	
 	
r4   c                t    |j                  d      }|rdnd} | || j                   d| d| d| d||      S )	Na_r   r   	/avatars//.
?size=1024rC   
startswithrE   )rF   r>   user_idavatarr;   formats         r   _from_avatarzAsset._from_avatar   sQ    $$T*"88*IgYaxq
K	
 	
r4   c           	     f    |j                  d      }d} | || j                   d| d| d||      S )NrJ   zavatar-decoration-presetsrL   .png?size=1024rC   rO   )rF   r>   rQ   avatar_decorationr;   endpoints         r   _from_avatar_decorationzAsset._from_avatar_decoration   sP     %//5' 	
 88*AhZq):(;>J!	
 	
r4   c                z    |j                  d      }|rdnd} | || j                   d| d| d| d| d
||	      S )
NrJ   r   r   z/guilds/z/users/rK   rM   rN   rC   rO   )rF   r>   guild_id	member_idrR   r;   rS   s          r   _from_guild_avatarzAsset._from_guild_avatar   s]     $$T*"88*HXJgi[	&QRSYRZZde	
 	
r4   c                F     | || j                    d| d| d| d|d      S )NrL   z-icons/rV   FrC   rE   )rF   r>   	object_id	icon_hashpaths        r   
_from_iconzAsset._from_icon   s8    88*AdV79+QykP	
 	
r4   c           	     @     | || j                    d| d| d|d      S )Nz/app-assets/z/store/rV   FrC   r_   )rF   r>   r`   cover_image_hashs       r   _from_cover_imagezAsset._from_cover_image   s4    88*L7;K:LN[ 	
 	
r4   c                    d}d}|dk(  r|j                  d      }|rdnd} | || j                   d| d| d| d| d
||	      S )
NFr   bannersrJ   r   rL   rM   rN   rC   rO   )rF   r>   r[   imagerb   r;   rS   s          r   _from_guild_imagezAsset._from_guild_image   si    9''-H&UEF88*AdV1XJawaxzJ	
 	
r4   c                t    |j                  d      }|rdnd} | || j                   d| d| d| d||      S )	NrJ   r   r   z/icons/rL   rM   rN   rC   rO   )rF   r>   r[   ra   r;   rS   s         r   _from_guild_iconzAsset._from_guild_icon   sQ    ''-"88*GH:Qyk6(*M	
 	
r4   c                L     | || j                    d| dt        |      d      S )Nz%/app-assets/710982414301790216/store/rB   FrC   rD   )rF   r>   banners      r   _from_sticker_bannerzAsset._from_sticker_banner  s1    88*A&NF	
 	
r4   c                t    |j                  d      }|rdnd} | || j                   d| d| d| d||      S )	NrJ   r   r   z	/banners/rL   rM   z	?size=512rC   rO   )rF   r>   rQ   banner_hashr;   rS   s         r   _from_user_bannerzAsset._from_user_banner  sQ    ))$/"88*IgYa}AfXYO	
 	
r4   c           	     @     | || j                    d| d| d|d      S )Nz/guild-events/rL   rB   FrC   r_   )rF   r>   event_id
cover_hashs       r   _from_scheduled_event_coverz!Asset._from_scheduled_event_cover  s4     88*N8*Aj\F	
 	
r4   c                    | j                   S r=   r7   r   s    r   __str__zAsset.__str__"  s    yyr4   c                ,    t        | j                        S r=   )lenr7   r   s    r   __len__zAsset.__len__%  s    499~r4   c                Z    | j                   j                  | j                  d      }d|dS )N z<Asset url=>)r7   replacerE   )r   shortens     r   __repr__zAsset.__repr__(  s+    ))##DIIr2WKq))r4   c                X    t        |t              xr | j                  |j                  k(  S r=   )r    r   r7   )r   others     r   __eq__zAsset.__eq__,  s!    %'CDII,CCr4   c                ,    t        | j                        S r=   )hashr7   r   s    r   __hash__zAsset.__hash__/  s    DIIr4   c                    | j                   S )z(Returns the underlying URL of the asset.rx   r   s    r   r   z	Asset.url2       yyr4   c                    | j                   S )z)Returns the identifying key of the asset.)r9   r   s    r   r?   z	Asset.key7  r   r4   c                    | j                   S )z&Returns whether the asset is animated.)r8   r   s    r   is_animatedzAsset.is_animated<  s    ~~r4   )sizerS   static_formatc               6   t        j                  | j                        }t        j                  j                  |j                        \  }}|t        uru| j                  r1|t        vrt        dt               |j                  | d|       }n8|t        u r0|t        vrt        dt               |j                  | d|       }|t        ur<| j                  s0|t        vrt        dt               |j                  | d|       }|t        ur3t        j                  |      st        d      |j                  |      }n|j                  |j                        }t!        |      }t#        | j$                  || j&                  | j                        S )a  Returns a new asset with the passed components replaced.

        Parameters
        ----------
        size: :class:`int`
            The new size of the asset.
        format: :class:`str`
            The new format to change it to. Must be either
            'webp', 'jpeg', 'jpg', 'png', or 'gif' if it's animated.
        static_format: :class:`str`
            The new format to change it to if the asset isn't animated.
            Must be either 'webp', 'jpeg', 'jpg', or 'png'.

        Returns
        -------
        :class:`Asset`
            The newly updated asset.

        Raises
        ------
        InvalidArgument
            An invalid size or format was passed.
        format must be one of rM   zstatic_format must be one of -size must be a power of 2 between 16 and 4096r   r>   r   r?   r;   )yarlURLr7   osrb   splitextMISSINGr8   VALID_ASSET_FORMATSr
   	with_pathVALID_STATIC_FORMATSr   valid_icon_size
with_queryraw_query_stringr   r   r   r9   )r   r   rS   r   r   rb   _s          r   r   zAsset.replace@  sz   < hhtyy!''""388,a ~~!44)01D0EF  mmtfAfX$67')!55)01E0FG  mmtfAfX$67'$88%34H3IJ  --4&- 9:Cw((.%&UVV..d.+C..!5!56C#h4;;CTYYXXr4   c                  t        j                  |      st        d      t        t	        j
                  | j                        j                  |            }t        | j                  || j                  | j                        S )a[  Returns a new asset with the specified size.

        Parameters
        ----------
        size: :class:`int`
            The new size of the asset.

        Returns
        -------
        :class:`Asset`
            The new updated asset.

        Raises
        ------
        InvalidArgument
            The asset had an invalid size.
        r   r   r   )r   r   r
   r   r   r   r7   r   r   r   r9   r8   )r   r   r   s      r   	with_sizezAsset.with_size  s`    $ $$T*!"QRR$((499%00d0;<4;;CTYYXXr4   c                  | j                   r|t        vr,t        dt               |t        vrt        dt               t	        j
                  | j                        }t        j                  j                  |j                        \  }}t        |j                  | d|       j                  |j                              }t        | j                  || j                   | j                         S )ac  Returns a new asset with the specified format.

        Parameters
        ----------
        format: :class:`str`
            The new format of the asset.

        Returns
        -------
        :class:`Asset`
            The new updated asset.

        Raises
        ------
        InvalidArgument
            The asset has an invalid format.
        r   rM   r   )r8   r   r
   r   r   r   r7   r   rb   r   r   r   r   r   r   r   r9   )r   rS   r   rb   r   s        r   with_formatzAsset.with_format  s    & >>00%(>?R>S&TUU//!$:;O:P"QRRhhtyy!''""388,a#--4&& 23>>s?S?STU4;;CTYYXXr4   c               @    | j                   r| S | j                  |      S )a  Returns a new asset with the specified static format.

        This only changes the format if the underlying asset is
        not animated. Otherwise, the asset is not changed.

        Parameters
        ----------
        format: :class:`str`
            The new static format of the asset.

        Returns
        -------
        :class:`Asset`
            The new updated asset.

        Raises
        ------
        InvalidArgument
            The asset had an invalid format.
        )r8   r   )r   rS   s     r   with_static_formatzAsset.with_static_format  s!    , >>K''r4   N)r   r   r?   r   r;   r-   )rG   r.   r+   r   )rQ   r.   rR   r   r+   r   )rQ   r.   rW   r   r+   r   )r[   r.   r\   r.   rR   r   r+   r   )r`   r.   ra   r   rb   r   r+   r   )r`   r.   re   r   r+   r   )r[   r.   ri   r   rb   r   r+   r   )r[   r.   ra   r   r+   r   )rn   r.   r+   r   )rQ   r.   rq   r   r+   r   )rt   r.   ru   r   r+   r   )r+   r   )r+   r.   )r+   r-   )r   r.   rS   ValidAssetFormatTypesr   ValidStaticFormatTypesr+   r   )r   r.   r+   r   )rS   r   r+   r   )rS   r   r+   r   )"r/   r0   r1   __doc__r:   r2   rE   r@   classmethodrH   rT   rY   r]   rc   rf   rj   rl   ro   rr   rv   ry   r|   r   r   r   propertyr   r?   r   r   r   r   r   r   r3   r4   r   r   r   |   s   2"I  (DFK  
 
 
 
 
 
58
	
 
  

!

.1

;>

	

 

 
 
 
 
 
 
 
 
 
 
 
 
 
!
/2
	
 
*D     (/07>Y >Y &	>Y
 .>Y 
>Y@Y0Y<(r4   r   )r   
__future__r   r!   r   typingr   r   r   r   r~   r   errorsr	   r
   __all__r   r   	frozensetr   r   r   r   r   r3   r4   r   <module>r      s   2 # 	 	 . .   5
$%AB#$GH !?@ *eW4  --G% G%TR(J R(r4   