
    2i_                        S r SrSSKJr  SSKJr  SSKrSSKrSSKJ	r	J
r
Jr  SSKJr  SSKrSS	R                  S
 \ 5       5      -   S-   rSrSr\R&                  " \5      r\\S4   r " S S\5      r " S S\5      r\\\4   rS\S\4S jr\R<                  \R>                  " S5      \R@                  \R>                  " S5      0r! " S S5      r" " S S5      r# " S S5      r$g)z
Wikipedia-API is easy to use wrapper for extracting information from Wikipedia.

It supports extracting texts, sections, links, categories, translations, etc.
from Wikipedia. Documentation provides code snippets for the most common use
cases.
)          r   )defaultdict)IntEnumN)AnyOptionalUnion)parsezWikipedia-API/.c              #   8   #    U  H  n[        U5      v   M     g 7fN)str).0ss     O/home/james-whalen/.local/lib/python3.13/site-packages/wikipediaapi/__init__.py	<genexpr>r      s     +{!s1vv{s   z1; https://github.com/martin-majlis/Wikipedia-API/   WikipediaPagec                   "    \ rS rSrSrSr SrSrg)ExtractFormat$   zRepresents extraction format.r       N)__name__
__module____qualname____firstlineno____doc__WIKIHTML__static_attributes__r       r   r   r   $   s    'D Dr"   r   c                       \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!S r"S!r#S"r$S#r%S$r&S%r'S&r(S'r)g())	Namespace:   z
Represents namespace in Wikipedia

You can gen list of possible namespaces here:

* https://en.wikipedia.org/wiki/Wikipedia:Namespace
* https://en.wikipedia.org/wiki/Wikipedia:Namespace#Programming

Currently following namespaces are supported:
r   r   r         r         r   	   
                  d   e   f   g   h   i   l   m   v   w   i  i  i  i  i<  i=  i  i  i  i  r   N)*r   r   r   r   r   MAINTALKUSER	USER_TALK	WIKIPEDIAWIKIPEDIA_TALKFILE	FILE_TALK	MEDIAWIKIMEDIAWIKI_TALKTEMPLATETEMPLATE_TALKHELP	HELP_TALKCATEGORYCATEGORY_TALKPORTALPORTAL_TALKPROJECTPROJECT_TALK	REFERENCEREFERENCE_TALKBOOK	BOOK_TALKDRAFT
