3

T'íc¥<ã@sædZddlmZmZmZmZddlmZddlm	Z	m
Z
ddlmZ
ddlmZddlmZddlmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZejeƒZ Gdd„deƒZ!Gdd„dƒZ"Gdd„dee
ƒZ#dS)z5Manual page writer, extended for Sphinx custom nodes.é)ÚAnyÚDictÚIterableÚcast)Únodes)ÚElementÚTextElement)Ú
Translator)ÚWriter)Úaddnodes)ÚBuilder)Ú_Úadmonitionlabels)Úlogging)ÚSphinxTranslator)Úformat_date)ÚNodeMatchercs2eZdZeddœ‡fdd„Zddœdd„Z‡ZS)ÚManualPageWriterN)ÚbuilderÚreturncstƒjƒ||_dS)N)ÚsuperÚ__init__r)Úselfr)Ú	__class__©ú8/tmp/pip-build-gk9425m9/sphinx/sphinx/writers/manpage.pyrs
zManualPageWriter.__init__)rcCsLt|jƒ}|jƒ|jj|j|jƒ}tt|ƒ|_|jj|ƒ|jj	ƒ|_
dS)N)ÚNestedInlineTransformÚdocumentÚapplyrZcreate_translatorrÚManualPageTranslatorÚvisitorÚ	walkaboutÚastextÚoutput)rZ	transformr rrrÚ	translates
zManualPageWriter.translate)Ú__name__Ú
__module__Ú__qualname__rrr$Ú
__classcell__rr)rrrsrc@s2eZdZdZejddœdd„Zeddœdd„ZdS)	ra
    Flatten nested inline nodes:

    Before:
        <strong>foo=<emphasis>1</emphasis>
        &bar=<emphasis>2</emphasis></strong>
    After:
        <strong>foo=</strong><emphasis>var</emphasis>
        <strong>&bar=</strong><emphasis>2</emphasis>
    N)rrcCs
||_dS)N)r)rrrrrr.szNestedInlineTransform.__init__)ÚkwargsrcsÈttjtjtjƒ‰x°t|jjˆƒƒD]œ}t‡fdd„|Dƒƒr$|j	j
|ƒ}x`tt|ƒƒD]P}|j|ƒˆ|ƒr‚|j	j
|d|ƒqX|jdd|f|jŽ}|j	j
|d|ƒqXWt|ƒs$|j	j|ƒq$WdS)Nc3s|]}ˆ|ƒVqdS)Nr)Ú.0Úsubnode)Úmatcherrrú	<genexpr>4sz.NestedInlineTransform.apply.<locals>.<genexpr>éÚ)rrÚliteralZemphasisÚstrongÚlistrÚfindallÚanyÚparentÚindexÚreversedÚremoveÚinsertrÚ
attributesÚlen)rr)ÚnodeÚposr+Znewnoder)r,rr1s
zNestedInlineTransform.apply)	r%r&r'Ú__doc__rrrrrrrrrr#s
rcsTeZdZUdZiZeeefej	e
ddœ‡fdd„Zedœdd„Ze
dd	œd
d„Ze
dd	œdd
„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œdd„Ze
dd	œd d!„Ze
dd	œd"d#„Ze
dd	œd$d%„Ze
dd	œd&d'„Ze
dd	œd(d)„Ze
dd	œd*d+„Ze
dd	œd,d-„Ze
dd	œd.d/„Z e
dd	œd0d1„Z!e
dd	œd2d3„Z"e
dd	œd4d5„Z#e
dd	œd6d7„Z$e
dd	œd8d9„Z%e
dd	œd:d;„Z&e
dd	œd<d=„Z'e
dd	œd>d?„Z(e
dd	œd@dA„Z)e
dd	œdBdC„Z*e
dd	œdDdE„Z+e
dd	œ‡fdFdG„Z,e
dd	œdHdI„Z-e
dd	œ‡fdJdK„Z.e
dd	œdLdM„Z/e
dd	œdNdO„Z0e
dd	œdPdQ„Z1e
dd	œdRdS„Z2e
dd	œdTdU„Z3e
dd	œdVdW„Z4e
dd	œdXdY„Z5e
dd	œdZd[„Z6e
dd	œd\d]„Z7e
dd	œd^d_„Z8e
dd	œd`da„Z9e
dd	œdbdc„Z:e
dd	œddde„Z;e
dd	œdfdg„Z<e
dd	œdhdi„Z=e
dd	œdjdk„Z>e
dd	œdldm„Z?e
dd	œdndo„Z@e
dd	œdpdq„ZAe
dd	œdrds„ZBe
dd	œdtdu„ZCe
dd	œdvdw„ZDe
dd	œdxdy„ZEe
dd	œdzd{„ZFe
dd	œd|d}„ZGe
dd	œd~d„ZHe
dd	œd€d„ZIe
dd	œd‚dƒ„ZJe
dd	œd„d…„ZKe
dd	œd†d‡„ZLe
dd	œdˆd‰„ZMe
dd	œdŠd‹„ZNe
dd	œdŒd„ZOe
dd	œdŽd„ZPe
dd	œ‡fdd‘„ZQe
dd	œ‡fd’d“„ZRe
dd	œ‡fd”d•„ZSe
dd	œ‡fd–d—„ZTe
dd	œd˜d™„ZUe
dd	œdšd›„ZVe
dd	œdœd„ZWe
dd	œdždŸ„ZXe
dd	œd d¡„ZYe
dd	œd¢d£„ZZe
dd	œd¤d¥„Z[e
dd	œd¦d§„Z\‡Z]S)¨rz%
    Custom man page translator.
    N)rrrcsþtƒj||ƒd|_d|_|jj|jd<|jj|jd<|jjrL|jj|jd<|jj	|jd<|jdj
ƒ|jd<|jjr†|jj|jd<n"t
|jjp–td	ƒ|jjd
|jd<|jj|jd<|jj|jd<|jj|jd
<x&tjƒD]\}}|j|ƒ|jj|<qÜWdS)Nrr.ÚtitleÚsubtitleÚauthorZmanual_sectionZtitle_upperÚdatez	%b %d, %Y)ÚlanguageÚ	copyrightÚversionZmanual_groupéÿÿÿÿ)rrÚin_productionlistÚ
section_levelÚsettingsr?Ú_docinfor@ZauthorsÚsectionÚupperÚconfigÚtodayrZ	today_fmtr
rCrDrEÚprojectrÚitemsÚ	deunicodeÚlabels)rrrÚlabelÚtranslation)rrrrIs$zManualPageTranslator.__init__)rcCs d}|jdr|d7}||jS)NzW.TH "%(title_upper)s" "%(manual_section)s" "%(date)s" "%(version)s" "%(manual_group)s"
r@z#.SH NAME
%(title)s \- %(subtitle)s
)rJ)rÚtmplrrrÚheaderis
zManualPageTranslator.header)r<rcCsdS)Nr)rr<rrrÚvisit_start_of_fileqsz(ManualPageTranslator.visit_start_of_filecCsdS)Nr)rr<rrrÚdepart_start_of_filetsz)ManualPageTranslator.depart_start_of_filecCs|j|ƒdS)N)Zvisit_definition_list)rr<rrrÚ
visit_desc~szManualPageTranslator.visit_desccCs|j|ƒdS)N)Zdepart_definition_list)rr<rrrÚdepart_descsz ManualPageTranslator.depart_desccCs|j|ƒ|j|ƒdS)N)Zvisit_definition_list_itemÚ
visit_term)rr<rrrÚvisit_desc_signature„s
z)ManualPageTranslator.visit_desc_signaturecCs|j|ƒdS)N)Zdepart_term)rr<rrrÚdepart_desc_signatureˆsz*ManualPageTranslator.depart_desc_signaturecCsdS)Nr)rr<rrrÚvisit_desc_signature_line‹sz.ManualPageTranslator.visit_desc_signature_linecCs|jjdƒdS)Nú )ÚbodyÚappend)rr<rrrÚdepart_desc_signature_lineŽsz/ManualPageTranslator.depart_desc_signature_linecCs|j|ƒdS)N)Zvisit_definition)rr<rrrÚvisit_desc_content‘sz'ManualPageTranslator.visit_desc_contentcCs|j|ƒdS)N)Zdepart_definition)rr<rrrÚdepart_desc_content”sz(ManualPageTranslator.depart_desc_contentcCsdS)Nr)rr<rrrÚvisit_desc_inline—sz&ManualPageTranslator.visit_desc_inlinecCsdS)Nr)rr<rrrÚdepart_desc_inlinešsz'ManualPageTranslator.depart_desc_inlinecCsdS)Nr)rr<rrrÚvisit_desc_name sz$ManualPageTranslator.visit_desc_namecCsdS)Nr)rr<rrrÚdepart_desc_name£sz%ManualPageTranslator.depart_desc_namecCsdS)Nr)rr<rrrÚvisit_desc_addname¦sz'ManualPageTranslator.visit_desc_addnamecCsdS)Nr)rr<rrrÚdepart_desc_addname©sz(ManualPageTranslator.depart_desc_addnamecCsdS)Nr)rr<rrrÚvisit_desc_type¬sz$ManualPageTranslator.visit_desc_typecCsdS)Nr)rr<rrrÚdepart_desc_type¯sz%ManualPageTranslator.depart_desc_typecCs|jjdƒdS)Nz -> )r`ra)rr<rrrÚvisit_desc_returns²sz'ManualPageTranslator.visit_desc_returnscCsdS)Nr)rr<rrrÚdepart_desc_returnsµsz(ManualPageTranslator.depart_desc_returnscCs|jjdƒd|_dS)Nú(r.)r`raÚfirst_param)rr<rrrÚvisit_desc_parameterlist¸sz-ManualPageTranslator.visit_desc_parameterlistcCs|jjdƒdS)Nú))r`ra)rr<rrrÚdepart_desc_parameterlist¼sz.ManualPageTranslator.depart_desc_parameterlistcCs|js|jjdƒnd|_dS)Nz, r)rpr`ra)rr<rrrÚvisit_desc_parameter¿sz)ManualPageTranslator.visit_desc_parametercCsdS)Nr)rr<rrrÚdepart_desc_parameterÅsz*ManualPageTranslator.depart_desc_parametercCs|jjdƒdS)Nú[)r`ra)rr<rrrÚvisit_desc_optionalÈsz(ManualPageTranslator.visit_desc_optionalcCs|jjdƒdS)Nú])r`ra)rr<rrrÚdepart_desc_optionalËsz)ManualPageTranslator.depart_desc_optionalcCsdS)Nr)rr<rrrÚvisit_desc_annotationÎsz*ManualPageTranslator.visit_desc_annotationcCsdS)Nr)rr<rrrÚdepart_desc_annotationÑsz+ManualPageTranslator.depart_desc_annotationcCs|j|ƒdS)N)Zvisit_paragraph)rr<rrrÚvisit_versionmodifiedÖsz*ManualPageTranslator.visit_versionmodifiedcCs|j|ƒdS)N)Zdepart_paragraph)rr<rrrÚdepart_versionmodifiedÙsz+ManualPageTranslator.depart_versionmodifiedcs.t|jtjƒƒr|jjdƒntƒj|ƒdS)NÚ
)r4r3rr1r`rarr[)rr<)rrrr[ÝszManualPageTranslator.visit_termcCs
tj‚dS)N)rÚSkipNode)rr<rrrÚ
visit_commentäsz"ManualPageTranslator.visit_commentcs|jƒtƒj|ƒdS)N)Ú
ensure_eolrÚvisit_footnote)rr<)rrrr‚èsz#ManualPageTranslator.visit_footnotecCsb|jƒt|ƒdkrR|jƒdtdƒfkrR|jjd|j|jƒƒjƒdƒtj	‚n|jjdƒdS)Nr.Z	Footnotesz.SH r~z.sp
)
rr;r"r
r`rarQrLrr)rr<rrrÚvisit_rubricís
 "z!ManualPageTranslator.visit_rubriccCs|jjdƒdS)Nr~)r`ra)rr<rrrÚ
