CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/python/test/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/python/test/__pycache__/test_url.cpython-310.pyc

o

�b q�@sXdZddlmZddlmZdZdZgd�Zdd	�ZGd
d�de�Z	Gdd
�d
e�Z
dS)z"
Tests for L{twisted.python.url}.
�)�SynchronousTestCase���URL�*http://www.foo.com/a/nice/path/?zot=23&zut�http://a/b/c/d;p?q)()�g�http://a/b/c/g)z./gr	)zg/�http://a/b/c/g/)z/g�
http://a/g)z//gzhttp://g)z?yzhttp://a/b/c/d;p?y)zg?yzhttp://a/b/c/g?y)z#szhttp://a/b/c/d;p?q#s)zg#szhttp://a/b/c/g#s)zg?y#szhttp://a/b/c/g?y#s)z;xzhttp://a/b/c/;x)zg;xzhttp://a/b/c/g;x)zg;x?y#szhttp://a/b/c/g;x?y#s)�r)�.�
http://a/b/c/)z./r)�..�http://a/b/)z../r)z../g�http://a/b/g)z../..�	http://a/)z../../r)z../../gr)z
../../../gr)z
../../../../gr)z/./gr)z/../gr)zg.zhttp://a/b/c/g.)z.gzhttp://a/b/c/.g)zg..zhttp://a/b/c/g..)z..gzhttp://a/b/c/..g)z./../gr)z./g/.r
)zg/./hzhttp://a/b/c/g/h)zg/../hzhttp://a/b/c/h)z	g;x=1/./yzhttp://a/b/c/g;x=1/y)z
g;x=1/../yzhttp://a/b/c/y)zg?y/./xzhttp://a/b/c/g?y/./x)zg?y/../xzhttp://a/b/c/g?y/../x)zg#s/./xzhttp://a/b/c/g#s/./x)zg#s/../xzhttp://a/b/c/g#s/../xcCsd�dd�|D��S)Nrcss�|]	}dt|�VqdS)z%%%02XN)�ord)�.0�c�r�>/usr/lib/python3/dist-packages/twisted/python/test/test_url.py�	<genexpr>Gs�z<lambda>.<locals>.<genexpr>)�join)�srrr�<lambda>Gsrc@sreZdZdZdd�Zd\dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[S)]�TestURLz
    Tests for L{URL}.
    cCs�|�t|jt�p|jdut|��|�t|jt�p|jdut|��|jD]}|�|tt|��q%|jD]\}}|�|tt|��|�|dupKt|t�t|��q4|�|j	tt|��dS)zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
�
assertTrue�
isinstance�scheme�str�repr�host�path�assertIsInstance�query�fragment)�self�u�seg�k�vrrr�assertUnicodedOs""
 zTestURL.assertUnicodedrc	CsL|j|j|j|j|j|j|jf}	||t|�t|�|||jf}
|�|	|
�dS)a�
        The given L{URL} should have the given components.

        @param u: The actual L{URL} to examine.

        @param scheme: The expected scheme.

        @param host: The expected host.

        @param path: The expected path.

        @param query: The expected query.

        @param fragment: The expected fragment.

        @param port: The expected port.

        @param userinfo: The expected userinfo.
        N)	rr"r#r%r&�port�userinfo�tuple�assertEqual)r'r(rr"r#r%r&r-r.�actual�expectedrrr�	assertURL^s zTestURL.assertURLcsD�fdd�}|tdd��|tddgg��|tddggd��dS)z@
        L{URL} should have appropriate default values.
        c
s&��|���|ddggddd�dS)N�httpr�P)r,r3)r(�r'rr�check{s
z(TestURL.test_initDefaults.<locals>.checkr4rNr)r'r7rr6r�test_initDefaultsvszTestURL.test_initDefaultsc	Csjtdddgddgd�}|�|�|�|dddgddgdd�|�tdd	d
gdgd�dd	d
gdgdd
�dS)z=
        L{URL} should accept L{unicode} parameters.
        r�h�p�r*r+)r*N�fNr4�à�é)uλuπu⊥r5�rr,r3�r'r(rrr�	test_init�s
�zTestURL.test_initc	Cs@tdddgddgd�}|�|�|�|dddgddgdd�dS)zN
        L{URL} should accept (and not interpret) percent characters.
        rz%68z%70)�%6Bz%76)rBNz%66Nr?r@rrr�test_initPercent�s