DRAFT_TALKEDUCATION_PROGRAMEDUCATION_PROGRAM_TALK
TIMED_TEXTTIMED_TEXT_TALKMODULEMODULE_TALKGADGETGADGET_TALKGADGET_DEFINITIONGADGET_DEFINITION_TALKr!   r   r"   r   r$   r$   :   s    	 DDDIINDIINHMDIHMFKGLINDIEJ JOFKFK!r"   r$   	namespacereturnc                 H    [        U [        5      (       a  U R                  $ U $ )zConverts namespace into integer)
isinstancer$   value)r_   s    r   namespace2intrd   o   s    )Y''r"   z\n\n *(==+) (.*?) (==+) *\nz\n? *<h([1-9])[^>]*?>(<span[^>]*></span>)? *(<span[^>]*>)? *(<span[^>]*></span>)? *(.*?) *(</span>)?(<span>Edit</span>)?</h[1-9]>
?c                   |   \ rS rSrSrSS\R                  SS4S\S\S\\   S\S	\\	\\
4      S
\\	\\
4      SS4S jjrS+S jr\R                  S4S\S\S\SS4S jjr\R                  S4S\S\S\SS4S jjrSSS\4S jrS,S jrSSS\4S jrSSS\4S jrSSS\4S jrSSS\4S jrSSS\4S jrSSS\	\\
4   4S jrSSS\	\\
4   S\	\\
4   4S jrSSS\4S  jrS! rS,S" jrS\4S# jr S\4S$ jr!S\4S% jr"S\4S& jr#S\4S' jr$\%S-S( j5       r&\%S\\   S\\   S\\   S\'\\\   \4   4S) j5       r(S*r)g).	Wikipedia   z'Wikipedia is wrapper for Wikipedia API.enN
user_agentlanguagevariantextract_formatheadersextra_api_paramsr`   c                    UR                  SS5        Uc  0 OUnUb  UR                  SU5        U R                  UUUR                  S5      5      u  pnUS-   [        -   S-   US'   Xl        Xl        X@l        [        R                  SU R                  US   U R                  5        X`l	        [        R                  " 5       U l        U R                  R                  R                  U5        Xpl        g)an  
Constructs Wikipedia object for extracting information Wikipedia.

:param user_agent: HTTP User-Agent used in requests
        https://meta.wikimedia.org/wiki/User-Agent_policy
:param language: Language mutation of Wikipedia -
        http://meta.wikimedia.org/wiki/List_of_Wikipedias
:param variant: Language variant.
        Only works if the base language supports variant conversion.
:param extract_format: Format used for extractions
        :class:`ExtractFormat` object.
:param headers:  Headers sent as part of HTTP request
:param extra_api_params:  Extra parameters that are used to construct
        query string when calling Wikipedia API
:param request_kwargs: Optional parameters used in -
        http://docs.python-requests.org/en/master/api/#requests.request

Examples:

* Proxy: ``Wikipedia('foo (merlin@example.com)', proxies={'http': 'http://proxy:1234'})``
timeoutg      $@Nz
User-Agentz ()z9Wikipedia: language=%s, user_agent: %s, extract_format=%s)
setdefault_check_and_correct_paramsget
USER_AGENTrj   rk   rl   loginfo_extra_api_paramsrequestsSession_sessionrm   update_request_kwargs)selfri   rj   rk   rl   rm   rn   request_kwargsdefault_headersused_languageused_variantused_user_agents               r   __init__Wikipedia.__init__   s    > 	!!)T2 '"W!&& 8<7U7U-8
4_ )8$(>(Kc(Q%%#,GMML)		
 "2 ((*$$_5-r"   c                     [        U S5      (       a-  U R                  (       a  U R                  R                  5         ggg)zCloses session.r{   N)hasattrr{   closer~   s    r   __del__Wikipedia.__del__   s-    4$$MM! *7$r"   Ftitlensunquoter   c                 z    U(       a  [         R                  " U5      n[        XX R                  U R                  S9$ )u  
Constructs Wikipedia page with title `title`.

Creating `WikipediaPage` object is always the first step for extracting
any information.

Example::

    wiki_wiki = wikipediaapi.Wikipedia('en')
    page_py = wiki_wiki.page('Python_(programming_language)')
    print(page_py.title)
    # Python (programming language)

    wiki_hi = wikipediaapi.Wikipedia('hi')

    page_hi_py = wiki_hi.article(
        title='%E0%A4%AA%E0%A4%BE%E0%A4%87%E0%A4%A5%E0%A4%A8',
        unquote=True,
    )
    print(page_hi_py.title)
    # पाइथन

:param title: page title as used in Wikipedia URL
:param ns: :class:`WikiNamespace`
:param unquote: if true it will unquote title
:return: object representing :class:`WikipediaPage`
r   r   rj   rk   )r
   r   r   rj   rk   r~   r   r   r   s       r   pageWikipedia.page   s2    B MM%(E"}}dll
 	
r"   c                 $    U R                  UUUS9$ )a  
Constructs Wikipedia page with title `title`.

This function is an alias for :func:`page`

:param title: page title as used in Wikipedia URL
:param ns: :class:`WikiNamespace`
:param unquote: if true it will unquote title
:return: object representing :class:`WikipediaPage`
)r   r   r   )r   r   s       r   articleWikipedia.article   s#     yy  
 	
r"   r   c                    SSUR                   S.nU R                  [        R                  :X  a  O(U R                  [        R                  :X  a
  SUS'   SUS'   UnUR                  U5        U R                  X5      nU R                  US   U5        US   S   nUR                  5        H-  u  pxUS	:X  a  S
UR                  S'     gU R                  X5      s  $    g)al  
Returns summary of the page with respect to parameters

Parameter `exsectionformat` is taken from `Wikipedia` constructor.

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bextracts
- https://www.mediawiki.org/wiki/Extension:TextExtracts#API

Example::

    import wikipediaapi
    wiki = wikipediaapi.Wikipedia('en')

    page = wiki.page('Python_(programming_language)')
    print(wiki.extracts(page, exsentences=1))
    print(wiki.extracts(page, exsentences=2))

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: summary of the page

queryextracts)actionproptitlesr   explaintextwikiexsectionformatpages-1pageid )r   rl   r   r    r   r|   _query_common_attributesitems_attributes_build_extracts	r~   r   kwargsparamsused_paramsrawr   kvs	            r   r   Wikipedia.extracts  s    4 jj
 -"4"44  M$6$66$%F=!(.F$%6"kk$,Gd3GW%KKMDADy-/  *''00	 "
 r"   c                 ,   SSUR                   SR                  / SQ5      S.nU R                  X5      nU R                  US   U5        US   S   nUR	                  5        H/  u  pVUS:X  a  SUR
                  S	'   Us  $ U R                  Xa5      s  $    U$ )
zn
https://www.mediawiki.org/w/api.php?action=help&modules=query%2Binfo
https://www.mediawiki.org/wiki/API:Info
r   rw   |)
protectiontalkidwatchedwatchersvisitingwatchersnotificationtimestamp	subjectidurlreadablepreloaddisplaytitlevarianttitles)r   r   r   inpropr   r   r   r   )r   joinr   r   r   r   _build_info)r~   r   r   r   r   r   r   s          r   rw   Wikipedia.info:  s     jjhh	
* kk$'Gd3GW%KKMDADy-/  *##A,, " r"   c                 2   SSUR                   SSS.nUnUR                  U5        U R                  X5      nU R                  US   U5        US   S   nUR	                  5        H/  u  pxUS:X  a  SUR
                  S	'   0 s  $ U R                  X5      s  $    0 $ )
