U C^ @sdZdZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z m Z ddlmZmZddlmZz ddlZWnPek rz"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__rrL/tmp/pip-install-6_kvzl1k/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|tjSN)rchoicer align_valuesargumentrrralign#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_valuesrr! argumentsZ escape2null splitlinesZ parse_target block_textlinenor referencerrZindirect_reference_namedocumentZ note_refnameappendr imageZadd_name)selfmessagesr2Zreference_nodeblockZ target_typedata image_noderrrrun5sd             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_specr;rrrrrs" rc@sLeZdZddZddZejZeed<ej ed<eed<dZ d d Z d S) FigurecCst|tjSr)rrr@r-rrrrrgsz Figure.aligncCs |dkrdSt|dSdS)Nr5Zpx)lowerrr<rrrrfigwidth_valuejs zFigure.figwidth_valuefigwidthfigclassrTc Cs|jdd}|jdd}|jdd}t|\}t|tjrH|gStd|}|dkrtr|j j j j rt j|d}ztj|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)NrCrDrr5r!\/z%dpxrrclassesz4Figure caption must be a paragraph or empty comment.)r#r)rE)-r'poprr;r(rZsystem_messagefigurer r)r3settingsZfile_insertion_enabledurllibrequest url2pathnameopenencodesysgetfilesystemencodingIOErrorUnicodeEncodeErrorZrecord_dependenciesaddreplacesizecontentElementZ nested_parseZcontent_offsetZ paragraphcaptionZ rawsourcechildrensourcer#commentlenZ state_machineZreporterr+Z literal_blockr0r1Zlegend) r6rCZ figclassesrr:Z figure_nodeZ imagepathimgnodeZ first_noderZr+rrrr;vsd         z Figure.runN) r r r rrBrr?copyrr>Z has_contentr;rrrrr@es  r@)__doc__Z __docformat__rQurllib.requestrL urllib.parse urllib.errorZdocutilsrrZdocutils.parsers.rstrrrZdocutils.nodesrrZdocutils.parsers.rst.rolesr Z PIL.Imager ImportErrorrobjectr@rrrrs&    H