B \ @sdZdZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z m Z ddlmZmZddlmZy ddlZWnPek ry"ddlZGd d d eZee_Wnek rdZYnXYnXGd d d e ZGd ddeZdS)z+ Directives for figures and simple images. ZreStructuredTextN)nodesutils) Directive) directivesstates)fully_normalize_namewhitespace_normalize_name) set_classesc@s eZdZdS)PILN)__name__ __module__ __qualname__rrJ/tmp/pip-build-uw_ogi45/docutils/docutils/parsers/rst/directives/images.pyr sr c @s\eZdZdZdZeeZddZdZdZdZ e j e j e j e jee j e je jdZd d Zd S) Image)leftcenterright)topZmiddleZbottomcCst|tjS)N)rchoicer align_values)argumentrrralign#sz Image.alignrT)ZaltheightwidthZscalernametargetclasscCsd|jkrt|jtjrN|jd|jkr|d|j|jdd|jfn4|jd|j kr|d|j|jdd|j fg}t |j d}||jd<d}d|jkrJt |jd}dd |D}|j||j|j\}}|d krtj|d }n@|d kr8tjt|t|d }||_|jj|n |||jd=t|jtj|jf|j}|||r||7}||gS||gSdS)NrzError in "%s" directive: "%s" is not a valid value for the "align" option within a substitution definition. Valid values for "align" are: "%s".z", "zoError in "%s" directive: "%s" is not a valid value for the "align" option. Valid values for "align" are: "%s".rurircSsg|]}|qSrr).0linerrr MszImage.run..refuri)r#refname)r$r)options isinstancestaterZSubstitutionDefalign_v_valueserrorrjoinalign_h_valuesrrZ argumentsZ escape2null splitlinesZ parse_target block_textlinenor referencerrZindirect_reference_namedocumentZ note_refnameappendr imageZadd_name)selfmessagesr/Zreference_nodeblockZ target_typedata image_noderrrrun5sN            z Image.runN)r r r r+r(rrZrequired_argumentsZoptional_argumentsZfinal_argument_whitespacerZ unchangedZlength_or_unitless length_or_percentage_or_unitless percentageZunchanged_required class_option option_specr8rrrrrs  rc@sLeZdZddZddZejZeed<ej ed<eed<dZ d d Z d S) FigurecCst|tjS)N)rrr=r+)rrrrrgsz Figure.aligncCs |dkrdSt|dSdS)Nr2Zpx)lowerrr9)rrrrfigwidth_valuejs zFigure.figwidth_valuefigwidthfigclassrTc Cs|jdd}|jdd}|jdd}t|\}t|tjrH|gStd|}|dkrtr|j j j j rt j|d}ytj|t}Wnttfk rYqX|j j j j|ddd |jd |d <~n|dk r||d <|r|d |7<|r||d<|jrt}|j |j|j||d } t| tjr~tj| j df| j!} | j"| _"| j#| _#|| 7}nFt| tj$rt%| d ks|j&j'j(d t)|j*|j*|j+d} || gSt%|dkr|tj,d|dd7}|gS)Nr@rArr2r\/z%dpxrrclassesz4Figure caption must be a paragraph or empty comment.)r!r)rB)-r%poprr8r&rZsystem_messagefigurer r'r0settingsZfile_insertion_enabledurllibrequest url2pathnameopenencodesysgetfilesystemencodingIOErrorUnicodeEncodeErrorZrecord_dependenciesaddreplacesizecontentElementZ nested_parseZcontent_offsetZ paragraphcaptionZ rawsourcechildrensourcer!commentlenZ state_machineZreporterr)Z literal_blockr-r.Zlegend) r3r@Z figclassesrr7Z figure_nodeZ imagepathimgnodeZ first_noderWr)rrrr8vsZ        z Figure.runN) r r r rr?rr<copyrr;Z has_contentr8rrrrr=es  r=)__doc__Z __docformat__rNurllib.requestrI urllib.parse urllib.errorZdocutilsrrZdocutils.parsers.rstrrrZdocutils.nodesrrZdocutils.parsers.rst.rolesr Z PIL.Imager ImportErrorrobjectr=rrrrs&    H