�zTestURL.test_initPercentc
Cs2|�ttdddgddgdd��d�td	���d
S)z�
        L{URL.__repr__} will display the canonical form of the URL, wrapped in
        a L{URL.fromText} invocation, so that it is C{eval}-able but still easy
        to read.
        r4�foo�bar)�bazNr;�frob)rr"r#r%r&zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)r0r!r�formatr6rrr�	test_repr�s��	�zTestURL.test_reprcCst�t�}|�t|���dS)zb
        Round-tripping L{URL.fromText} with C{str} results in an equivalent
        URL.
        N)r�fromText�theurlr0�asText�r'�urlpathrrr�
test_fromText�s
zTestURL.test_fromTextcCs,d}|D]}t�|���}|�||�qdS)z>
        L{URL.asText} should invert L{URL.fromText}.
        )zhttp://localhost�http://localhost/zhttp://localhost/foozhttp://localhost/foo/zhttp://localhost/foo!!bar/zhttp://localhost/foo%20bar/zhttp://localhost/foo%2Fbar/zhttp://localhost/foo?nzhttp://localhost/foo?n=vzhttp://localhost/foo?n=/a/bz%http://example.com/foo!@$bar?b!@z=123z$http://localhost/asd?a=asd%20sdf/345z6http://(%2525)/(%2525)?(%2525)&(%2525)=(%2525)#(%2525)z<http://(%C3%A9)/(%C3%A9)?(%C3%A9)&(%C3%A9)=(%C3%A9)#(%C3%A9)N)rrJrLr0)r'�tests�test�resultrrr�test_roundtrip�s
�zTestURL.test_roundtripcCs2t�t�}|�|t�t��|�|t�d��dS)z�
        Two URLs decoded using L{URL.fromText} will be equal (C{==}) if they
        decoded same URL string, and unequal (C{!=}) if they decoded different
        strings.
        z:ftp://www.anotherinvaliddomain.com/foo/bar/baz/?zot=21&zutN)rrJrKr0�assertNotEqualrMrrr�
test_equality�s
��zTestURL.test_equalitycCs0|�tdd�t��|�t�d�t�d��dS)z�
        An URL created with the empty string for a fragment compares equal
        to an URL created with an unspecified fragment.
        r)r&zhttp://localhost/#rPN)r0rrJr6rrr�test_fragmentEquality�s�zTestURL.test_fragmentEqualitycCsft�t�}|�d|�d����|�d|�d����|�d|�d����|�d|�d����d	S)
zm
        L{URL.child} appends a new path segment, but does not affect the query
        or fragment.
        z.http://www.foo.com/a/nice/path/gong?zot=23&zut�gongz1http://www.foo.com/a/nice/path/gong%2F?zot=23&zutzgong/z7http://www.foo.com/a/nice/path/gong%2Fdouble?zot=23&zutzgong/doublez:http://www.foo.com/a/nice/path/gong%2Fdouble%2F?zot=23&zutzgong/double/N)rrJrKr0�childrLrMrrr�
test_child�s"
����zTestURL.test_childcCs$|�t�d��ddd���d�dS)zg
        L{URL.child} receives multiple segments as C{*args} and appends each in
        turn.
        zhttp://example.com/a/br�d�ezhttp://example.com/a/b/c/d/eN)r0rrJrYrLr6rrr�test_multiChilds�zTestURL.test_multiChildcCs0tdd��d�}|�|j�|�d|���dS)zo
        L{URL.child} of a L{URL} without a path produces a L{URL} with a single
        path segment.
        �www.foo.com�r"rzhttp://www.foo.com/cN)rrYr�rootedr0rL)r'�childURLrrr�test_childInitRootszTestURL.test_childInitRootcCsHt�t�}|�d|�d����d}t�|�}|�d|�d����dS)z
        L{URL.sibling} of a L{URL} replaces the last path segment, but does not
        affect the query or fragment.
        z0http://www.foo.com/a/nice/path/sister?zot=23&zut�sisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)rrJrKr0�siblingrL)r'rN�theurl2rrr�test_siblings
�
�zTestURL.test_siblingcCs�t�t�}|�d|�d����|�d|�d����|�d|�d����|�d|�d����|�d	|�d
����t�d�}|�d|�d
����t�d�}|�|�d���d�dS)z�
        L{URL.click} interprets the given string as a relative URI-reference
        and returns a new L{URL} interpreting C{self} as the base absolute URI.
        rrz$http://www.foo.com/a/nice/path/click�clickzhttp://www.foo.com/clickz/clickz$http://www.foo.com/a/nice/path/?burpz?burpz//foobarzhttp://www.foo.com/foobarzhttp://www.foo.com/me/noqueryz!http://www.foo.com/me/17?spam=158z/me/17?spam=158zhttp://localhost/foo?abc=defzhttp://www.python.orgN)rrJrKr0rgrL�assertNotIn)r'rNr(rrr�
