3

T'ícÀ?ã@sødZddlmZmZmZmZmZmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZddlmZdd	lmZdd
lmZerœddlmZejeƒZeje dœd
d„Z!Gdd„dƒZ"Gdd„de"ƒZ#Gdd„de#ƒZ$Gdd„dƒZ%dS)z¨Utility code for "Doc fields".

"Doc fields" are reST field lists in object descriptions that will
be domain-specifically transformed to a more appealing presentation.
é)Ú
TYPE_CHECKINGÚAnyÚDictÚListÚTupleÚTypeÚUnionÚcast)Únodes)ÚNode)ÚInliner)Úaddnodes)ÚBuildEnvironment)Ú__)Úlogging)ÚTextlikeNode)ÚObjectDescription)ÚnodeÚreturncCsZt|ƒdkrdSt|ƒdkrBx$|dd…D]}t|tjƒs*dSq*Wt|dtjƒrVdSdS)zCTrue if the node only contains one paragraph (and system messages).rFéNT)ÚlenÚ
isinstancer
Zsystem_messageÚ	paragraph)rZsubnode©rú7/tmp/pip-build-gk9425m9/sphinx/sphinx/util/docfields.pyÚ_is_single_paragraphsrc@söeZdZdZdZdZfddddfeeedfeeeeddœdd„Z	e
jddddfeeeee
eeeeed	œ	d
d„Ze
jddddfeeeee
eeeeeed	œ	dd
„Zeeeeeeefdœdd„Zdeeeefeeeeeejdœdd„ZdS)ÚFielda¼A doc field that is never grouped.  It can have an argument or not, the
    argument can be linked using a specified *rolename*.  Field should be used
    for doc fields that usually don't occur more than once.

    The body can be linked using a specified *bodyrolename* if the content is
    just a single inline or text node.

    Example::

       :returns: description of the return value
       :rtype: description of the return type
    FNT.)ÚnameÚnamesÚlabelÚhas_argÚrolenameÚbodyrolenamercCs(||_||_||_||_||_||_dS)N)rrrr r!r")Úselfrrrr r!r"rrrÚ__init__5szField.__init__)	r!ÚdomainÚtargetÚ	innernodeÚcontnodeÚenvÚinlinerÚlocationrc	Csú|dk	st‚|dk|dkks(t||fƒ‚|s:|p8|||ƒS|j|ƒj|ƒ}	|	dksZ|dkrÂ|	dkrˆ|dk	rˆtdƒ}
tjt|
ƒ|||dtjd|d||d}||pª|||ƒ7}|j|ƒj|ƒ|St	j
|ƒd}|	|||||igƒ\}
}tj|df|
žŽS)Nz]Problem in %s domain: field is supposed to use role '%s', but that role is not in the domain.)r+ÚF)Z	refdomainZrefexplicitZreftypeZ	reftargetr)
ÚAssertionErrorZ
get_domainÚrolerÚloggerÚwarningr
Zpending_xrefZprocess_field_xrefrZget_source_liner
Úinline)r#r!r%r&r'r(r)r*r+r.ÚmsgZrefnodeÚlinenoÚnsÚmessagesrrrÚ	make_xref>s"