aM  
Returns langlinks of the page with respect to parameters

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Blanglinks
- https://www.mediawiki.org/wiki/API:Langlinks

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: links to pages in other languages

r   	langlinks  r   )r   r   r   lllimitllpropr   r   r   r   )r   r|   r   r   r   r   _build_langlinksr   s	            r   r   Wikipedia.langlinks_  s     jj
 6"kk$,Gd3GW%KKMDADy-/  *	((11	 "
 	r"   c                    SSUR                   SS.nUnUR                  U5        U R                  X5      nU R                  US   U5        US   S   nUR	                  5        Hr  u  pxUS:X  a  SUR
                  S'   0 s  $ S	U;   a=  US	   S
   US
'   U R                  X5      nUS==   US   S   U   S   -  ss'   S	U;   a  M=  U R                  X5      s  $    0 $ )a8  
Returns links to other pages with respect to parameters

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Blinks
- https://www.mediawiki.org/wiki/API:Links

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: links to linked pages

r   linksr   )r   r   r   pllimitr   r   r   r   continue
plcontinue)r   r|   r   r   r   r   _build_linksr   s	            r   r   Wikipedia.links  s     jj	
 6"kk$,Gd3GW%KKMDADy-/  *	#'*:|'D|$kk$/'
c'l73A6w??
 #
 $$Q-- " 	r"   c                 <   SSUR                   SS.nUnUR                  U5        U R                  X5      nU R                  US   U5        US   nSU;   a7  US   S   US'   U R                  X5      nUS==   US   S   -  ss'   SU;   a  M7  U R	                  Xa5      $ )aK  
Returns backlinks from other pages with respect to parameters

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bbacklinks
- https://www.mediawiki.org/wiki/API:Backlinks

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: backlinks from other pages

r   	backlinksr   )r   listbltitlebllimitr   
blcontinue)r   r|   r   r   _build_backlinksr~   r   r   r   r   r   r   s          r   r   Wikipedia.backlinks  s     zz	
 6"kk$,Gd3LC#&z?<#@F< ++d+CkNc'l;77N C $$Q--r"   c                 0   SSUR                   SS.nUnUR                  U5        U R                  X5      nU R                  US   U5        US   S   nUR	                  5        H/  u  pxUS:X  a  SUR
                  S'   0 s  $ U R                  X5      s  $    0 $ )	a>  