test_click's,
����
�
�zTestURL.test_clickcCs2t�t�}tD]\}}|�|�|���|�qdS)zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)rrJ�relativeLinkBaseForRFC3986�relativeLinkTestsForRFC3986r0rgrL)r'�base�refr2rrr�test_clickRFC3986Os
�zTestURL.test_clickRFC3986cCs.t�t�}|�t|jd�|�t|jd�dS)zM
        L{URL.click} should not accept schemes with relative paths.
        zg:hzhttp:hN)rrJrj�assertRaises�NotImplementedErrorrg)r'rlrrr�test_clickSchemeRelPathWs
zTestURL.test_clickSchemeRelPathc
CsFt�d�}|�|�|j|j|j|j|j|j	�|�|�|��|�dS)zf
        Verify that L{URL.replace} doesn't change any of the arguments it
        is passed.
        zhttps://x:1/y?z=1#AN)
rrJr0�replacerr"r#r%r&r-rMrrr�test_cloneUnchanged_s
��zTestURL.test_cloneUnchangedcCs�gd�gd�gd�gd�gd�gd�gd�gd�gd	�gd
�gd�gd�gd
�g
}|D]\}}}t�|��|���}|�||dj|t|�||d��q+dS)zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        )rPr
rP)rPrrP)�http://localhost/a/b/cr
zhttp://localhost/a/b/)rtrzhttp://localhost/a/)rtz./d/ezhttp://localhost/a/b/d/e)rt�../d/e�http://localhost/a/d/e)rtz/./d/e�http://localhost/d/e)rtz/../d/erw)zhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/)zhttp://localhost/a/./crurw)zhttp://localhost/a/./c/rurv)zhttp://localhost/a/b/c/dz
./e/../f/../gzhttp://localhost/a/b/c/g)rtzd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})�startrgr1r2N)rrJrgrLr0rHr!)r'rQrxrgr2r1rrr�test_clickCollapsers6����zTestURL.test_clickCollapsecCs�|�dt�d��dd����|�dtdd��dd����t�t�}|�d|�d	����|�d
|�d	d����|�d|�d	d��d
����|�d|�d
��d	d����|�d|�d	d��dd����dS)z3
        L{URL.add} adds query parameters.
        z'http://www.foo.com/a/nice/path/?foo=barzhttp://www.foo.com/a/nice/path/rDrEzhttp://www.foo.com/?foo=barr^r_z/http://www.foo.com/a/nice/path/?zot=23&zut&burp�burpz3http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx�xxxz8http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zing�zingz8http://www.foo.com/a/nice/path/?zot=23&zut&zing&burp=xxxz:http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zot=32�zot�32N)r0rrJ�addrLrKrMrrr�
test_queryAdd�s:��
�����zTestURL.test_queryAddcCsdt�t�}|�d|�dd����|�d|�d��dd����|�d|�dd��dd����dS)	z?
        L{URL.set} replaces query parameters by name.
        z*http://www.foo.com/a/nice/path/?zot=32&zutr}r~z0http://www.foo.com/a/nice/path/?zot&zut=itworked�zut�itworkedr{N)rrJrKr0�setrLrrMrrr�
test_querySet�s
���zTestURL.test_querySetcCs&t�d�}|�|�d�t�d��dS)zK
        L{URL.remove} removes all instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3rDzhttps://example.com/a/b/?bar=2N)rrJr0�remove�r'�urlrrr�test_queryRemove�s
�zTestURL.test_queryRemovecCs|�t���d�dS)zG
        An empty L{URL} should serialize as the empty string.
        rN)r0rrLr6rrr�
test_empty�szTestURL.test_emptycCs tdgd�}|�|��d�dS)zP
        An L{URL} with query text should serialize as just query text.
        ��hello�world�r%z?hello=worldN)rr0rLr@rrr�test_justQueryText�szTestURL.test_justQueryTextcCst�d�}|�||�dS)z2
        L{URL} compares equal to itself.
        rPN�rrJr0r@rrr�test_identicalEqual�s