zField.make_xrefc			Cs|j||||||||ƒgS)N)r6)	r#r!r%r&r'r(r)r*r+rrrÚ
make_xrefsXszField.make_xrefs)ÚfieldargÚcontentrcCs||fS)Nr)r#r8r9rrrÚ
make_entry_szField.make_entry)Útypesr%Úitemr)r*r+rc
Csä|\}}tjd|jƒ}	|rJ|	tjdƒ7}	|	j|j|j||tj|||dƒt|ƒdkrÀt|dtjƒsšt|dtj	ƒrÀt|dƒdkrÀt|ddtjƒrÀ|j|j
||djƒ|d|||d}tjdtj
d|žŽƒ}
tjd|	|
ƒS)Nr,ú )r)r*r+rr)r(r)r*r+)r,r,)r
Ú
field_namerÚTextÚextendr7r!rrr1r"ÚastextÚ
field_bodyrÚfield)r#r;r%r<r)r*r+r8r9Ú	fieldnameÚ	fieldbodyrrrÚ
make_fieldbs  
zField.make_field)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
is_groupedÚis_typedÚstrrÚboolr$r
Úliteral_emphasisrrrrrr6rr7r:rr
rCrFrrrrr%s*	(,"rc	sveZdZdZdZejZfdddfee	edfeee
ddœ‡fdd„
Zdeee
efee	eeeejd	œd
d„Z‡ZS)
ÚGroupedFielda×
    A doc field that is grouped; i.e., all fields of that type will be
    transformed into one field with its body being a bulleted list.  It always
    has an argument.  The argument can be linked using the given *rolename*.
    GroupedField should be used for doc fields that can occur more than once.
    If *can_collapse* is true, this field will revert to a Field if only used
    once.

    Example::

       :raises ErrorClass: description when it is raised
    TNF.)rrrr!Úcan_collapsercstƒj|||d|ƒ||_dS)NT)Úsuperr$rQ)r#rrrr!rQ)Ú	__class__rrr$ˆszGroupedField.__init__)r;r%Úitemsr)r*r+rcCsÒtjd|jƒ}|jƒ}x`|D]X\}	}
tjƒ}|j|j|j||	tj	|||dƒ|tj
dƒ7}||
7}|tjd|ƒ7}qWt|ƒdkr¸|j
r¸ttj|dƒ}tjd|dƒ}
tjd||
ƒStjd|ƒ}
tjd||
ƒS)Nr,)r)r*r+z -- rr)r
r>rÚ	list_typerr@r7r!r
Úliteral_strongr?Ú	list_itemrrQr	rBrC)r#r;r%rTr)r*r+rDZlistnoder8r9ÚparrWrErrrrFs zGroupedField.make_field)NNN)rGrHrIrJrKr
Zbullet_listrUrMrrNr$rrrrrrCrFÚ
__classcell__rr)rSrrPxs*rPc
s€eZdZdZdZffddddfeeedfeedfeeeeddœ‡fdd„
Zde	ee
efeeee
eejd	œd
d„Z‡ZS)
Ú
TypedFieldaa
    A doc field that is grouped and has type information for the arguments.  It
    always has an argument.  The argument can be linked using the given
    *rolename*, the type using the given *typerolename*.

    Two uses are possible: either parameter and type description are given
    separately, using a field from *names* and one from *typenames*,
    respectively, or both are given using a field from *names*, see the example.

    Example::

       :param foo: description of parameter foo
       :type foo:  SomeClass

       -- or --

       :param SomeClass foo: description of parameter foo
    TNF.)rrÚ	typenamesrr!ÚtyperolenamerQrcs$tƒj|||||ƒ||_||_dS)N)rRr$r[r\)r#rrr[rr!r\rQ)rSrrr$¹szTypedField.__init__)r;r%rTr)r*r+rc
s¤tttjdœ‡‡‡‡‡‡fdd„}tjdˆjƒ}t|ƒdkrZˆjrZ|d\}	}
||	|
ƒ}n0ˆjƒ}x&|D]\}	}
|tjd||	|
ƒƒ7}qhWtj	d|ƒ}tj
d||ƒS)N)r8r9rc
sÂtjƒ}|jˆjˆjˆ|tjˆdƒ|ˆkr¨|tjdƒ7}ˆj|ƒ}t	|ƒdkr’t
|dtjƒr’|djƒ}|jˆjˆjˆ|tj
ˆˆˆdƒn||7}|tjdƒ7}|tjdƒ7}||7}|S)N)r)z (rr)r)r*r+ú)z -- )r
rr@r7r!r
rVr?ÚpoprrrAr\rO)r8r9rXÚ	fieldtypeÚtypename)r%r)r*r+r#r;rrÚhandle_itemÃs 
z*TypedField.make_field.<locals>.handle_itemr,rr)rMr
rr>rrrQrUrWrBrC)
r#r;r%rTr)r*r+rarDr8r9ZbodynoderEr)r%r)r*r+r#r;rrFÀs"zTypedField.make_field)NNN)rGrHrIrJrLrMrrNr$rrrrrr
rCrFrYrr)rSrrZ¤s4rZc@sZeZdZUdZeeeeeff	dddœdd„Z
ejddœdd	„Z
ejddœd
d„ZdS)ÚDocFieldTransformerz
    Transforms field lists in "doc field" syntax into better-looking
    equivalents, using the field type definitions given on a domain.
    rN)Ú	directivercCs||_|jƒ|_dS)N)rcZget_field_type_mapÚtypemap)r#rcrrrr$ìszDocFieldTransformer.__init__)rrcCs(x"|D]}t|tjƒr|j|ƒqWdS)z,Transform all field list children of a node.N)rr