Returns categories for page with respect to parameters

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bcategories
- https://www.mediawiki.org/wiki/API:Categories

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: categories for page
r   
categoriesr   )r   r   r   cllimitr   r   r   r   )r   r|   r   r   r   r   _build_categoriesr   s	            r   r   Wikipedia.categories  s      jj	
 6"kk$,Gd3GW%KKMDADy-/  *	))!22	 "
 	r"   c                 <   SSUR                   SS.nUnUR                  U5        U R                  X5      nU R                  US   U5        US   nSU;   a7  US   S   US'   U R                  X5      nUS==   US   S   -  ss'   SU;   a  M7  U R	                  Xa5      $ )aP  
Returns pages in given category with respect to parameters

API Calls for parameters:

- https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bcategorymembers
- https://www.mediawiki.org/wiki/API:Categorymembers

:param page: :class:`WikipediaPage`
:param kwargs: parameters used in API call
:return: pages in given category
r   categorymembersr   )r   r   cmtitlecmlimitr   
cmcontinue)r   r|   r   r   _build_categorymembersr   s          r   r   Wikipedia.categorymembers  s     %zz	
 6"kk$,Gd3LC#&z?<#@F< ++d+C CL1B$CC  C
 **133r"   r   c                    SUR                   -   S-   nU R                  X5      n[        R                  SUS-   SR	                  UR                  5        VVs/ s H  u  pVUS-   [        U5      -   PM     snn5      -   5        U R                  R                  " U4SU0U R                  D6nUR                  5       $ s  snnf )z'Queries Wikimedia API to fetch content.zhttps://z.wikipedia.org/w/api.phpzRequest URL: %s?&=r   )rj   _construct_paramsrv   rw   r   r   r   r{   rt   r}   json)r~   r   r   base_urlr   r   r   rs           r   r   Wikipedia._query  s    -0JJ,,T:hh[5F5F5HI5HTQC#a&(5HIJK	
 MMhS{Sd>R>RSvvx	 Js   B:c                     0 nUR                   (       a  UR                   US'   SUS'   SUS'   UR                  U5        U R                  (       a  UR                  U R                  5        U$ )Nrk   r   formatr   	redirects)rk   r|   rx   )r~   r   r   r   s       r   r   Wikipedia._construct_params  sc     <<%)\\K	" &H#$K 6"!!t556r"   c                 l   SUl         [        [        5      Ul        U R	                  X5        U/nSnSn[
        R                  " [        U R                     US   5       GH  n[        UR                  5      S:X  a*  US   SUR                  5        R                  5       Ul         O+Ub(  US   XVR                  5        R                  5       Ul        U R                  U5      nUR                  S-   nU[        U5      :  a  UR                  U5        OsU[        U5      :X  a"  UR!                  5         UR                  U5        OB[#        [        U5      U-
  S-   5       H  nUR!                  5         M     UR                  U5        U[        U5      S-
     R$                  R                  U5        UR'                  5       nUR                  UR(                     R                  U5        GM     UR                   S:X  a  US   R                  5       Ul         US:  a  Ub  US   US Ul        UR                   $ )z!Constructs summary of given page.r   Nr   extractr   r   )_summaryr   r   _section_mappingr   refinditer
RE_SECTIONrl   lenstartstrip_text_create_sectionlevelappendpoprange_sectionendr   )	r~   r   r   section_stacksectionprev_posmatch	sec_level_s	            r   r   Wikipedia._build_extracts+  s    +D 1.[[D,?,?!@')BTUE4(()Q. '	 21u{{} E K K M$!(!3H{{}!M T T V**51G)I3}--$$W-c-00!!#$$W-s=1I=ABA!%%' C$$W-#m,q01::AA'J yy{H!!'--077@/ V4 ==B#I.446DMa<G/#I.xy9GM}}r"   c                    SnSnU R                   [        R                  :X  a:  UR                  S5      R	                  5       n[        UR                  S5      5      nOeU R                   [        R                  :X  aG  UR                  S5      R	                  5       n[        UR                  S5      R	                  5       5      n[        XUS-
  5      nU$ )zCreates section.r   r   r   r   )	rl   r   r   groupr   r   r    intWikipediaPageSection)r~   r	  	sec_titler
  r  s        r   r   Wikipedia._create_sectionX  s    		-"4"44A,,.IEKKN+I  M$6$66A,,.IEKKN0023I&t	AFr"   c                 v    U R                  X5        UR                  5        H  u  p4XBR                  U'   M     U$ )zBuilds page from API call info.)r   r   r   )r~   r   r   r   r   s        r   r   Wikipedia._build_infof  s7    .MMODA"#Q $ r"   c           	          0 Ul         U R                  X5        UR                  S/ 5       H?  n[        U US   [        R
                  US   US   S9nXBR                   UR                  '   MA     UR                   $ )z$Builds page from API call langlinks.r   *langr   )r   r   r   rj   r   )
_langlinksr   rt   r   r$   r;   rj   )r~   r   r   langlinkps        r   r   Wikipedia._build_langlinksn  st    .K4Hsm>>!&)UOA +,OOAJJ' 5 r"   c           	          0 Ul         U R                  X5        UR                  S/ 5       HC  n[        U US   [	        US   5      UR
                  UR                  S9UR                   US   '   ME     UR                   $ )z Builds page from API call links.r   r   r   r   r   r   rj   rk   )_linksr   rt   r   r  rj   rk   )r~   r   r   links       r   r   Wikipedia._build_links  sr    .KK,D)67mtDz?*DKKW& - {{r"   c           	          0 Ul         U R                  X5        UR                  S/ 5       HC  n[        U US   [	        US   5      UR
                  UR                  S9UR                   US   '   ME     UR                   $ )z$Builds page from API call backlinks.r   r   r   r  )
_backlinksr   rt   r   r  rj   rk   )r~   r   r   backlinks       r   r   Wikipedia._build_backlinks  su    .K4H1>w'x~&2DOOHW-. 5 r"   c           	          0 Ul         U R                  X5        UR                  S/ 5       HC  n[        U US   [	        US   5      UR
                  UR                  S9UR                   US   '   ME     UR                   $ )z%Builds page from API call categories.r   r   r   r  )_categoriesr   rt   r   r  rj   rk   )r~   r   r   categorys       r   r   Wikipedia._build_categories  sz    .L"5H2?w'x~&3DXg./ 6 r"   c           	         0 Ul         U R                  X5        UR                  S/ 5       HN  n[        U US   [	        US   5      UR
                  UR                  S9nUS   Ul        XBR                   US   '   MP     UR                   $ )z*Builds page from API call categorymembers.r   r   r   r  r   )_categorymembersr   rt   r   r  rj   rk   r   )r~   r   r   memberr  s        r   r    Wikipedia._build_categorymembers  s     ".kk"3R8FWovd|$A h'AH56!!&/2 9 $$$r"   c                 N    / SQnU H  nX0;   d  M
  X   UR                   U'   M     g)z$Fills in common attributes for page.)r   r   r   r   N)r   )r   r   common_attributesattrs       r   r   Wikipedia._common_attributes  s,     C%D)0  & &r"   c                    U(       a  [        U5      [        :  a5  [        S[        U5      -   S-   S-   [        U5      =(       d    S-   S-   5      eU (       d,  [        S[        U 5      -   S-   S-   [        U5      -   S-   5      eU R	                  5       R                  5       n[        U5      [        :  a  [        R                  S	U[        5        UU(       a   UR	                  5       R                  5       U4$ UU4$ )
a=  
Checks the constructor parameters and throws AssertionError if they are incorrect.
Otherwise, it normalises them to easy use later on.
:param language: Language mutation of Wikipedia
:param variant: Language variant
:param user_agent: HTTP User-Agent used in requests
:return: tuple of language, variant, user_agent
z~Please, be nice to Wikipedia and specify user agent - https://meta.wikimedia.org/wiki/User-Agent_policy. Current user_agent: 'z' is not sufficient. z6Use Wikipedia(user_agent='your-user-agent', language='zyour-languagez')z%Specify language. Current language: 'zUse Wikipedia(user_agent='z', language='your-language')z6Used language '%s' is longer than %d. It is suspicious)	r   MIN_USER_AGENT_LENAssertionErrorr   r   lowerMAX_LANG_LENrv   warning)rj   rk   ri   r   s       r   rs   #Wikipedia._check_and_correct_params  s    S_/AA ]j/" ** K	K
 z?5o7    7h- )* // j/	"
 11  !(..0},KKH '.GMMO!!#
 	
4;
 	
r"   )rx   r}   r{   rl   rj   rk   )r`   N)r   r   r`   r   )r   r   )*r   r   r   r   r   r   r   r   r   dictr   r   r   r$   r;   WikiNamespaceboolr   r   r   rw   	PagesDictr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   staticmethodr   tuplers   r!   r   r"   r   rf   rf      su   1
 !%(5(:(:,059>.>. >. #	>.
 &>. $sCx.)>. #4S>2>. 
>.@" &NN	&
&
 &
 	&

 
&
R /8nne

+
GK
	
&1_ 13 1f#J!o !I !F&/ &	 &P .o  .I  .D Y B 4O  4)  4D? DcN #-1#s(^	c3h+_ + +Z $Y " " )  "%y %( 7 7 ,
3-,
*23-,
EMc],
	sHSM3&	',
 ,
r"   rf   c                       \ rS rSrSr SS\S\S\S\SS4
S	 jjr\	S\4S
 j5       r
\	S\4S j5       r\	S\4S j5       r\	S\S    4S j5       rS\S\S    4S jrSS\S\4S jjrS rSrg)r  i   z4WikipediaPageSection represents section in the page.r   r   r   textr`   Nc                 B    Xl         X l        X0l        X@l        / U l        g)z Constructs WikipediaPageSection.N)r   _title_levelr   r  )r~   r   r   r   r?  s        r   r   WikipediaPageSection.__init__  s     	
r"   c                     U R                   $ )zN
Returns title of the current section.

:return: title of the current section
)rA  r   s    r   r   WikipediaPageSection.title       {{r"   c                     U R                   $ )zf
Returns indentation level of the current section.

:return: indentation level of the current section
)rB  r   s    r   r   WikipediaPageSection.level  rF  r"   c                     U R                   $ )zL
Returns text of the current section.

:return: text of the current section
)r   r   s    r   r?  WikipediaPageSection.text  s     zzr"   c                     U R                   $ )zZ
Returns subsections of the current section.

:return: subsections of the current section
)r  r   s    r   sectionsWikipediaPageSection.sections(  s     }}r"   c                     U R                    Vs/ s H  o"R                  U:X  d  M  UPM     nnU(       a  US   $ gs  snf )z
Returns subsections of the current section with given title.

:param title: title of the subsection
:return: subsection if it exists
r   N)r  r   )r~   r   r   rL  s       r   section_by_title%WikipediaPageSection.section_by_title1  s;      $}}A}!50@A}AB< Bs   ;;c                    SnU R                   R                  [        R                  :X  a  X R                  -  nOMU R                   R                  [        R
                  :X  a  USU SU R                   SU S3-  nO[        S5      eUS-  nX R                  -  n[        U R                  5      S:  a  US-  nU R                   H  nX#R                  US	-   5      -  nM     U$ )
z
Returns text of the current section as well as all its subsections.

:param level: indentation level
:return: text of the current section as well as all its subsections
r   z<h>z</hzUnknown ExtractFormat type
r   

r   )r   rl   r   r   r   r    NotImplementedErrorr   r   rL  	full_text)r~   r   ressecs       r   rV  WikipediaPageSection.full_text=  s     99##}'9'99::CYY%%););;Rwa

|3ugQ77C%&BCCtzztzz?Q6MC==C==++C !
r"   c                     SR                  U R                  U R                  U R                  [	        U R
                  5      SR                  [        [        U R
                  5      5      5      $ )Nz)Section: {} ({}):
{}
Subsections ({}):
{}rS  )	r   rA  rB  r   r   r  r   mapreprr   s    r   __repr__WikipediaPageSection.__repr__T  sM    =DDKKKKJJIIc$./
 	
r"   )rB  r  r   rA  r   )r   r   )r   )r   r   r   r   r   rf   r   r  r   propertyr   r   r?  r   rL  r   rO  rV  r]  r!   r   r"   r   r  r     s    > HJ&)25AD	 s   s   c   $56  
c 
h7M.N 
s 3 .
r"   r  c                      \ rS rSrSr0 S/ _S/ _S/ SQ_S/ SQ_S/ SQ_S	S
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_SS
/_S
/S
/S
/S
/S
/S
/S
/S
/S.Er\R                  SSS4S\S\	S\
S\	S\\	   S\\	   SS4S jjrS r\S\	4S j5       r\S\\	   4S j5       r\S\	4S  j5       r\S\4S! j5       rS\4S" jr\S\	4S# j5       r\S\\   4S$ j5       rS\	S\\   4S% jrS\	S\\   4S& jr\S\	4S' j5       r\S\4S( j5       r\S\4S) j5       r\S\4S* j5       r \S\4S+ j5       r!\S\4S, j5       r"S0S- jr#S. r$S/r%g)1r   i^  aP  
Represents Wikipedia page.

Except properties mentioned as part of documentation, there are also
these properties available:

* `fullurl` - full URL of the page
* `canonicalurl` - canonical URL of the page
* `pageid` - id of the current page
* `displaytitle` - title of the page to display
* `talkid` - id of the page with discussion

rj   rk   r   )rw   r   r   r   r   contentmodelrw   pagelanguagepagelanguagehtmlcodepagelanguagedirtouched	lastrevidlengthr   restrictiontypesr   r   r   )r   fullurlediturlcanonicalurlr   r   r   r   rh   Nr   r   r`   c                     Xl         SU l        / U l        0 U l        0 U l        0 U l        0 U l        0 U l        0 U l        SSSSSSSS.U l	        U[        U5      UUS.U l        Ub  X`R                  S'   g g )Nr   F)r   rw   r   r   r   r   r   r   ri  )r   r   r  r   r  r  r"  r&  r*  _calledrd   r   )r~   r   r   r   rj   rk   r   s          r   r   WikipediaPage.__init__  s     	 " " $
 # 	
 ?*-Y' r"   c                    XR                   ;  a  U R                  U5      $ XR                  ;   a  U R                  U   $ U R                   U    H9  nU R                  U   (       a  M  U R	                  U5        U R                  U   s  $    g r   )ATTRIBUTES_MAPPING__getattribute__r   rm  _fetch)r~   namecalls      r   __getattr__WikipediaPage.__getattr__  s}    ...((..#####D))++D1D<<%%D!''-- 2r"   c                 2    [        U R                  S   5      $ )z:
Returns language of the current page.

:return: language
rj   r   r   r   s    r   rj   WikipediaPage.language  s     4##J/00r"   c                 H    U R                   S   nU(       a  [        U5      $ S$ )zJ
Returns language variant of the current page.

:return: language variant
rk   N)r   r   )r~   r   s     r   rk   WikipediaPage.variant  s%     Y's1v$$r"   c                 2    [        U R                  S   5      $ )z4
Returns title of the current page.

:return: title
r   rx  r   s    r   r   WikipediaPage.title  s     4##G,--r"   c                 2    [        U R                  S   5      $ )z<
Returns namespace of the current page.

:return: namespace
r   )r  r   r   s    r   r_   WikipediaPage.namespace  s     4##D)**r"   c                 2    [        U R                  S:g  5      $ )zh
Returns `True` if the current page exists, otherwise `False`.

:return: if current page existst or not
r   )r:  r   r   s    r   existsWikipediaPage.exists  s     DKK2%&&r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z8
Returns summary of the current page.

:return: summary
r   )rm  rr  r   r   s    r   summaryWikipediaPage.summary  &     ||J'KK
#}}r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )zZ
Returns all sections of the curent page.

:return: List of :class:`WikipediaPageSection`
r   )rm  rr  r  r   s    r   rL  WikipediaPage.sections  r  r"   c                     U R                   S   (       d  U R                  S5        U R                  R                  U5      nU(       a  US   $ g)z
Returns last section of the current page with given `title`.

:param title: section title
:return: :class:`WikipediaPageSection`
r   r   Nrm  rr  r   rt   r~   r   rL  s      r   rO  WikipediaPage.section_by_title  sB     ||J'KK
#((,,U3B<r"   c                     U R                   S   (       d  U R                  S5        U R                  R                  U5      nUc  / $ U$ )z
Returns all section of the current page with given `title`.

:param title: section title
:return: :class:`WikipediaPageSection`
r   r  r  s      r   sections_by_titleWikipediaPage.sections_by_title  sB     ||J'KK
#((,,U3Ir"   c                     U R                   n[        U5      S:  a  US-  nU R                   H  nXR                  SS9-  nM     UR	                  5       $ )zF
Returns text of the current page.

:return: text of the current page
r   rT  r   )r   )r  r   rL  rV  r   )r~   txtrX  s      r   r?  WikipediaPage.text!  sN     lls8a<6MC==C==q=))C !yy{r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z
Returns all language links to pages in other languages.

This is wrapper for:

* https://www.mediawiki.org/w/api.php?action=help&modules=query%2Blanglinks
* https://www.mediawiki.org/wiki/API:Langlinks

:return: :class:`PagesDict`
r   )rm  rr  r  r   s    r   r   WikipediaPage.langlinks/  &     ||K(KK$r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z
Returns all pages linked from the current page.

This is wrapper for:

* https://www.mediawiki.org/w/api.php?action=help&modules=query%2Blinks
* https://www.mediawiki.org/wiki/API:Links

:return: :class:`PagesDict`
r   )rm  rr  r  r   s    r   r   WikipediaPage.links?  s&     ||G$KK {{r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z
Returns all pages linking to the current page.

This is wrapper for:

* https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bbacklinks
* https://www.mediawiki.org/wiki/API:Backlinks

:return: :class:`PagesDict`
r   )rm  rr  r"  r   s    r   r   WikipediaPage.backlinksO  r  r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z
Returns categories associated with the current page.

This is wrapper for:

* https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bcategories
* https://www.mediawiki.org/wiki/API:Categories

:return: :class:`PagesDict`
r   )rm  rr  r&  r   s    r   r   WikipediaPage.categories_  s(     ||L)KK%r"   c                 d    U R                   S   (       d  U R                  S5        U R                  $ )z
Returns all pages belonging to the current category.

This is wrapper for:

* https://www.mediawiki.org/w/api.php?action=help&modules=query%2Bcategorymembers
* https://www.mediawiki.org/wiki/API:Categorymembers

:return: :class:`PagesDict`
r   )rm  rr  r*  r   s    r   r   WikipediaPage.categorymemberso  s*     ||-.KK)*$$$r"   c                 \    [        U R                  U5      " U 5        SU R                  U'   U $ )zFetches some data?.T)getattrr   rm  )r~   rt  s     r   rr  WikipediaPage._fetch  s(    		4 &!Tr"   c                     U R                    SU R                   SU R                   S3n[        U R                  R                  5       5      (       a  USU R                   S3-  nOUS-  nUSU R                   S3-  nU$ )Nz (lang: z, variant: z, zid: zid: ??, zns: rq   )r   rj   rk   anyrm  valuesr   r   )r~   r   s     r   r]  WikipediaPage.__repr__  sz    zzl(4==/T\\N"Mt||""$%%4}B''AOA	tDGG9Ar"   )r   r"  rm  r&  r*  r  r  r  r   r   r   )r`   r   )&r   r   r   r   r   rp  r$   r;   rf   r   r9  r   r   ru  r_  rj   rk   r   r  r_   r:  r  r  r   r  rL  rO  r  r?  r;  r   r   r   r   r   rr  r]  r!   r   r"   r   r   r   ^  s)   B2 	3 	/	
 	2 	 	 	 	F8 	F8 	fX 	6( 	vh 	VH 	VH  	VH!" 	 &#$ (88H8 3@ &NN!%!%.%. %. 	%.
 %. #%. c]%. 
%.N
. 1# 1 1 %# % % .s . . +3 + +' '    $34   
&	'" 
"	#" c   9   y   9    I     % % %r"   )%r   __version__collectionsr   enumr   loggingr   typingr   r   r	   urllibr
   ry   r   ru   r2  r5  	getLoggerr   rv   r8  r   r;  r   r$   r  r9  rd   r   compiler    r   rf   r  r   r   r"   r   <module>r     s    #   	 ' '   	hh+{++,9:   ! o%&	G ,/" /"d in%] s  

#AB

	7

y	
 y	
x[
 [
|o or"   