zTestURL.test_identicalEqualcCs$t�d�}t�d�}|�||�dS)zG
        URLs with equivalent components should compare equal.
        rPNr��r'�u1�u2rrr�test_similarEqual�s

zTestURL.test_similarEqualcCs>t�d�}t�d�}|�||k|�d|���|�||�dS)z|
        L{URL}s that refer to different resources are both unequal (C{!=}) and
        also not equal (not C{==}).
        �http://localhost/a�http://localhost/b� != N)rrJ�assertFalserUr�rrr�test_differentNotEqual�s

zTestURL.test_differentNotEqualcCsJt�d�}|�|dkd�|�|t�kd�|�|d�|�|t��dS)z=
        L{URL} is not equal (C{==}) to other types.
        rP�*zURL must not equal a number.zURL must not equal an object.N)rrJr��objectrUr@rrr�test_otherTypesNotEqual�s

zTestURL.test_otherTypesNotEqualcCs"t�d�}|�||kd|�dS)zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        rPz%r == itselfN�rrJr�r@rrr�test_identicalNotUnequals
z TestURL.test_identicalNotUnequalcCs2t�d�}t�d�}|�||k|�d|���dS)zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        rP� == Nr�r�rrr�test_similarNotUnequal�

zTestURL.test_similarNotUnequalcCs2t�d�}t�d�}|�||k|�d|���dS)zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        r�r�r�N)rrJrr�rrr�test_differentUnequalr�zTestURL.test_differentUnequalcCs0t�d�}|�|dkd�|�|t�kd�dS)z;
        L{URL} is unequal (C{!=}) to other types.
        rPr�zURL must differ from a number.z"URL must be differ from an object.N)rrJrr�r@rrr�test_otherTypesUnequals
zTestURL.test_otherTypesUnequalcC�nd}t�|�}|��}|�|jd�|�|jdd�|�|��|�d}|��}|�|||�d|���dS)z�
        L{URL.asURI} produces an URI which converts any URI unicode encoding
        into pure US-ASCII and returns a new L{URL}.
        �http://é.com/é?á=í#úué.comrué�.http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BAr�N)rrJ�asURIr0r"r#rL)r'�unicodey�iri�uri�expectedURI�	actualURIrrr�
test_asURI$s�

�zTestURL.test_asURIcCr�)z�
        L{URL.asIRI} decodes any percent-encoded text in the URI, making it
        more suitable for reading by humans, and returns a new L{URL}.
        r�zxn--9ca.comrz%C3%A9uhttp://é.com/é?á=í#úr�N)rrJ�asIRIr0r"r#rL)r'�asciiishr�r��expectedIRI�	actualIRIrrr�
test_asIRI;s
�zTestURL.test_asIRIcCs>d}t�|�}|��}d}|��}|�|||�d|���dS)z�
        Bad UTF-8 in a path segment, query parameter, or fragment results in
        that portion of the URI remaining percent-encoded in the IRI.
        z http://xn--9ca.com/%00%FF/%C3%A9uhttp://é.com/%00%FF/ér�N)rrJr�rLr0)r'�
urlWithBinaryr�r�r�r�rrr�test_badUTF8AsIRIPs
�zTestURL.test_badUTF8AsIRIcCs*d}t�|�}|��}|�|��|�dS)zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        r�N)rrJr�r0rL)r'r�r��alsoIRIrrr�test_alreadyIRIAsIRI`s
�
zTestURL.test_alreadyIRIAsIRIcCs*d}t�|�}|����}|�||�dS)zH
        A L{URL} composed of encoded text will remain encoded.
        r�N)rrJr�rLr0)r'r�r�r�rrr�test_alreadyURIAsURIos
zTestURL.test_alreadyURIAsURIcCsvt�d�}|�|�d�d�|�|�d�d�|�|jd�|�|jd�|�|��d�|�|jdd	���d
�dS)zz
        L{URL.fromText} will parse the C{userinfo} portion of the URI
        separately from the host and port.
        z<http://someuser:somepassword@example.com/some-segment@ignoreTz!someuser:somepassword@example.comFzsomeuser:@example.comzsomeuser:somepassword�someuserz0http://someuser:@example.com/some-segment@ignore)r.z/http://someuser@example.com/some-segment@ignoreN)rrJr0�	authorityr.�userrLrrr�rrr�
test_userinfoxs���zTestURL.test_userinfocCs,t�d�}|�|jd�|�|��d�dS)zI
        L{URL.fromText} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i�N)rrJr0r-rL)r'�portURLrrr�
test_portText�s
zTestURL.test_portTextcCs|�t�d���d�dS)a
        Although L{URL} instances are mainly for dealing with HTTP, other
        schemes (such as C{mailto:}) should work as well.  For example,
        L{URL.fromText}/L{URL.asText} round-trips cleanly for a C{mailto:} URL
        representing an email address.
        zmailto:user@example.comN)r0rrJrLr6rrr�test_mailto�s�zTestURL.test_mailtocCs"tddggd�}|�|jd�dS)z�
        When a L{URL} is created with a C{query} argument, the C{query}
        argument is converted into an N-tuple of 2-tuples.
        �alpha�betar�))r�r�N)rr0r%r�rrr�test_queryIterable�szTestURL.test_queryIterablecCs tddgd�}|�|jd�dS)zr
        When a L{URL} is created with a C{path} argument, the C{path} is
        converted into a tuple.
        r�r��r#r�N)rr0r#r�rrr�test_pathIterable�szTestURL.test_pathIterablecs�Gdd�d��ttur
dnd}�fdd��|f���fdd�	}|d	�|d
�|d�|dd
�|d�|dd���t��}t��gd�Wd�n1sPwY�||d���t��}td��fgd�Wd�n1stwY�||dd���t��}t��dfgd�Wd�n1s�wY�||d���t��t��gd�Wd�n1s�wY��t��tdgd�Wd�n1s�wY��t��tdgd�Wd�n1s�wYt�d�}��t��}|����Wd�n	1�swY�||d���t��}|����Wd�n	1�s5wY�||d���t��}|�	���Wd�n	1�sWwY�||d�dS)a�
        Passing an argument of the wrong type to any of the constructor
        arguments of L{URL} will raise a descriptive L{TypeError}.

        L{URL} typechecks very aggressively to ensure that its constitutent
        parts are all properly immutable and to prevent confusing errors when
        bad data crops up in a method call long after the code that called the
        constructor is off the stack.
        c@s(eZdZdefdd�Zdefdd�ZdS)z1TestURL.test_invalidArguments.<locals>.Unexpected�returncS�dS)N�wrongrr6rrr�__str__��z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__cSr�)N�<unexpected>rr6rrr�__repr__�r�z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__N)�__name__�
__module__�__qualname__r r�r�rrrr�
Unexpected�sr��unicoder cs ��t|j�d�||d��dS)Nzexpected {} for {}, got {}r�)r0r �	exceptionrH)�raised�expectation�namer6rr�assertRaised�s�z3TestURL.test_invalidArguments.<locals>.assertRaisedcsN��t��}tdi|��i��Wd�n1swY�|||�dS)Nr)ro�	TypeErrorr)�paramr�r��r�r�r'rrr7�s�z,TestURL.test_invalidArguments.<locals>.checkrr"r&r`�boolr.r-zint or NoneTyper�Nzpath segmentr�r�z or NoneTypezquery parameter value�valuezquery parameter name)r*r+�vv)r*zhttps://valid.example.com/zrelative URL)
�bytesr ror�r�
ValueErrorrJrYrdrg)r'�defaultExpectationr7r�r�rr�r�test_invalidArguments�sn

������
�������
���zTestURL.test_invalidArgumentscCsT|�t��
}tdd�Wd�n1swY|�t|j�d�td���dS)z�
        Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
        C{URL(path="foo")} resulting in C{URL.fromText("f/o/o")} is never what
        you want.
        rDr�Nz+expected iterable of text for path, not: {})ror�rr0r r�rHr!)r'r�rrr�!test_technicallyTextIsIterableButs��z)TestURL.test_technicallyTextIsIterableButN)r)0r�r�r��__doc__r,r3r8rArCrIrOrTrVrWrZr]rbrfrirnrqrsryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrJs\




	(!$	

	Qrc@seZdZdZdd�ZdS)�URLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    cCsFddlm}||�|jg�}|�dt|��|�d|dd�dS)zK
        L{twisted.python.url} is deprecated since Twisted 17.5.0.
        r)r��z\twisted.python.url was deprecated in Twisted 17.5.0: Please use hyperlink from PyPI instead.�messageN)�twisted.pythonr��
flushWarnings�test_urlDeprecationr0�len)r'r��
warningsShownrrrr�s
�z'URLDeprecationTests.test_urlDeprecationN)r�r�r�r�r�rrrrr�sr�N)r��twisted.trial.unittestrr�rrKrjrk�_percentencrr�rrrr�<module>s7I
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY