1Tc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddlm Z ddl m Z ddlmZmZddlmZddlmZmZddlmZdd lmZmZmZdd lmZdd lmZm Z dd l!m"Z#dd l$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3ddl4m5Z5m6Z6m7Z7ddl8m9Z9ddl:m;Z;ddl<m=Z=ddl>m?Z?ddl@mAZAmBZBddlCmDZDddlEmFZFmGZGddlHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPejQZRe jSZTdeUfdYZVi eWd6eXd6dd 6d!d"6d#d$6eWd%6eWd&6d'd(6eXd)6ZYd*ejZd+d,Z[ed-d.d.Z\ieWd/6ej]d06e?d16Z^d2eUfd3YZ_d4ej`fd5YZad6e'fd7YZbd8d:d9YZcdS(;s sphinx.environment ~~~~~~~~~~~~~~~~~~ Global creation environment. :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. iN(tpath(tglob(tiziptgroupby(tnodes(t FileInputt NullOutput(t Publisher(tReportert relative_pathtget_source_line(t standalone(trolest directives(ten(tMetaBody(tUnfilteredWriter(taddnodes(turl_retget_matching_docst docname_joint split_intotFilenameUniqDict(t clean_astextt make_refnodet WarningStream(tSEPt fs_encodingtfind_catalog_files(tcompile_matchers(t class_types(tdocutils_version(tis_commentable(t SphinxErrortExtensionError(t_(tadd_uidstmerge_doctrees(tDefaultSubstitutionstMoveModuleTargetstHandleCodeBlockstSortIdstCitationReferencestLocaletRemoveTranslatableInlinetSphinxContentsFiltertElementLookupErrorcBseZRS((t__name__t __module__(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR.8stembed_stylesheettcloak_email_addressesshttp://www.python.org/dev/peps/t pep_base_urlshttp://tools.ietf.org/html/t rfc_base_urls utf-8-sigtinput_encodingtdoctitle_xformtsectsubtitle_xformit halt_leveltfile_insertion_enabledi*iititnonettextt commentabletNoUricBseZdZRS(s8Raised by get_relative_uri if there is no URI available.(R/R0t__doc__(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR>UstSphinxStandaloneReadercBs2eZdZeeeeeee gZ dZ RS(s! Add our own transforms. cCstjj||jS(N(R tReadertget_transformst transforms(tself((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRBbs( R/R0R?R+R*R&R'R(R)R,RCRB(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR@Zs    tSphinxDummyWritercBseZdZdZRS(thtmlcCsdS(N((RD((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt translateis(shtml(R/R0t supportedRG(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyREfstBuildEnvironmentcBs$eZdZedZdZdZdZdZd5dZ dZ dZ e d5d Zd5d Zd Zd Zd5d ZdZdZdZdZd5e d5dZedZedZedZddZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d5e e/d*Z0e d+e/e/e/d,Z1d-Z2d.Z3d5d/Z4d0Z5e e6j7d1d2Z8d3Z9d4Z:RS(6s The environment in which the ReST files are translated. Stores an inventory of cross-file targets and provides doctree transformations to resolve links to them. cCsat|d}ztj|}Wd|jX|jtkrNtdn|j|j_|S(Ntrbsenv version not current( topentpickletloadtclosetversiont ENV_VERSIONtIOErrortvaluestconfig(RStfilenamet picklefiletenv((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt frompicklevs cCs |j}|jd|jj}|j`|j}|`t|d}xrt|jjD][\}}|j dst |t j st |t j st |tr_|j|=q_q_Wztj||tjWd|jX||_||j_|j|dS(NtwbR#(t _warnfunct set_warnfunctNoneRSRRtdomainsRKtvarstitemst startswitht isinstancettypest ModuleTypet FunctionTypeRRLtdumptHIGHEST_PROTOCOLRN(RDRTtwarnfuncRRR\RUtkeytval((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyttopickles&     "   cCs7||_||_||_d|_d|_i|_tj|_ ||j d                             cCs ||_t||jd>>s<<t?| j7qt>t@| | j7nd| _Ad| _Bd| j _Cd| j _Dd| j _Ex&| jFtGjHD]} tIjH| _JqWjjK|rjj9d}t4jL|}t4jM|sltNjO|nt8|d} zt:jP| | t:jQWd| j<Xn| SdS(sParse a file and add/update inventory entries for the doctree. If srcpath is given, read from a different source file. s env-purge-docRRR5ttrim_footnote_reference_spaceRiR:sdefault role %s not foundtsphinxtSphinxSourceClasscs/eZdZdZfdZRS(c_s!t|d|g}jd||d}njjre|djjd}njjrjjd|}n|S(Ns source-readis (RtreadRRSt rst_epilogt rst_prolog(RR targ(RmRRD(s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR \s    (R/R0RR R ((RmRRD(s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRQs  treadertwritert source_classtdestination_classtrestructuredtextis doctree-reads.doctreeRJNRX(ii(RRRR[RRR\RRStprimary_domaintsource_encodingRpRRRt default_roleR Rtenglishtdummy_reportert_rolesRtcodecstregister_errorRRRR@RERtset_componentstprocess_programmatic_settingsRt set_sourceRRtset_destinationtpublishRtfilter_messagestprocess_dependenciestprocess_imagestprocess_downloadstprocess_metadatatprocess_refonly_bullet_liststcreate_title_fromtnote_indexentries_fromtnote_citations_fromtbuild_toc_fromt itervaluest process_doctmaxttimeRRRsRlRKRjRLRMRNRtlistR$R%Rt transformerRRVtrecord_dependenciesttraverseRtmetaRt __class__tclearRtisdirRtmakedirsRdRe(RDRtsrc_patht save_parsedRmtrole_fntmessagesRtpubtdoctreeRtft old_doctreetmetanodetdoctree_filenameR((RmRRDs</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR,s      "      +            cCs |jdS(s;Returns the docname of the document currently being parsed.R(R(RD((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRscCs|jjdS(sBackwards compatible alias.s py:module(RR(RD((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt currmodulescCs|jjdS(sBackwards compatible alias.spy:class(RR(RD((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt currclasssR:cCs4|d}|jj|d}|d|j|<|S(sReturn a serial number, e.g. for index entry targets. The number is guaranteed to be unique in the current document. tserialnoii(RR(RDtcategoryRgtcur((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt new_serialnos cCs&|jj|jtj|dS(sAdd *filename* as a dependency of the current document. This means that the document will be rebuilt if this file changes. *filename* should be absolute or relative to the source directory. N(RtRRRqR(RDRT((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytnote_dependencyscCs|jj|jdS(sxAdd the current document to the list of documents that will automatically be re-read at the next build. N(RuRR(RD((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt note_rereadscCsW|jj|gj||jd||jjd|jjd|jfdS(NRs py:moduleR(RRtappendRRtastext(RDRRORR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytnote_versionchangescCsu|jjrdpd}xV|jtjD]B}|d|kr+|jjd|j|jj |q+q+WdS(s&Filter system messages from a doctree.iitlevels%s [filtered system message]N( RSt keep_warningsR3Rtsystem_messageRmtdebugRLtparenttremove(RDR>t filterlevelR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR"s cCstj}tjtj|jd}|jj}|s@dSxT|jD]I}t |tjtj||}|j j |t j |qJWdS(s+Process docutils-generated dependency info.tdummyN(RtgetcwdRRtnormpathRkRpR2R0R RtRRqR(RDRR>tcwdtfrompathtdepsRtrelpath((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR#s  cCsx|jtjD]}|d}|j||\}}|jj|tj|tj |tj s|j d||qn|j j ||}||dRt targetnamet rel_filenameRTt uniquename((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR%s  cCs8x1|jtjD]}i|d<}|d}|jddkrj|jd||||dRRdtimgurit rel_imgpatht full_imgpathRTt new_imgpathR?timgtypeterrtimgpath((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR$sF        $ c Csi|j|<}y|d}Wntk r3dSX|jtjk rJdSx|D]}t|tjrg|D]}|j^qp|dtmdRwRtauthorRtbody((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR&Ds  & c s|jjrdSdtjfdYfd}xjtjD]l}||rNxW|jtjD]@}|d}|d}tj}||7}|j ||qsWqNqNWdS(sChange refonly bullet lists to use compact_paragraphs. Specifically implemented for 'Indices and Tables' section, which looks odd when html_compact_lists is false. NtRefOnlyListCheckercBs2eZdZdZdZdZdZRS(sRaise `nodes.NodeFound` if non-simple list item is encountered. Here 'simple' means a list item containing only a paragraph with a single reference in it. cSs tjdS(N(Rt NodeFound(RDR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt default_visitmscSsdS(N((RDR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytvisit_bullet_listpscSsg}x3|jD](}t|tjs|j|qqWt|dkrZtjnt|dtjs|tjn|d}t|dkrtjnt|dtj stjntj dS(Nii( tchildrenR`Rt InvisibleRKRR}t paragraphRt pending_xreft SkipChildren(RDRRtchildtpara((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytvisit_list_itemss     cSsdS(s"Invisible nodes should be ignored.N((RDR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytinvisible_visits(R/R0R?R~RRR(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR|fs    cs=}y|j|Wntjk r4tSXtSdS(s*Check for list with only references in it.N(twalkRR}RR(Rtvisitor(R|R>(s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytcheck_refonly_lists  i( RSthtml_compact_listsRtGenericNodeVisitorR3t bullet_listt list_itemRtcompact_paragraphR( RDRR>RRtitemRtreft compact_para((R|R>s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR']s !      cCstj}|}|jdrGtj}|tj|d7}nx[|jtjD]4}t|}|dj|||j7}PqZW|tjd7}||j |<||j |N( RRthas_keytTextR3tsectionR-t walkabouttget_entry_textRwRx(RDRRt titlenodet longtitlenodeRR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR(s    cCsCg}|j|ttoctreesRRR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytget_toctree_for%s$       cCs7y|j|SWn!tk r2td|nXdS(sReturn the domain instance with the specified name. Raises an ExtensionError if the domain is not registered. sDomain %r is not registeredN(R\RR"(RDt domainname((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt get_domain:s cCs|j||jd}t|d}ztj|}Wd|jX||j_t|j|dddt |j |_ |S(s:Read the doctree for a file from the pickle and return it.s.doctreeRJNiitstream( RRjRKRLRMRNRpRVRRRYR(RDRRBR?R>((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRFs  c Cs|dkr|j|}n|j|||xd|jtjD]P}|j|||d|d|}|dkr|jgqD|j|qDW|S(sgRead the doctree from the pickle, resolve cross-references and toctrees and return it. RRN(R[Rtresolve_referencesR3RRRt replace_self(RDRRR>tprune_toctreesRRR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytget_and_resolve_doctreeTs  ic s~|jdtr rdSfdfdttfd|pw|jdd} r|jdtrtn r|jdtrtn|gd t} | sdStjd d | } t| d <| d | d |r|p!d xR| jtjD]>} t j | ds8j | d| d| dt resolve_xrefRRsRLRRwRtemphasisRRRRKRRR`tElementRmtemit_firstresultt_warn_missing_referenceRRR(RDR>t fromdocnameRRtcontnodeRttypttargetRRRtcaptiont innernodetlabelid((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyR2sb                 c CsK|jd}|jjrt}|jr|rCd|j|fpF|}||f|jkrgt}n|jdkr||f|jkrt}qqn|sdS|r||jkr|j|}nc|dkrd}nN|dkrd}n9|jdddkr"d |d|f}n d |}|j|i|d 6|dS( Ntrefwarns%s:%sRRsunknown document: %(target)sRscitation not found: %(target)sRs-%s:%s reference target not found: %%(target)ss*%s reference target not found: %%(target)sR( RRStnitpickyRRRRtdangling_warningsR( RDtfromdocRRRRRtdtypeR((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRxs,   $     cCsx|jtjD]}y|jj|d}WnCtk rx}|jd|||j|jpqt j qX|r|j|jpt j q|jt j qWdS(NRs8exception while evaluating only directive expression: %s( R3RRttagsteval_conditiont ExceptionRRRRtcomment(RDR>RRRRRs((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRs   csgji_dfdfdxnjD]c}j|}xK|jtjD]7}|jdd}|rzdg||qzqzWqRWS(sAAssign a section number to each heading under a numbered toctree.cs\xU|jD]J}t|tjrYjd|||d|jd}q t|tjr||||d}q t|tj r||||d}q t|tj r2dcd7<|dkrt }nd}|||dd<|dd<|rT||dRR((R R R R R RDs</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRs    s(.*) ([(][^()]*[)])csi}t|fdx|jjD]\}x|D]\}}y|dkrytdd|\}} Wn,tk rtdd|\}d} nX|| nF|dkrtdd|\} } | | | | n|dkrptdd|\} } } | | d | | | d | | | d | n|d krtdd |\} } | td | d tnX|dkrtdd |\} } | td| d tn|jd|WqJtk r8} |jt| qJXqJWq7Wt j dd}|j }|j d||rNd}d}d}x|t|krJ||\}\}}|s7|j|}|r.||jdkr|j|jdgigdj|||=qn|jd}q7|}n|}|d7}qWnt jdd}gt||D]\}}|t|f^qqS(s7Create the real index from the collected index entries.cst|}|j|}|s8gig||<}n|r^|dd|d|dnR|ryjdd}Wntk rqX|dj|fndS(NR:tlinktdicitgenindexRi(RRRR>RK(twordtsubwordRRtentryRe(t add_entryRRtmainttid(s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyRs   tsingleiiR:tpairttripleit s, tseessee %sRtseealsos see also %ssunknown index entry type %rR#cSsAtjd|dj}|dd!|kr=td|S|S(NtNFDiii(t unicodedatat normalizeRtchr(Rt lcletterstlckey((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytkeyfuncsRgicSsn|\}}td|djD|dGsiRitSymbols(RRRRtupperR#(Rtletterstktvtletter((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pytkeyfunc2Ds  $  N(RRRRRR#RRtstrtstringtascii_lowercaseR^tsortR[RRtgroupRRtascii_uppercaseRR0(RDRt group_entriest_fixreRRRtvalueRtsubentrytfirsttsecondtthirdRsR#tnewlisttoldkeyt oldsubitemsRRgttargetstsubitemstmR.R3((RRRRRs</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt create_indexsl!          " %  csMi|jjfddgt|jjddS(Nc sR||krdS|}|s3|dd}n&x#|}|rU|d}q6Pq6|rl|d}nZ|runQxN|D]F\}}|} | r||dt| kr|| |d}Pq|q|W|r3xdtt|dg||ddgD]5\} } || fg||j|g| qWn|dd||g|RAR@RERI(((s</usr/local/lib/python2.7/site-packages/sphinx/environment.pyt sr          (: