Ϫf}AdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z Gdd e jZGd d e jZGd d e jZGdde jZGdde jZGdde jZGdde jZGdde jZGdde j.Zy)z HTTP errors. ) annotationsN) nativeString)unittest)error)Tagc(eZdZdZddZddZddZy)CodeToMessageTestsz< L{_codeToMessages} inverts L{_responses.RESPONSES} cRtjd}|j|dy)N302sFoundr_codeToMessage assertEqualselfms =/usr/lib/python3/dist-packages/twisted/web/test/test_error.pytest_validCodez!CodeToMessageTests.test_validCodes"   ( H%cRtjd}|j|dy)Ns987r rs rtest_invalidCodez#CodeToMessageTests.test_invalidCodes"   ( D!rcRtjd}|j|dy)Ns InvalidCoder rs rtest_nonintegerCodez&CodeToMessageTests.test_nonintegerCode!s"   0 D!rNreturnNone)__name__ __module__ __qualname____doc__rrrrrr r s&""rr c8eZdZdZddZddZddZddZddZy) ErrorTestsz< Tests for how L{Error} attributes are initialized. ctjd}|j|jd|jt |dy)z If no C{message} argument is passed to the L{Error} constructor and the C{code} argument is a valid HTTP status code, C{message} is set to the HTTP reason phrase for C{code}. 200OK200 OKNrErrorrmessagestrres rtest_noMessageValidStatusz$ErrorTests.test_noMessageValidStatus+s: KK  E* Q*rctjd}|j|jd|jt |dy)z If no C{message} argument is passed to the L{Error} constructor and C{code} isn't a known HTTP status code, C{message} stays L{None}. 999N999r'r+s rtest_noMessageForStatusz"ErrorTests.test_noMessageForStatus5s: KK  D) Q'rc|jt5tjddddy#1swYyxYw)z If C{code} isn't plausibly an HTTP status code (i.e., composed of digits) it is rejected with L{ValueError}. s InvalidStatusN) assertRaises ValueErrorrr(rs rtest_invalidStatuszErrorTests.test_invalidStatus>s4   z * * KK( ) * * *s5>ctjdd}|j|jd|jt |dy)z If a C{message} argument is passed to the L{Error} constructor, the C{message} isn't affected by the value of C{status}. r$My own messagez200 My own messageNr'r+s rtest_messageExistszErrorTests.test_messageExistsFs? KK 1 2 $56 Q!56rctjdd}|jt|dtjdd}|jt|dy)zh C{str()} on an L{Error} returns the code and message it was instantiated with. r$r%r&N)rr(rr*r+s rtest_strzErrorTests.test_strOsN KK & Q* KKU # Q*rNr) rrrrr-r1r6r9r<r rrr"r"&s +(*7 +rr"c8eZdZdZddZddZddZddZddZy) PageRedirectTestszC Tests for how L{PageRedirect} attributes are initialized. cjtjdd}|j|jdy)z If no C{message} argument is passed to the L{PageRedirect} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned. r$/foolocation OK to /fooNr PageRedirectrr)r+s rr-z+PageRedirectTests.test_noMessageValidStatusbs*   v 8 M2rcftjd}|j|jdy)a; If no C{message} argument is passed to the L{PageRedirect} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location. r$r%NrDr+s r#test_noMessageValidStatusNoLocationz5PageRedirectTests.test_noMessageValidStatusNoLocationks(   v & E*rcjtjdd}|j|jdy)z If no C{message} argument is passed to the L{PageRedirect} constructor and C{code} isn't a valid HTTP status code, C{message} stays L{None}. r/r@rANrDr+s r)test_noMessageInvalidStatusLocationExistsz;PageRedirectTests.test_noMessageInvalidStatusLocationExistsus*   v 8 D)rcltjddd}|j|jdy)z If a C{message} argument is passed to the L{PageRedirect} constructor, the C{message} isn't affected by the value of C{status}. r$r8r@rAMy own message to /fooNrDr+s r test_messageExistsLocationExistsz2PageRedirectTests.test_messageExistsLocationExists}s.   v'87 K $=>rchtjdd}|j|jdy)z If a C{message} argument is passed to the L{PageRedirect} constructor and no location is provided, C{message} doesn't try to include the empty location. r$r8NrDr+s rtest_messageExistsNoLocationz.PageRedirectTests.test_messageExistsNoLocations,   v'8 9 $56rNr rrrrr-rGrIrLrNr rrr>r>]s 3+*?7rr>c8eZdZdZddZddZddZddZddZy) InfiniteRedirectionTestszJ Tests for how L{InfiniteRedirection} attributes are initialized. cjtjdd}|j|jdy)z If no C{message} argument is passed to the L{InfiniteRedirection} constructor and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned. r$r@rArCNrInfiniteRedirectionrr)r+s rr-z2InfiniteRedirectionTests.test_noMessageValidStatuss*  % %fw ? M2rcftjd}|j|jdy)aJ If no C{message} argument is passed to the L{InfiniteRedirection} constructor and C{location} is also empty and the C{code} argument is a valid HTTP status code, C{code} is mapped to a descriptive string to which C{message} is assigned without trying to include an empty location. r$r%NrSr+s rrGz  % %fw ? D) Q'rcltjddd}|j|jdy)z If a C{message} argument is passed to the L{InfiniteRedirection} constructor, the C{message} isn't affected by the value of C{status}. r$r8r@rArKNrSr+s rrLz9InfiniteRedirectionTests.test_messageExistsLocationExistss.  % %f.?' R $=>rchtjdd}|j|jdy)z If a C{message} argument is passed to the L{InfiniteRedirection} constructor and no location is provided, C{message} doesn't try to include the empty location. r$r8NrSr+s rrNz5InfiniteRedirectionTests.test_messageExistsNoLocations,  % %f.? @ $56rNrrOr rrrQrQs 3 +(?7rrQceZdZdZddZy)RedirectWithNoLocationTestszq L{RedirectWithNoLocation} is a subclass of L{Error} which sets a custom message in the constructor. ctjddd}|j|jd|j|jdy)z When C{code}, C{message}, and C{uri} are passed to the L{RedirectWithNoLocation} constructor, the C{message} and C{uri} attributes are set, respectively. r sREDIRECTshttps://example.comsREDIRECT to https://example.comN)rRedirectWithNoLocationrr)urir+s rtest_validMessagez-RedirectWithNoLocationTests.test_validMessagesC  ( (>T U $FG  67rNr)rrrrr^r rrrZrZs  8rrZc eZdZdZddZddZy)MissingRenderMethodTestsz\ Tests for how L{MissingRenderMethod} exceptions are initialized and displayed. ct}tj|d}|j|j||j|j dy)z Given C{element} and C{renderName} arguments, the L{MissingRenderMethod} constructor assigns the values to the corresponding attributes. renderThingN)objectrMissingRenderMethodassertIselement renderNamereltr,s rtest_constructorz)MissingRenderMethodTests.test_constructorsA h  % %c= 9 aii% allM2rct}tj|d}|jt |d|zy)z A L{MissingRenderMethod} is represented using a custom string containing the element's representation and the method name. rbzB'MissingRenderMethod': %r had no render method named 'renderThing'N)rcrrdrreprrhs r test_reprz"MissingRenderMethodTests.test_reprs= h  % %c= 9  G T  rNrrrrrrjrmr rrr`r`s 3  rr`c eZdZdZddZddZy)MissingTemplateLoaderTestsz^ Tests for how L{MissingTemplateLoader} exceptions are initialized and displayed. czt}tj|}|j|j|y)z Given an C{element} argument, the L{MissingTemplateLoader} constructor assigns the value to the corresponding attribute. N)rcrMissingTemplateLoaderrerfrhs rrjz+MissingTemplateLoaderTests.test_constructors- h  ' ' , aii%rc~t}tj|}|jt |d|zy)z A L{MissingTemplateLoader} is represented using a custom string containing the element's representation and the method name. z)'MissingTemplateLoader': %r had no loaderN)rcrrrrrlrhs rrmz$MissingTemplateLoaderTests.test_reprs6 h  ' ' , a"MPS"STrNrrnr rrrprps &UrrpceZdZdZgfddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zdd ZddZddZddZy)FlattenerErrorTestsz& Tests for L{FlattenerError}. c td#t$rK}tjt j d}t j|||cYd}~Sd}~wwxYw)Noh noes) RuntimeError Exception traceback extract_tbsysexc_inforFlattenerError)rrootsr,tbs rmakeFlattenerErrorz&FlattenerErrorTests.makeFlattenerErrorsR 6y) ) 6%%cllnQ&78B''5"5 5 6s A!AAA!A!c d|zS)NzR(%s)r )robjs rfakeFormatRootz"FlattenerErrorTests.fakeFormatRoots }rch|jddg}|j|jddgy)z Given C{exception}, C{roots}, and C{traceback} arguments, the L{FlattenerError} constructor assigns the roots to the C{_roots} attribute. ab)rN)rr_rootsr+s rrjz$FlattenerErrorTests.test_constructors3  # #3* # 5 C:.rcl|j}|jt|t|y)zd The string form of a L{FlattenerError} is identical to its representation. N)rrr*rlr+s rr<zFlattenerErrorTests.test_str&s*  # # % Qa)rc|jddg}|j|_|jt j dt |tjtjzt |y)z The representation of a L{FlattenerError} initialized with roots and a traceback contains a formatted representation of those roots (using C{_formatRoot}) and a formatted traceback. rrzException while flattening: R\(a\) R\(b\) File "[^"]*", line [0-9]*, in makeFlattenerError raise RuntimeError\("oh noes"\) RuntimeError: oh noes $N) rr _formatRoot assertTruerematchrlMSr+s r"test_reprWithRootsAndWithTracebackz6FlattenerErrorTests.test_reprWithRootsAndWithTraceback.sc  # #S#J /++   HH+ Qrtt   G rc|jg}|jtjdt |tj tj zt |y) The representation of a L{FlattenerError} initialized without roots but with a traceback contains a formatted traceback but no roots. zException while flattening: File "[^"]*", line [0-9]*, in makeFlattenerError raise RuntimeError\("oh noes"\) RuntimeError: oh noes $N)rrrrrlrrr+s r%test_reprWithoutRootsAndWithTracebackz9FlattenerErrorTests.test_reprWithoutRootsAndWithTracebackDsR  # #B '  HH+Qrtt   G rctjtdgd}|jt j dt |tjtjzt |y)rrwNz3Exception while flattening: RuntimeError: oh noes $) rrryrrrrlrrr+s r(test_reprWithoutRootsAndWithoutTracebackze-abcde-abcde-abcde-N)rrrrrlrr, longStrings r test_formatRootLongUnicodeStringz4FlattenerErrorTests.test_formatRootLongUnicodeStringms?  # # %!-0   MM* % @ A rcx|j}|j|jdtdy)zh The C{_formatRoot} method formats a short byte string using the built-in repr. sabcdNrrrrlr+s rtest_formatRootShortByteStringz2FlattenerErrorTests.test_formatRootShortByteStringys/  # # % w/g?rc||j}d}|j|j|tdy)zx The C{_formatRoot} method formats a long byte string using the built-in repr with an ellipsis. sxabcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-abcde-s-abcde-abcde-abcde-ab<...>e-abcde-abcde-abcde-Nrrs rtest_formatRootLongByteStringz1FlattenerErrorTests.test_formatRootLongByteStrings:  # # %#   MM* % A B rcx|j}|j|jtddy)zu The C{_formatRoot} method formats a C{Tag} with no filename information as 'Tag '. a-tagz Tag N)rrrrr+s rtest_formatRootTagNoFilenamez0FlattenerErrorTests.test_formatRootTagNoFilenames/  # # % s7|4mDrc|j}tdddd}|j|j|dy)z The C{_formatRoot} method formats a C{Tag} with filename information using the filename, line, column, and tag information rztpl.py )filename lineNumber columnNumberz-File "tpl.py", line 10, column 20, in "a-tag"N)rrrr)rr,ts rtest_formatRootTagWithFilenamez2FlattenerErrorTests.test_formatRootTagWithFilenames?  # # % (r K  MM! M rc |jttjt ddggd|jttjt ddggdy)z If a L{FlattenerError} is created with a string root, up to around 40 bytes from that string are included in the string representation of the exception. reason abc123xyzz?Exception while flattening: 'abc123xyz' RuntimeError: reason d0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789zcException while flattening: '01234567890123456789<...>01234567890123456789' RuntimeError: reason Nrr*rrryr5s r test_stringzFlattenerErrorTests.test_stringsi  $$\(%;k]BO P V   $$\(%;>O=PRTU V % rc |jttjt ddggd|jttjt ddggdy)z If a L{FlattenerError} is created with a unicode root, up to around 40 characters from that string are included in the string representation of the exception. ru abc☃xyzzBException while flattening: 'abc\u2603xyz' RuntimeError: reason ux01234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃901234567☃9zwException while flattening: '01234567\u2603901234567\u26039<...>01234567\u2603901234567\u26039' RuntimeError: reason Nrr5s r test_unicodez FlattenerErrorTests.test_unicodesv  $$\(%;>Q=RTVW  %    $$ *-H,I2   % rN)rz list[object]rzerror.FlattenerError)rrcrr*r)rrrrrrrjr<rrrrrrrrrrrr rrrurusZ8:6/* , $  L  @  E   $ rruceZdZdZddZy)UnsupportedMethodTestsz) Tests for L{UnsupportedMethod}. chtjddg}|jt|dy)z The C{__str__} for L{UnsupportedMethod} makes it clear that what it shows is a list of the supported methods, not the method that was unsupported. sHEADsPATCHz#Expected one of [b'HEAD', b'PATCH']N)rUnsupportedMethodrr*r+s rr<zUnsupportedMethodTests.test_strs1  # #Wh$7 8  F 1 rNr)rrrrr<r rrrrs   rr)r __future__rrr}r{twisted.python.compatr twisted.trialr twisted.webrtwisted.web.templaterTestCaser r"r>rQrZr`rpruSynchronousTestCaserr rrrs# ."$"**"$4+""4+n/7))/7d37x0037l8("3"38" x00 >U!2!2U2} (++} @ X99 r