o !ÔbÏqã@sÖddlZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl m Z ddl mZddlmZddlmZmZddlmZmZddlmZGd d „d ejƒZd d „Zed kriejd ddSdS)éN)ÚBytesIOÚStringIO)ÚMarkup)Ú Translator)ÚXML)ÚBadDirectiveErrorÚTemplateSyntaxError)ÚTemplateLoaderÚTemplateNotFound©ÚMarkupTemplatec@s eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zd6d7„Zd8d9„Zd:d;„Z dd?„Z"d@dA„Z#dBdC„Z$dDdE„Z%dFdG„Z&dHdI„Z'dJdK„Z(dLdM„Z)dNdO„Z*dPdQ„Z+dRdS„Z,dTdU„Z-dVdW„Z.dXdY„Z/dZd[„Z0d\d]„Z1d^d_„Z2d`da„Z3dbdc„Z4ddde„Z5dfS)gÚMarkupTemplateTestCasez%Tests for markup template processing.cCó,tdƒ}t|ƒ}| dt|jddƒ¡dS©Nz ${var} $varz 42 42é*©Úvar)rr Ú assertEqualÚstrÚgenerate)ÚselfÚfileobjÚtmpl©rú>/usr/lib/python3/dist-packages/genshi/template/tests/markup.pyÚtest_parse_fileobj$óz)MarkupTemplateTestCase.test_parse_fileobjcCrr)rr rrr)rÚstreamrrrrÚtest_parse_stream)rz(MarkupTemplateTestCase.test_parse_streamcCsTtdƒ}t|ƒ}tƒ}t ||d¡| d¡t |¡}| dt|j ddƒ¡dS)Nz$varérz42rr) rr rÚpickleÚdumpÚseekÚloadrrr)rrrÚbufÚ unpickledrrrÚ test_pickle.s  z"MarkupTemplateTestCase.test_picklecCó$tdƒ}| dt|jddƒ¡dSr©r rrr©rrrrrÚtest_interpolate_mixed37óz.MarkupTemplateTestCase.test_interpolate_mixed3cCr')Nz${ foo }zbarÚbar©Úfoor(r)rrrÚ'test_interpolate_leading_trailing_space;r+z>MarkupTemplateTestCase.test_interpolate_leading_trailing_spacecCr')Nz:${dict( bar = 'baz' )[foo]}zbazr,r-r(r)rrrÚtest_interpolate_multiline?sz1MarkupTemplateTestCase.test_interpolate_multilinecCó tdƒ}| dt| ¡ƒ¡dS)Nzzr(r)rrrÚ!test_interpolate_non_string_attrsEóz8MarkupTemplateTestCase.test_interpolate_non_string_attrscCr')Nz$foozbuzz)Úbuzzr-r(r)rrrÚtest_interpolate_list_resultIr+z3MarkupTemplateTestCase.test_interpolate_list_resultcCs tdƒ}| dt| ¡ƒ¡dS)Núr(r)rrrÚtest_empty_attrMr3z&MarkupTemplateTestCase.test_empty_attrcCr')Nzr6Ú)Úattrr(r)rrrÚtest_empty_attr_interpolatedQr+z3MarkupTemplateTestCase.test_empty_attr_interpolatedc CsZd}z t|dd}WdSty,}z| d|j¡| d|j¡WYd}~dSd}~ww)Nz<

ú test.html©Úfilenameé)r rrr=Úlineno©rÚxmlrÚerrrÚtest_bad_directive_errorUs€þz/MarkupTemplateTestCase.test_bad_directive_errorc Cshd}zt|dd ¡}| d¡WdSty3}z| d|j¡| d|j¡WYd}~dSd}~ww)Nz9

r;r<úExpected TemplateSyntaxErrorr>)r rÚfailrrr=r?r@rrrÚ!test_directive_value_syntax_error]s€þz8MarkupTemplateTestCase.test_directive_value_syntax_errorc Códd}zt|dd}| d¡WdSty1}z| d|j¡| d|j¡WYd}~dSd}~ww)Nz/

Foo ${bar"}

r;r<rDr©r rErrr=r?r@rrrÚtest_expression_syntax_errorfs €þz3MarkupTemplateTestCase.test_expression_syntax_errorc CrG)Nz$

${bar"}

r;r<rDérHr@rrrÚ'test_expression_syntax_error_multi_lineqs €þz>MarkupTemplateTestCase.test_expression_syntax_error_multi_linecCs(tdƒ}| dt|jtdƒdƒ¡dS)zi Verify that outputting context data that is a `Markup` instance is not escaped. úL
$myvar
z)
foo
z foo©ÚmyvarN)r rrrrr)rrrÚtest_markup_noescape~sþz+MarkupTemplateTestCase.test_markup_noescapecCó$tdƒ}| dt|jddƒ¡dS)zb Verify that outputting context data in text nodes doesn't escape quotes. rLz$
"foo"
ú"foo"rMNr(r)rrrÚtest_text_noescape_quotesŠsþz0MarkupTemplateTestCase.test_text_noescape_quotescCrP)zR Verify that outputting context data in attribtes escapes quotes. z\
z<
rQrMNr(r)rrrÚtest_attr_escape_quotes–sþz.MarkupTemplateTestCase.test_attr_escape_quotescCr')Nze
bar
z"
bar
rQrMr(r)rrrÚtest_directive_element¡sþz-MarkupTemplateTestCase.test_directive_elementcCr1)NzV
z/
r(r)rrrÚtest_normal_comment©s þz*MarkupTemplateTestCase.test_normal_commentcCr1)Nzi
z
r(r)rrrÚtest_template_comment±s ÿz,MarkupTemplateTestCase.test_template_commentcCr1)Nz…
z7
r(r)rrrÚ%test_parse_with_same_namespace_nested¹s ýz
ö
ú iso-8859-1©ÚencodinguM
ö
©r ÚencoderÚsixÚ text_typerr)rrrÚ test_latin1_encoded_with_xmldeclÃs ý þz7MarkupTemplateTestCase.test_latin1_encoded_with_xmldeclcCrX)NuH
ö
rYrZu!
ö
r\r)rrrÚ%test_latin1_encoded_explicit_encodingÌs þ þz Nr )rrrrÚtest_exec_with_trailing_spaceÔs z4MarkupTemplateTestCase.test_exec_with_trailing_spacecCr1)Nz
${timedelta(days=2)}
z.
2 days, 0:00:00
r(r)rrrÚtest_exec_importßs þz'MarkupTemplateTestCase.test_exec_importcCr1)Nzœ
${foo()}
z!
42
r(r)rrrÚ test_exec_defès þz$MarkupTemplateTestCase.test_exec_defcCs tdƒ}| dt| ¡ƒ¡dS)zÈ Verify that a namespace declaration on an element that is removed from the generated stream does not get pushed up to the next non-stripped element (see ticket #107). z¢ Size zI Nr(r)rrrÚtest_namespace_on_removed_elemõs ýz5MarkupTemplateTestCase.test_namespace_on_removed_elemc CóÆtjdd}zVttj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gƒ}|  d¡}|  d|j d d j dd ¡Wt  |¡dSt  |¡w) NÚ genshi_test©Úsuffixú tmpl1.htmlÚwú
Included $idx
ú tmpl2.htmlzã úp
Included 0
Included 1
Included 2
Útmpl1©ÚnamerZ©ÚtempfileÚmkdtempÚopenÚosÚpathÚjoinÚwriteÚcloser r#rrÚrenderÚshutilÚrmtree©rÚdirnameÚfile1Úfile2ÚloaderrrrrÚtest_include_in_loopó     þz+MarkupTemplateTestCase.test_include_in_loopc Crf) Nrgrhrjrkú
Included
rmzÊ úD
Included
rorprZrrr~rrrÚtest_dynamic_include_hrefr„z0MarkupTemplateTestCase.test_dynamic_include_hrefc CóÂtjdd}zTttj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gƒ}|  d¡}|  d|  ¡j dd ¡Wt  |¡dSt  |¡w) Nrgrhrjrkz
  • $item
  • rmac
      ${select('li')}
    zX
    • 1
    • 2
    • 3
    rZrrr~rrrÚtest_select_included_elements9ó     þz4MarkupTemplateTestCase.test_select_included_elementsc Crˆ) Nrgrhrjrkr…rmú¾ Missing r†rZrrr~rrrÚ test_fallback_when_include_foundVs     þz7MarkupTemplateTestCase.test_fallback_when_include_foundc CsŠtjdd}z8ttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gdd}|  d¡}|  t |  ¡j ¡Wt |¡dSt |¡w)Nrgrhrmrkz{ T©Ú auto_reload)rsrtrurvrwrxryrzr r#Ú assertRaisesr rr{r|r}©rrrr‚rrrrÚ!test_error_when_include_not_foundps   z8MarkupTemplateTestCase.test_error_when_include_not_foundc CóŒtjdd}z9ttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gƒ}|  d¡}|  d|  ¡j dd¡Wt  |¡dSt  |¡w)Nrgrhrmrkz¼ Missing z8 Missing rZrrrrrrÚ$test_fallback_when_include_not_founds    þz;MarkupTemplateTestCase.test_fallback_when_include_not_foundc Cstjdd}z;ttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gdd}|  d¡}|  d|  ¡j dd ¡Wt  |¡dSt  |¡w) Nrgrhrmrkr‹Trz: Missing rZrrrrrrÚ#test_fallback_when_auto_reload_true•s   þz:MarkupTemplateTestCase.test_fallback_when_auto_reload_truec Crˆ) Nrgrhrjrkr…ú tmpl3.htmlás Missing zH
    Included
    rZrrr~rrrÚtest_include_in_fallback©s     þz/MarkupTemplateTestCase.test_include_in_fallbackc Cr’)Nrgrhr•rkr–z< Missing rZrrrrrrÚtest_nested_include_fallbackÈs    þz3MarkupTemplateTestCase.test_nested_include_fallbackc Crˆ) Nrgrhrmrkr…r•a r†rZrrr~rrrÚtest_nested_include_in_fallbackárŠz6MarkupTemplateTestCase.test_nested_include_in_fallbackc Cstjdd}z;ttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gƒ}|  d¡}|  d|j ddj dd ¡Wt  |¡dSt  |¡w) Nrgrhrmrka6 tmpl1.html not found zG tmpl1.html not found T)ÚdebugrZrrrrrrÚ$test_include_fallback_with_directiveþs    þz;MarkupTemplateTestCase.test_include_fallback_with_directivec CsØtjdd}z_ttj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gdd }|  d¡}|  d t |j ƒ¡|  d |  ¡jdd ¡Wt |¡dSt |¡w) Nrgrhrjrkr…rmzÈ Frér†rZ)rsrtrurvrwrxryrzr r#rÚlenrrr{r|r}r~rrrÚtest_include_inlineds"    þz+MarkupTemplateTestCase.test_include_inlinedc CsÆtjdd}zVttj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gdd }|  d¡}|  d |  ¡j dd ¡Wt  |¡dSt  |¡w) Nrgrhrjrkrlrmzá FrrnrZrrr~rrrÚtest_include_inlined_in_loop0s    þz3MarkupTemplateTestCase.test_include_inlined_in_loopc Csžtjdd}zBttj |d¡dƒ}z | d¡W| ¡n| ¡wt|gdd}|  tj |d¡¡}|  d|j d d j dd ¡Wt  |¡dSt  |¡w) NrgrhrjrkzÝ
    $depth
    Frz$
    0
    1
    2
    r)ÚdepthrZrr)rrr€r‚rrrrÚtest_include_inline_recursiveJs ÿ þz4MarkupTemplateTestCase.test_include_inline_recursivec CsJd}zt|ddd}| d¡WdSty$}zWYd}~dSd}~ww)Núì This is replaced. r;F©r=Ú allow_execzExpected SyntaxError)r rErr@rrrÚtest_allow_exec_falsedsÿ€ÿz,MarkupTemplateTestCase.test_allow_exec_falsecCsd}t|ddd}dS)Nr¢r;Tr£r ©rrArrrrÚtest_allow_exec_truetsz+MarkupTemplateTestCase.test_allow_exec_truecCs.d}t|ddd}| d| ¡jdd¡dS)Nzå ${title}

    moot text

    r;Tr£zW wakka wakka wakka rZ©r rrr{r¦rrrÚtest_exec_in_matchs üz)MarkupTemplateTestCase.test_exec_in_matchcCó,d}t|dd}| d| ¡jdd¡dS)Nzó

    ${select('text()')}

    ${select('.')}

    ${foo}

    r;r<zi

    bar

    bar

    rZr¨r¦rrrÚtest_with_in_matchŽs  ûz)MarkupTemplateTestCase.test_with_in_matchc Csøtjdd}zottj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d¡W| ¡n| ¡wttj |d¡dƒ}z | d ¡W| ¡n| ¡wt|gƒ}|  d¡}|  d |  ¡j dd ¡Wt  |¡dSt  |¡w) Nrgrhrjrkzl
    Some content.
    rmzÚ

    Some full html document that includes file1.html

    r•a 
    Some added stuff. ${select('*|text()')}

    Some full html document that includes file1.html

    Some added stuff. Some content.
    rZrr)rrr€rÚfile3r‚rrrrÚtest_nested_include_matchesžs(       ö z2MarkupTemplateTestCase.test_nested_include_matchescCrª)Nak ${select('*|text')} And some other stuff... Foo Bar r;r<z‚ Foo And some other stuff... rZr¨r¦rrrÚ%test_nested_matches_without_bufferingÔs  ûz This replaces the other text. This gets replaced. r;r<zi This replaces the other text. rZr¨r¦rrrÚtest_match_without_selectés  üz0MarkupTemplateTestCase.test_match_without_selectcCrª)Nal ${select('.')} fish fish fish fish r;r<zî fish fish fish fish rZr¨r¦rrrÚtest_match_tail_handlingüs  ùz/MarkupTemplateTestCase.test_match_tail_handlingcCs:tdƒ}tdd„ƒ}| tj|¡| dt| ¡ƒ¡dS)NzÒ
    cSs|S)Nr)ÚsrrrÚszSMarkupTemplateTestCase.test_directive_single_line_with_translator..zR
    0 1
    )r rÚadd_directivesÚ NAMESPACErrr)rrÚ translatorrrrÚ*test_directive_single_line_with_translators   ýzAMarkupTemplateTestCase.test_directive_single_line_with_translatorN)6Ú__name__Ú __module__Ú __qualname__Ú__doc__rrr&r*r/r0r2r5r7r:rCrFrIrKrOrRrSrTrUrVrWr`rarbrcrdrerƒr‡r‰rŒr‘r“r”r—r˜r™r›ržrŸr¡r¥r§r©r«r­r®r¯r°r¶rrrrr !sh             6 r cCs0t ¡}| t tj¡¡| t td¡¡|S)NÚtest) ÚunittestÚ TestSuiteÚaddTestÚdoctestÚ DocTestSuiter r¸Ú makeSuiter )ÚsuiterrrrÂ"srÂÚ__main__)Ú defaultTest)r¿rvr r|Úsysrsr¼r^Ú genshi.compatrrÚ genshi.corerÚgenshi.filters.i18nrÚ genshi.inputrÚgenshi.template.baserrÚgenshi.template.loaderr r Úgenshi.template.markupr ÚTestCaser rÂr·ÚmainrrrrÚs4     ÿ