depart_rubricõsz"ManualPageTranslator.depart_rubriccCs|j|dƒdS)NÚseealso)Zvisit_admonition)rr<rrrÚ
visit_seealsoøsz"ManualPageTranslator.visit_seealsocCs|j|ƒdS)N)Zdepart_admonition)rr<rrrÚdepart_seealsoûsz#ManualPageTranslator.depart_seealsocCs2|jƒg}|jd7_|jjdƒtttj|ƒ}x|D]}|j|dƒq<Wtdd„|Dƒƒ}d}x¤|D]œ}|drÔ|dj	|ƒ}|jj|j
ddƒ|jj|j|ƒƒ|jj|j
ddƒ|jjdƒn |dk	rô|jjd	d
t|ƒƒ|j
|ƒ|jjdƒqnW|jjdƒ|jd8_tj‚dS)
Nr.z.sp
.nf
Z	tokennamecss|]}t|ƒVqdS)N)r;)r*Únamerrrr-sz<ManualPageTranslator.visit_productionlist.<locals>.<genexpr>r1rz ::= z%s     r_r~z
.fi
)rrGr`rarrrÚ
productionÚmaxÚljustÚdefsrQr;r!rr)rr<ÚnamesZproductionlistr‰ÚmaxlenÚlastnamerrrÚvisit_productionlistþs.


z)ManualPageTranslator.visit_productionlistcCsdS)Nr)rr<rrrÚvisit_productionsz%ManualPageTranslator.visit_productioncCsdS)Nr)rr<rrrÚdepart_productionsz&ManualPageTranslator.depart_productioncCsDd|jkr&|jjtdƒ|ddƒ|jjtdƒdƒtj‚dS)NZaltz[image: %s]r~z[image])r:r`rar
rr)rr<rrrÚvisit_images
z ManualPageTranslator.visit_imagecCsÈ|jj|jddƒ|j|ƒ|jj|jddƒ|jddƒ}|jdƒsj|jdƒsj|jdƒsj|jd	ƒr¾|jjr¾|jƒ|kr¾|jdƒr”|d
d…}|jj	d|jdd||jddd
gƒt
j‚dS)NÚ	referencerr.Zrefurir/zmailto:zhttp:zhttps:zftp:éz <r1ú>)r`rarŒÚ
visit_TextÚgetÚ
startswithrMZ
man_show_urlsr"Úextendrr)rr<ÚurirrrÚvisit_reference%s

z$ManualPageTranslator.visit_referencecCs&tj|jddƒƒ}|j|ƒtj‚dS)Nr?ú#)rZTextr˜r—r)rr<ÚtextrrrÚvisit_number_reference9s
z+ManualPageTranslator.visit_number_referencecCs|jƒ|jjdƒdS)Nz.sp
.ce
)rr`ra)rr<rrrÚvisit_centered>sz#ManualPageTranslator.visit_centeredcCs|jjdƒdS)Nz
.ce 0
)r`ra)rr<rrrÚdepart_centeredBsz$ManualPageTranslator.depart_centeredcCsdS)Nr)rr<rrrÚvisit_compact_paragraphEsz,ManualPageTranslator.visit_compact_paragraphcCsdS)Nr)rr<rrrÚdepart_compact_paragraphHsz-ManualPageTranslator.depart_compact_paragraphcCsdS)Nr)rr<rrrÚvisit_download_referenceKsz-ManualPageTranslator.visit_download_referencecCsdS)Nr)rr<rrrÚdepart_download_referenceNsz.ManualPageTranslator.depart_download_referencecCs
tj‚dS)N)rr)rr<rrrÚ
visit_toctreeQsz"ManualPageTranslator.visit_toctreecCs
tj‚dS)N)rr)rr<rrrÚvisit_indexTsz ManualPageTranslator.visit_indexcCs
tj‚dS)N)rr)rr<rrrÚvisit_tabular_col_specWsz+ManualPageTranslator.visit_tabular_col_speccCsdS)Nr)rr<rrrÚvisit_glossaryZsz#ManualPageTranslator.visit_glossarycCsdS)Nr)rr<rrrÚdepart_glossary]sz$ManualPageTranslator.depart_glossarycCs~ttj|dƒ}tttj|ƒ}|jƒttj|dƒ}tttj|ƒ}|jjdjdd„|Dƒƒdƒ|jjdƒtj	‚dS)Nrz, css|]}|jƒVqdS)N)r")r*Únrrrr-fsz2ManualPageTranslator.visit_acks.<locals>.<genexpr>Ú.r~)
rrÚbullet_listrZ	list_itemrr`raÚjoinr)rr<r­Z
list_itemsrrrÚ
visit_acks`s zManualPageTranslator.visit_ackscCs|j|ƒdS)N)Zvisit_bullet_list)rr<rrrÚvisit_hlistjsz ManualPageTranslator.visit_hlistcCs|j|ƒdS)N)Zdepart_bullet_list)rr<rrrÚdepart_hlistmsz!ManualPageTranslator.depart_hlistcCsdS)Nr)rr<rrrÚvisit_hlistcolpsz#ManualPageTranslator.visit_hlistcolcCsdS)Nr)rr<rrrÚdepart_hlistcolssz$ManualPageTranslator.depart_hlistcolcCs
|j|ƒS)N)Zvisit_emphasis)rr<rrrÚvisit_literal_emphasisvsz+ManualPageTranslator.visit_literal_emphasiscCs
|j|ƒS)N)Zdepart_emphasis)rr<rrrÚdepart_literal_emphasisysz,ManualPageTranslator.depart_literal_emphasiscCs
|j|ƒS)N)Úvisit_strong)rr<rrrÚvisit_literal_strong|sz)ManualPageTranslator.visit_literal_strongcCs
|j|ƒS)N)Ú
depart_strong)rr<rrrÚdepart_literal_strongsz*ManualPageTranslator.depart_literal_strongcCsdS)Nr)rr<rrrÚvisit_abbreviation‚sz'ManualPageTranslator.visit_abbreviationcCsdS)Nr)rr<rrrÚdepart_abbreviation…sz(ManualPageTranslator.depart_abbreviationcCs
|j|ƒS)N)r¶)rr<rrrÚ
visit_manpageˆsz"ManualPageTranslator.visit_manpagecCs
|j|ƒS)N)r¸)rr<rrrÚdepart_manpage‹sz#ManualPageTranslator.depart_manpagecs8t|jtjƒr(|jjdƒr(|jjdƒntƒj|ƒdS)NÚ
literal_blockz.sp
)	Ú
isinstancer5rÚ	containerr˜r`rarÚ
visit_caption)rr<)rrrrÁsz"ManualPageTranslator.visit_captioncs8t|jtjƒr(|jjdƒr(|jjdƒntƒj|ƒdS)Nr¾r~)	r¿r5rrÀr˜r`rarÚdepart_caption)rr<)rrrr•sz#ManualPageTranslator.depart_captioncsxt|jtjƒr|jjdƒdSt|jtjƒrl|jdkr>tj	‚n.|jdkrl|jjd|j
|jƒjƒƒƒtj	‚t
ƒj|ƒS)Nz.IP "rr.z.SH %s
)r¿r5rr…r`rarrKrHrrQr"rLrÚvisit_title)rr<)rrrrÜs

z ManualPageTranslator.visit_titlecs*t|jtjƒr|jjdƒdStƒj|ƒS)Nz"
)r¿r5rr…r`rarÚdepart_title)rr<)rrrrĪsz!ManualPageTranslator.depart_titlecCs.d|jddƒjƒkr$|jj|jƒƒtj‚dS)NZmanpageÚformatr/)r˜Úsplitr`rar"rr)rr<rrrÚ	visit_raw°szManualPageTranslator.visit_rawcCs
tj‚dS)N)rr)rr<rrrÚ
visit_metaµszManualPageTranslator.visit_metacCsdS)Nr)rr<rrrÚvisit_inline¸sz!ManualPageTranslator.visit_inlinecCsdS)Nr)rr<rrrÚ
depart_inline»sz"ManualPageTranslator.depart_inlinecCsdS)Nr)rr<rrrÚ
visit_math¾szManualPageTranslator.visit_mathcCsdS)Nr)rr<rrrÚdepart_mathÁsz ManualPageTranslator.depart_mathcCs|j|ƒdS)N)r )rr<rrrÚvisit_math_blockÄsz%ManualPageTranslator.visit_math_blockcCs|j|ƒdS)N)r¡)rr<rrrÚdepart_math_blockÇsz&ManualPageTranslator.depart_math_block)^r%r&r'r>rJrÚstrrrrrrrVrrWrXrYrZr\r]r^rbrcrdrerfrgrhrirjrkrlrmrnrqrsrtrurwryrzr{r|r}r[r€r‚rƒr„r†r‡rr‘r’r“rœrŸr r¡r¢r£r¤r¥r¦r§r¨r©rªr¯r°r±r²r³r´rµr·r¹rºr»r¼r½rÁrÂrÃrÄrÇrÈrÉrÊrËrÌrÍrÎr(rr)rrrBs¦
 

rN)$r>ÚtypingrrrrZdocutilsrZdocutils.nodesrrZdocutils.writers.manpager	ZBaseTranslatorr
ZsphinxrZsphinx.buildersrZ
sphinx.localer
rZsphinx.utilrZsphinx.util.docutilsrZsphinx.util.i18nrZsphinx.util.nodesrÚ	getLoggerr%ÚloggerrrrrrrrÚ<module>s