Ú
field_listÚ	transform)r#rÚchildrrrÚ
transform_allñs
z!DocFieldTransformer.transform_allc!Cs®|j}g}i}i}xtttj|ƒD]ö}t|ƒdks<t‚ttj|dƒ}ttj|dƒ}y|j	ƒj
ddƒ\}	}
Wn"tk
r–|j	ƒd}	}
YnX|j|	d
ƒ\}}t
|ƒrÈttj|dƒ}
|
j}n|j}|dksæ|jt|
ƒkrÜ|	dd…jƒ|	dd…}|
r|d|
7}tj|ƒ|d<|j|ƒ|r&|r&|r&t|ƒdkr&t|dtjƒr&tt|ƒ}|dj	ƒ}|j|j|jj||d|jjjjjd}t
|ƒrÀttj|dƒ}
|
jƒ|
j |ƒq&|jƒ|tjd|žŽ7}q&|j!}|rdd	„|Dƒ}|r&||j"|iƒ|
<q&|j#r\y|
j$ddƒ\}}Wntk
r>YnXtj|ƒg|j"|iƒ|<|}
tj%|j&d
d}|j'j|_|j'j(|_(|j'j)|_)||7}|j*r||krÂtt+t,tt-f|||ƒ}n t|ƒ||<|g|f}|j|ƒ|j.|
|gƒ}|dj|ƒq&|j.|
|gƒ}|j|||fƒq&Wtj/ƒ}xt|D]l}t|tjƒrL||7}nN|\}}}|j|j!iƒ}|jjjjj}|jjj0} ||j1||jj||| |d7}q0W|j2|ƒdS)z%Transform a single field list *node*.érrNr,r=)r(r)cSs"g|]}t|tjtjfƒr|‘qSr)rr
ZInliner?)Ú.0Únrrrú
<listcomp>:sz1DocFieldTransformer.transform.<locals>.<listcomp>T)Ztranslatable)r)r*r+)NN)r,r,)3rdr	rr
rCrr-r>rBrAÚsplitÚ
ValueErrorÚgetrrÚchildrenr rNÚupperr?ÚappendrrZr7r\rcr%ÚstateÚdocumentÚsettingsr)Úclearr@rÚ
setdefaultrLÚrsplitr1Z	rawsourceÚparentÚsourceÚlinerKrrrr:rer*rFZreplace_self)!r#rrdÚentriesZgroupindicesr;rCr>rBZfieldtype_namer8ZtypedescZis_typefieldrr9Z
new_fieldnameZtyped_fieldr&Zxrefsr`ZargtypeZargnameZtranslatable_contentÚgroupZ	new_entryZnew_listÚentryr_rTr+Z
fieldtypesr)r*rrrrføs 












zDocFieldTransformer.transform)rGrHrIrJrrMrrrNrdr$r
Zdesc_contentrhr
rerfrrrrrbås

rbN)&rJÚtypingrrrrrrrr	Zdocutilsr
Zdocutils.nodesrZdocutils.parsers.rst.statesrZsphinxr
Zsphinx.environmentrZ
sphinx.localerZsphinx.utilrZsphinx.util.typingrZsphinx.directivesrÚ	getLoggerrGr/rBrNrrrPrZrbrrrrÚ<module>s"(

S,A