
    bf'                         d dl Z d dlZd dlZd dlZd dlmZ ddlmZmZ ddl	m
Z
mZ d Zd Zd Z G d	 d
e          Z G d de          Z G d d          ZdS )    N)decorate   )MastodonVersionErrorMastodonAPIError)IMPL_HAS_BLURHASHblurhashc           	         |                      d          }t          t          j        d|d                                       d                    t          t          j        d|d                                       d                    t          t          j        d|d                                       d                    f}|S )zDParses a semver version string, stripping off "rc" stuff if present..z([0-9]*)r   r      )splitintrematchgroup)version_stringstring_partsversion_partss      ^/home/feoh/.local/pipx/venvs/mastodon-archive/lib/python3.11/site-packages/mastodon/utility.pyparse_version_stringr      s    !'',,LBHZa1177::;;BHZa1177::;;BHZa1177::;;M
     c                  .    t          | t                    S )z<Returns the maximum version of all provided version strings.)key)maxr   )version_stringss    r   max_versionr      s    $89999r   c                       fd}|S )z;Version check decorator. Currently only checks Bigger Than.c                 `    fd}| xj         d d dz  c_         t          | |          S )Nc                    |j         dk    s|j         dk    r}nt          	
          }t          |          \  }}}||j        k    rt	          d| d          ||j        k    r||j        k    rt	          d| d          ||j        k    r1||j        k    r&||j        k    rt	          d| d|j         d           | |g|R i |S )Nnonecreatedz#Version check failed (Need version )z, patch is )version_check_moder   r   mastodon_majorr   mastodon_minormastodon_patch)functionselfargskwargsversionmajorminorpatchcreated_verlast_changed_verreturn_value_vers           r   wrapperz?api_version.<locals>.api_min_version_decorator.<locals>.wrapper$   s$   *f44*i77)GG)*:<LMMG&:7&C&C#ue4..../_U\/_/_/_```d111ed>Q6Q6Q./_U\/_/_/_```d111et?R6R6RW\_c_rWrWr./U\//imi|///  A  A  A8D242226222r   z

        *Added: Mastodon vz, last changed: Mastodon v*)__doc__r   )r&   r1   r.   r/   r0   s     r   api_min_version_decoratorz.api_version.<locals>.api_min_version_decorator#   sa    	3 	3 	3 	3 	3 	3 	3 	w[wwdtwwww'***r    )r.   r/   r0   r4   s   ``` r   api_versionr6   !   s0    + + + + + + +" %$r   c                   $     e Zd Zd Z fdZ xZS )AttribAccessDictc                 >    || v r| |         S t          d|           NzAttribute not found: AttributeErrorr'   attrs     r   __getattr__zAttribAccessDict.__getattr__<   ,    4<<: !?!?!?@@@r   c                     || v rt          d          t          t          |                               ||           d S Nz#Attribute-style access is read only)r<   superr8   __setattr__r'   r>   val	__class__s      r   rD   zAttribAccessDict.__setattr__B   B    4<< !FGGG%%11$<<<<<r   __name__
__module____qualname__r?   rD   __classcell__rG   s   @r   r8   r8   ;   J        A A A= = = = = = = = =r   r8   c                   $     e Zd Zd Z fdZ xZS )AttribAccessListc                 >    || v r| |         S t          d|           r:   r;   r=   s     r   r?   zAttribAccessList.__getattr__M   r@   r   c                     || v rt          d          t          t          |                               ||           d S rB   )r<   rC   rQ   rD   rE   s      r   rD   zAttribAccessList.__setattr__S   rH   r   rI   rN   s   @r   rQ   rQ   L   rO   r   rQ   c                   B    e Zd Zd Zd ZddZd ZddZd	 Zd
 Z	d Z
dS )Mastodonc                     || _         dS )a  
        Set the locale Mastodon will use to generate responses. Valid parameters are all ISO 639-1 (two letter) or, for languages that do
        not have one, 639-3 (three letter) language codes. This affects some error messages (those related to validation) and trends.
        N)lang)r'   rW   s     r   set_languagezMastodon.set_language[   s    
 			r   c                     	 |                      |                                 d                   }d| _        n#  d}d| _        Y nxY wt          |          \  | _        | _        | _        |S )z
        Determine installed Mastodon version and set major, minor and patch (not including RC info) accordingly.

        Returns the version string, possibly including rc info.
        r*   Tz1.0.0F)#_Mastodon__normalize_version_string_Mastodon__instanceversion_check_workedr   r#   r$   r%   )r'   version_strs     r   retrieve_mastodon_versionz"Mastodon.retrieve_mastodon_versionb   st    	.99$//:K:KI:VWWK(,D%%	.!K(-D%%%H\]hHiHiET0$2Es	   47 AFc                     |s|                                   t          |          \  }}}|| j        k    rdS || j        k    r|| j        k    rdS || j        k    r|| j        k    r|| j        k    rdS dS )a   
        Update version info from server and verify that at least the specified version is present.

        If you specify "cached", the version info update part is skipped.

        Returns True if version requirement is satisfied, False if not.
        FT)r^   r   r#   r$   r%   )r'   r]   cachedr+   r,   r-   s         r   verify_minimum_versionzMastodon.verify_minimum_versions   s      	-**,,,2;??ue4&&&5d)))ed6I.I.I5d)))et7J.J.JuW[WjOjOj5tr   c                    |                      ddd          }d|j        v r^t          j                            |j        d                   }|                     |          }t          j                            |          S t          d          )z
        Retrieve the approximate server time

        We parse this from the hopefully present "Date" header, but make no effort to compensate for latency.
        HEAD/T)return_response_objectDatezNo server time in response.)	_Mastodon__api_requestheadersdateutilparserparse_Mastodon__datetime_to_epochdatetimefromtimestampr   )r'   responseserver_time_datetime
epoch_times       r   get_approx_server_timezMastodon.get_approx_server_time   s     %%fc$%OOX%%%#+?#8#89I&9Q#R#R  112FGGJ$22:>>>"#@AAAr      rt   Tc                     t           st          d          t          j        |d                   \  }}|r||d         z  }||d         z  }n|d         }|d         }t          j        |d         |||          }	|	S )a  
        Basic media-dict blurhash decoding.

        out_size is the desired result size in pixels, either absolute or per blurhash
        component (this is the default).

        By default, this function will return the image as linear RGB, ready for further
        scaling operations. If you want to display the image directly, set return_linear
        to False.

        Returns the decoded blurhash image as a three-dimensional list: [height][width][3],
        with the last dimension being RGB colours.

        For further info and tips for advanced usage, refer to the documentation for the
        blurhash module: https://github.com/halcy/blurhash-python
        zITo use the blurhash functions, please install the blurhash Python module.r   r   r   )linear)r   NotImplementedErrorr   
componentsdecode)
r'   
media_dictout_sizesize_per_componentreturn_lineardecode_components_xdecode_components_ydecode_size_xdecode_size_ydecoded_images
             r   decode_blurhashzMastodon.decode_blurhash   s    " ! 	]%[] ] ] 4<3FzR\G]3^3^00 	(/(1+=M/(1+=MM$QKM$QKM !
:(>}ersss r   c                 ,   t          |t                    r?t          |          dk    r,t          |d          rt	          j        |j                  }ndS t	          j        |          }|d         }|d= |d         }|d= |                     |||          S )a3  
        Fetches the next page of results of a paginated request. Pass in the
        previous page in its entirety, or the pagination information dict
        returned as a part of that pages last status ('_pagination_next').

        Returns the next page or None if no further data is available.
        r   _pagination_nextN_pagination_method_pagination_endpoint)
isinstancelistlenhasattrcopydeepcopyr   rg   )r'   previous_pageparamsmethodendpoints        r   
fetch_nextzMastodon.fetch_next   s     mT** 	2s=/A/AQ/F/F}&899 }'EFFt]=11F,-'(01)*!!&(F;;;r   c                 ,   t          |t                    r?t          |          dk    r,t          |d          rt	          j        |j                  }ndS t	          j        |          }|d         }|d= |d         }|d= |                     |||          S )a<  
        Fetches the previous page of results of a paginated request. Pass in the
        previous page in its entirety, or the pagination information dict
        returned as a part of that pages first status ('_pagination_prev').

        Returns the previous page or None if no further data is available.
        r   _pagination_prevNr   r   )r   r   r   r   r   r   r   rg   )r'   	next_pager   r   r   s        r   fetch_previouszMastodon.fetch_previous   s     i&& 	.3y>>Q+>+>y"455 y'ABBt]9--F,-'(01)*!!&(F;;;r   c                     t          j        |          }g }|}|Rt          |          dk    r?|                    |           |                     |          }|t          |          dk    ?|S )a{  
        Fetches all the remaining pages of a paginated request starting from a
        first page and returns the entire set of results (including the first page
        that was passed in) as a big list.

        Be careful, as this might generate a lot of requests, depending on what you are
        fetching, and might cause you to run into rate limits very quickly.
        Nr   )r   r   r   extendr   )r'   
first_page	all_pagescurrent_pages       r   fetch_remainingzMastodon.fetch_remaining   s|     ]:..
	!&3|+<+<q+@+@\***??<88L &3|+<+<q+@+@ r   N)F)rs   TT)rJ   rK   rL   rX   r^   ra   rr   r   r   r   r   r5   r   r   rU   rU   Z   s            "   &B B B&" " " "N< < <0< < <0    r   rU   )r   ri   rm   r   	decoratorr   errorsr   r   compatr   r   r   r   r6   dictr8   r   rQ   rU   r5   r   r   <module>r      s*   
			          : : : : : : : : / / / / / / / /  : : :
% % %4
= 
= 
= 
= 
=t 
= 
= 
="
= 
= 
= 
= 
=t 
= 
= 
=g g g g g g g g g gr   