
    i)                     d    S SK r S SKrSSKJrJr  SSKJrJrJrJ	r	   " S S5      r
 " S S5      rg)	    N   )TelegraphExceptionRetryAfterError)html_to_nodesnodes_to_htmlFilesOpener
json_dumpsc                   6    \ rS rSrSrSrSS jrS	S jrS rSr	g)
TelegraphApi
   zTelegraph API Client

:param access_token: access_token
:type access_token: str

:param domain: domain (e.g. alternative mirror graph.org)
)access_tokendomainsessionNc                 P    Xl         X l        [        R                  " 5       U l        g N)r   r   httpxAsyncClientr   selfr   r   s      :/app/mltbenv/lib/python3.13/site-packages/telegraph/aio.py__init__TelegraphApi.__init__   s    (((*    c                 .  #    Ub  UR                  5       O0 nSU;  a   U R                  (       a  U R                  US'   U R                  R                  SR	                  U R
                  X5      US9I S h  vN R                  5       nUR                  S5      (       a  US   $ UR                  S5      n[        U[        5      (       a?  UR                  S5      (       a)  [        UR                  SS	5      S
   5      n[        U5      e[        U5      e N7f)Nr   zhttps://api.{}/{}/{})dataokresulterrorFLOOD_WAIT__r   )copyr   r   postformatr   jsonget
isinstancestr
startswithintrsplitr   r   )r   methodvaluespathresponser   retry_afters          r   r,   TelegraphApi.method   s     "("4"'D,=,=%)%6%6F>",,++"))$++vD , 
 
 46 	
 <<H%%W%eS!!e&6&6}&E&Eell32267K!+..$U++
s   A3D5D6BDc                 0  #    [        U5       nU R                  R                  SR                  U R                  5      US9I Sh  vN R                  5       nSSS5        [        W[        5      (       a  US   R                  S5      nOUR                  S5      nU(       a_  [        U[        5      (       a?  UR                  S5      (       a)  [        UR                  SS5      S	   5      n[        U5      e[        U5      eU$  N! , (       d  f       N= f7f)
Upload file. NOT PART OF OFFICIAL API, USE AT YOUR OWN RISK
    Returns a list of dicts with `src` key.
    Allowed only .jpg, .jpeg, .png, .gif and .mp4 files.

:param f: filename or file-like object.
:type f: file, str or list
zhttps://{}/upload)filesNr   r   r   r    r   r!   )r   r   r#   r$   r   r%   r'   listr&   r(   r)   r*   r+   r   r   )r   fr4   r/   r   r0   s         r   upload_fileTelegraphApi.upload_file/   s      ^u"ll//#**4;;7 0   tv   h%%QKOOG,ELL)E%%%%*:*:=*I*I!%,,s1"5b"9:%k22(//# ^s/   D7DDDB+DD
DDNz
telegra.ph)N )
__name__
__module____qualname____firstlineno____doc__	__slots__r   r,   r7   __static_attributes__ r   r   r   r   
   s     6I+
,*r   r   c                       \ rS rSrSrSrSS jrS r  SS jr  SS jr	S	 r
SS
 jr  SS jr  SS jrSS jrSS jrSS jrS rSrg)	TelegraphL   zyTelegraph API client helper

:param access_token: access token
:param domain: domain (e.g. alternative mirror graph.org)
)
_telegraphNc                 $    [        X5      U l        g r   )r   rF   r   s      r   r   Telegraph.__init__U   s    &|<r   c                 .    U R                   R                  $ )zGet current access_token)rF   r   )r   s    r   get_access_tokenTelegraph.get_access_tokenX   s    +++r   c                    #    U R                   R                  SUUUS.S9I Sh  vN nU(       a   UR                  S5      U R                   l        U$  N-7f)a  Create a new Telegraph account

:param short_name: Account name, helps users with several
                   accounts remember which they are currently using.
                   Displayed to the user above the "Edit/Publish"
                   button on Telegra.ph, other users don't see this name
:param author_name: Default author name used when creating new articles
:param author_url: Default profile link, opened when users click on the
                   author's name below the title. Can be any link,
                   not necessarily to a Telegram profile or channels
:param replace_token: Replaces current token to a new user's token
createAccount
short_nameauthor_name
author_urlr-   Nr   rF   r,   r&   r   )r   rO   rP   rQ   replace_tokenr/   s         r   create_accountTelegraph.create_account\   sX      //00$&$J
0   +3<<+GDOO(s   "AA.Ac                 Z   #    U R                   R                  SUUUS.S9I Sh  vN $  N7f)a  Update information about a Telegraph account.
    Pass only the parameters that you want to edit

:param short_name: Account name, helps users with several
                   accounts remember which they are currently using.
                   Displayed to the user above the "Edit/Publish"
                   button on Telegra.ph, other users don't see this name
:param author_name: Default author name used when creating new articles
:param author_url: Default profile link, opened when users click on the
                   author's name below the title. Can be any link,
                   not necessarily to a Telegram profile or channels
editAccountInforN   rR   NrF   r,   )r   rO   rP   rQ   s       r   edit_account_infoTelegraph.edit_account_infou   s=      oo,,->$&$H
,   	 s   "+)+c                    #    U R                   R                  S5      I Sh  vN nUR                  S5      U R                   l        U$  N&7f)zRevoke access_token and generate a new one, for example,
if the user would like to reset all connected sessions, or
you have reasons to believe the token was compromised.
On success, returns dict with new access_token and auth_url fields
revokeAccessTokenNr   rS   )r   r/   s     r   revoke_access_tokenTelegraph.revoke_access_token   s?      //001DEE'/||N'C$	 Fs   A
A'A
c                    #    U R                   R                  SUSU0S9I Sh  vN nU(       a  U(       a  [        US   5      US'   U$  N%7f)a  Get a Telegraph page

:param path: Path to the Telegraph page (in the format Title-12-31,
             i.e. everything that comes after https://telegra.ph/)
:param return_content: If true, content field will be returned
:param return_html: If true, returns HTML instead of Nodes list
getPagereturn_contentr.   r-   Ncontent)rF   r,   r   )r   r.   rb   return_htmlr/   s        r   get_pageTelegraph.get_page   sW      //00nO
0   k"/0C"DHYs   !AA	&Ac           	         #    Uc  [        U5      n[        U5      nU R                  R                  SUUUUUS.S9I Sh  vN $  N7f)a  Create a new Telegraph page

:param title: Page title
:param content: Content in nodes list format (see doc)
:param html_content: Content in HTML format
:param author_name: Author name, displayed below the article's title
:param author_url: Profile link, opened when users click on
                   the author's name below the title
:param return_content: If true, a content field will be returned
N
createPagetitlerP   rQ   rd   rb   rR   r   r	   rF   r,   )r   rk   rd   html_contentrP   rQ   rb   content_jsons           r   create_pageTelegraph.create_page   s[      ?#L1G!'*oo,,\&$#,C
,   	 s   =AA Ac           
         #    Uc  [        U5      n[        U5      nU R                  R                  SUUUUUUS.S9I Sh  vN $  N7f)a  Edit an existing Telegraph page

:param path: Path to the page
:param title: Page title
:param content: Content in nodes list format (see doc)
:param html_content: Content in HTML format
:param author_name: Author name, displayed below the article's title
:param author_url: Profile link, opened when users click on
                   the author's name below the title
:param return_content: If true, a content field will be returned
NeditPagerj   rc   rl   )	r   r.   rk   rd   rm   rP   rQ   rb   rn   s	            r   	edit_pageTelegraph.edit_page   s]      ?#L1G!'*oo,,Zd&$#,L
,   	 s   >A AAc                 ~   #    U R                   R                  SSU(       a  [        U5      OS05      I Sh  vN $  N7f)u  Get information about a Telegraph account

:param fields: List of account fields to return. Available fields:
               short_name, author_name, author_url, auth_url, page_count

               Default: [“short_name”,“author_name”,“author_url”]
getAccountInfofieldsN)rF   r,   r	   )r   rw   s     r   get_account_infoTelegraph.get_account_info   s?      oo,,-=Fj(@
   	 s   4=;=c                 \   #    U R                   R                  SUUS.5      I Sh  vN $  N7f)a"  Get a list of pages belonging to a Telegraph account
    sorted by most recently created pages first

:param offset: Sequential number of the first page to be returned
               (default = 0)
:param limit: Limits the number of pages to be retrieved
              (0-200, default = 50)
getPageList)offsetlimitNrY   )r   r|   r}   s      r   get_page_listTelegraph.get_page_list   s5      oo,,]=
   	 s   #,*,c           	      ^   #    U R                   R                  SUUUUUS.S9I Sh  vN $  N7f)aE  Get the number of views for a Telegraph article

:param path: Path to the Telegraph page
:param year: Required if month is passed. If passed, the number of
             page views for the requested year will be returned
:param month: Required if day is passed. If passed, the number of
              page views for the requested month will be returned
:param day: Required if hour is passed. If passed, the number of
            page views for the requested day will be returned
:param hour: If passed, the number of page views for
             the requested hour will be returned
getViews)yearmonthdayhourrc   NrY   )r   r.   r   r   r   r   s         r   	get_viewsTelegraph.get_views   sA      oo,,Zd	L
,   	 s   $-+-c                 T   #    U R                   R                  U5      I Sh  vN $  N7f)r3   N)rF   r7   )r   r6   s     r   r7   Telegraph.upload_file  s"      oo11!4454s   (&(r9   )NNT)NNN)TT)NNNNFr   )r   2   )NNNN)r;   r<   r=   r>   r?   r@   r   rJ   rU   rZ   r^   rf   ro   rs   rx   r~   r   r7   rA   rB   r   r   rD   rD   L   sr      I=, MQ%)2 DH%)(
" CGFK2 GKDI4
(6r   rD   )r%   r   
exceptionsr   r   utilsr   r   r   r	   r   rD   rB   r   r   <module>r      s+      ; H H? ?DC6 C6r   