Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib64/python3.7/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/test/__pycache__/test_xmlrpc.cpython-37.pyc

B

� f^��@s�ddlZddlZddlZddlZddlZddlZddlmZddlmZ	ddl
ZddlZ
ddl
Z
ddlZ
ddlZddlZddlZddlZddlZddlmZyddlZWnek
r�dZYnXdddddge	�d	�d	ed	�d
dde	�d
�e	�d�e	�e�dddddd��d�gZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!Gdd �d ej�Z"da#a$a%dLd!d"�Z&dMd#d$�Z'd%d&�Z(d'd(�Z)Gd)d*�d*ej�Z*Gd+d,�d,e*�Z+Gd-d.�d.e*�Z,Gd/d0�d0e*�Z-Gd1d2�d2e*�Z.Gd3d4�d4e.�Z/Gd5d6�d6e.�Z0e�1edkd7�Gd8d9�d9e*��Z2e�1edkd7�Gd:d;�d;ej��Z3Gd<d=�d=ej�Z4Gd>d?�d?e
jj5�Z6Gd@dA�dAej�Z7ej8dNdCdD��Z9GdEdF�dFej�Z:GdGdH�dHej�Z;ej<dIdJ��Z=e>dKk�r�e=�dS)O�N)�mock)�supportzfoo@bar.baz.spamgH�zns�@i�z.zyx.41smy dog has fleasFu	䀀怀耀z
regular valuez20050210T11:41:23)	i�r�
��)�r����i�rrrr)ZastringZafloatZanintZ
ashortlongZanotherlistZabase64Zb64bytesZb64bytearrayZbooleanZunicodeuukey䀀Z	datetime1Z	datetime2Z	datetime3c@s�eZdZdd�Zdd�Zdd�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-S).�XMLRPCTestCasecCs.t�tf�}t�|�}|�t|dd�dS)Nr)�	xmlrpclib�dumps�alist�loads�assertEqual)�self�dump�load�r�5/opt/alt/python37/lib64/python3.7/test/test_xmlrpc.py�test_dump_load,s
zXMLRPCTestCase.test_dump_loadcCs6t�dddddd�}|�|t�d��t�|f�}tj|dd	�\}}|\}|�||�|�t|�tj�|�|�tj|d
d	�\}}|\}|�||�|�t|�tj�|�|�tj|dd�\}}|\}|�||�|�t|�tj�|�|�tj|d
d�\}}|\}|�||�|�t|�tj�|�|�dS)Ni�rrrrrz20050210T11:41:23T)�use_builtin_typesF)Zuse_datetime)	�datetimerr�DateTimer
r�assertIs�type�assertIsNone)r�dt�s�result�m�newdtrrr�test_dump_bare_datetime1s.


z&XMLRPCTestCase.test_dump_bare_datetimecCs�t�dddddd�}|�|t�d��t�|f�}tj|dd	�\}}|\}|�||�|�t|�tj�|�|�tj|d
d	�\}}|\}|�||�|�t|�tj�|�|�dS)Nr	rrrrrz00010210T11:41:23T)rF)	rrrrr
rrrr)rrrrr r!rrr�test_datetime_before_1900Ss
z(XMLRPCTestCase.test_datetime_before_1900cCsRt��}t�tj|fdd��\\}}|�|jt�tj|fdd�}|�|t�dS)NT)�methodresponse)rrrr
ZassertIsInstance�value�str)r�dZnew_d�dummyrrrr�test_bug_1164912eszXMLRPCTestCase.test_bug_1164912cCsLGdd�dt�}|�}d|_d|_t�t�|f��\\}}|�||j�dS)Nc@seZdZdS)z-XMLRPCTestCase.test_newstyle_class.<locals>.TN)�__name__�
__module__�__qualname__rrrr�Tpsr-�dZHello)�object�x�yrrr
r�__dict__)rr-�t�t2r(rrr�test_newstyle_classosz"XMLRPCTestCase.test_newstyle_classcCs|�ttjddf�dS)Nr�c)�assertRaises�
OverflowErrorrr
)rrrr�test_dump_big_longxsz!XMLRPCTestCase.test_dump_big_longcCs|�ttjddif�dS)N)r	r�r	)r7�	TypeErrorrr
)rrrr�test_dump_bad_dict{sz!XMLRPCTestCase.test_dump_bad_dictcCs6dddg}ddd|g}|�|�|�ttj|f�dS)Nr	rr:��)�appendr7r;rr
)r�lr3rrr�test_dump_recursive_seq~s

z&XMLRPCTestCase.test_dump_recursive_seqcCs2ddd�}d|d�}||d<|�ttj|f�dS)Nr	)�1�2r:)�3r'r3)r7r;rr
)rr'r3rrr�test_dump_recursive_dict�s

z'XMLRPCTestCase.test_dump_recursive_dictcCs�tjdkr |�ttjtd�f�t�tjtjf�|�ttjtjdf�|�ttjtjdf�dd�}t�	�}|�
tj|�|�
tj|�|�t|j
tjd|�|�t|j
tjd|�dS)Ni���lr	cSsdS)Nr)rrrr�dummy_write�sz5XMLRPCTestCase.test_dump_big_int.<locals>.dummy_write)�sys�maxsizer7r8rr
�int�MAXINT�MININT�
MarshallerZdump_int)rrFr rrr�test_dump_big_int�s 





z XMLRPCTestCase.test_dump_big_intcCs�t�td�f�t�ttj�ttj�f�t�ttjd�ttjd�f�dd�}t��}|�tj|�|�tj|�|�tjd|�|�tjd|�dS)Nl�*cSsdS)Nr)rrrrrF�sz4XMLRPCTestCase.test_dump_double.<locals>.dummy_write)rr
�floatrJrKrLZdump_double)rrFr rrr�test_dump_double�szXMLRPCTestCase.test_dump_doublecCsTtdg}tdgf}tj|dd�}|�|t�|�dd�|�ttj|f�dS)NT)�
allow_noner)rrr
rrr7r;)rr%Zarg1�strgrrr�test_dump_none�s
zXMLRPCTestCase.test_dump_nonecCs�ddi}tj|fdd�}d|}|�t�|�dd|�|�dd�}|�t�|�dd|�tj|fddd	�}|�t�|�dd|�|�dd�}|�t�|�dd|�d
}tj|fd|d�}|�t�|�dd|�|�t�|�d|�dS)
Nukey€¤u
value€¤ziso-8859-15)�encodingz,<?xml version='1.0' encoding='iso-8859-15'?>r�xmlcharrefreplaceT)rTr$umethod€¤)rT�
methodnamer	)rr
rr�encode)rr%rRrVrrr�test_dump_encoding�s"

z!XMLRPCTestCase.test_dump_encodingcCs�d}|�|t�|��x�tttjfD]�}||�}t�|f�}tj|dd�\}}|\}|�||�|�t|�t�|�	|�tj|dd�\}}|\}|�||�|�t|�tj�|�	|�q$WdS)Nsmy dog has fleasT)rF)
rr�Binary�bytes�	bytearrayr
rrrr)rZsampleZtype_r%rrr �newvaluerrr�test_dump_bytes�s
zXMLRPCTestCase.test_dump_bytescCsFtj}d}|�|tj|�d}|�|tj|�d}|�|tj|�dS)Nz6<params><param><value><spam/></value></param></params>zT<params><param><value><array><value><spam/></value></array></value></param></params>z�<params><param><value><struct><member><name>a</name><value><spam/></value></member><member><name>b</name><value><spam/></value></member></struct></value></param></params>)r�
ResponseErrorr7r)rr^�datarrr�test_loads_unsupported�sz%XMLRPCTestCase.test_loads_unsupportedcKsNd|}tj|f|�\}}|\}|�||�|�t|�t|��|�|�dS)Nz1<params><param><value>%s</value></param></params>)rrrrrr)rrr%�kwargsrrr r\rrr�check_loads�szXMLRPCTestCase.check_loadsc
Cs�|j}|dd�|dd�|dd�|dd�|dd�|d	d�|d
d�|dd
�|dt�d��|dddd�|dt�d��|dt�dddddd�dd�|dddg�|dddd��dS)N�stringz<string>string</string>u4<string>𝔘𝔫𝔦𝔠𝔬𝔡𝔢 string</string>u#𝔘𝔫𝔦𝔠𝔬𝔡𝔢 stringz<int>2056183947</int>i��zz<int>-2056183947</int>iuq�z<i4>2056183947</i4>z<double>46093.78125</double>g���@z<boolean>0</boolean>Fz%<base64>AGJ5dGUgc3RyaW5n/w==</base64>s
byte string�T)rz6<dateTime.iso8601>20050210T11:41:23</dateTime.iso8601>z20050210T11:41:23i�rrrrrzR<array><data><value><int>1</int></value><value><int>2</int></value></data></array>r	z�<struct><member><name>b</name><value><int>2</int></value></member><member><name>a</name><value><int>1</int></value></member></struct>)�a�b)rbrrYrr)r�checkrrr�test_load_standard_types�s,









z'XMLRPCTestCase.test_load_standard_typescCs`|j}|dd�|dd�|dd�|dd�|dd�|d	d
�|dd�|d
t�d��dS)Nz<nil/>z	<ex:nil/>z<i1>205</i1>��z<i2>20561</i2>iQPz<i8>9876543210</i8>l�`	z-<biginteger>98765432100123456789</biginteger>l5�?�4*UUz<float>93.78125</float>grW@z.<bigdecimal>9876543210.0123456789</bigdecimal>z9876543210.0123456789)rb�decimalZDecimal)rrfrrr�test_load_extension_typess





z(XMLRPCTestCase.test_load_extension_typesc
Cs�|j}d}t�|��bd|d}|�t��|d|�d�d�WdQRX|�t��|d|�d�d�WdQRXWdQRXdS)Ni�rBr	z<int>z</int>z<biginteger>z
</biginteger>)rbrZadjust_int_max_str_digitsr7�
ValueError)rrfZ	maxdigitsrrrr�test_limit_intszXMLRPCTestCase.test_limit_intcCs(tj��}|�|�d�ddgif�dS)Nz
user@host.tldzhost.tld)Z
AuthorizationzBasic dXNlcg==)�xmlrpc�client�	TransportrZ
get_host_info)rZtransprrr�test_get_host_info(s
z!XMLRPCTestCase.test_get_host_infocCs�yddl}Wntk
r$d}YnXd}ytj�d���Wn<tk
r^|�|d�Yntk
rz|�	|�YnXdS)NrFTzhttps://localhost:9999z&xmlrpc client's error with SSL support)
�ssl�ImportErrorrmrn�ServerProxyZbad_function�NotImplementedErrorZassertFalse�OSError�
assertTrue)rrqZhas_sslrrr�test_ssl_presence/s
z XMLRPCTestCase.test_ssl_presencec	s�Gdd�dtjj�}�fdd�}tj�tjdf|��|��j�tj	|d�}|�
�|�|j�dj�j
�}t�|��&}|�|��d�|�|��d�WdQRXdS)	Nc@s$eZdZdZdZdd�Zdd�ZdS)z@XMLRPCTestCase.test_keepalive_disconnect.<locals>.RequestHandlerzHTTP/1.1FcSs�t|j�d��}|j�|�|jr,d|_dStjddd�}|�	�}|�
tjj
�|�dt|��|��|j�|�d|_d|_dS)NzContent-LengthT)r>)r$F)rI�headers�getZrfile�read�handledZclose_connectionrr
rWZ
send_response�httpZ
HTTPStatusZOKZsend_header�lenZend_headersZwfile�write)r�length�responserrr�do_POSTBszHXMLRPCTestCase.test_keepalive_disconnect.<locals>.RequestHandler.do_POSTcWsdS)Nr)r�format�argsrrr�log_messageQszLXMLRPCTestCase.test_keepalive_disconnect.<locals>.RequestHandler.log_messageN)r*r+r,�protocol_versionr{r�r�rrrr�RequestHandler>sr�cs$�j�td��������dS)Nr	)�socket�
settimeoutrO�handle_requestr)�serverrr�
run_serverUsz<XMLRPCTestCase.test_keepalive_disconnect.<locals>.run_serverr)�targetz
http://{}:{}/r>)r|r�ZBaseHTTPRequestHandlerZ
HTTPServerrZHOST�
addCleanup�server_close�	threading�Thread�start�joinr�Zserver_addressrrsr�method)rr�r��thread�url�pr)r�r�test_keepalive_disconnect=sz(XMLRPCTestCase.test_keepalive_disconnectN)r*r+r,rr"r#r)r5r9r<rArErMrPrSrXr]r`rbrgrjrlrprwr�rrrrr*s,"
	

rc@sLeZdZGdd�de�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�SimpleXMLRPCDispatcherTestCasec@seZdZdZdS)z*SimpleXMLRPCDispatcherTestCase.DispatchExczSRaised inside the dispatched functions when checking for
        chained exceptionsN)r*r+r,�__doc__rrrr�DispatchExcfsr�c	szd}�fdd�}tj��}|�|����j��}|�d|�WdQRX��|jj	|f���
|jj���
|jj�dS)z$Calls explicitly registered function)r	rr:cs��|��dS)N)r�)�params)rrr�dispatched_funcqszQSimpleXMLRPCDispatcherTestCase.test_call_registered_func.<locals>.dispatched_funcr�N)
rmr��SimpleXMLRPCDispatcher�register_functionr7r��	_dispatchr�	exceptionr�r�	__cause__�__context__)r�
exp_paramsr��
dispatcher�exc_ctxr)rr�test_call_registered_funcjs

z8SimpleXMLRPCDispatcherTestCase.test_call_registered_funcc	Cs~d}Gdd�d�}tj��}|�|��|�|j��}|�d|�WdQRX|�|jj	|f�|�
|jj�|�
|jj�dS)z3Calls a registered instance attribute as a function)r	rr:c@seZdZdd�ZdS)zOSimpleXMLRPCDispatcherTestCase.test_call_instance_func.<locals>.DispatchedClasscWst�|��dS)N)r�r�)rr�rrrr��sz_SimpleXMLRPCDispatcherTestCase.test_call_instance_func.<locals>.DispatchedClass.dispatched_funcN)r*r+r,r�rrrr�DispatchedClass�sr�r�N)
rmr�r��register_instancer7r�r�rr�r�rr�r�)rr�r�r�r�rrr�test_call_instance_func|s
z6SimpleXMLRPCDispatcherTestCase.test_call_instance_funcc	Cs�d}d}Gdd�d�}tj��}|�|��|�|j��}|�||�WdQRX|�|jj	||f�|�
|jj�|�
|jj�dS)z4Calls the registered instance's `_dispatch` functionr�)r	rr:c@seZdZdd�ZdS)zLSimpleXMLRPCDispatcherTestCase.test_call_dispatch_func.<locals>.TestInstancecSst�||��dS)N)r�r�)rr�r�rrrr��szVSimpleXMLRPCDispatcherTestCase.test_call_dispatch_func.<locals>.TestInstance._dispatchN)r*r+r,r�rrrr�TestInstance�sr�N)
rmr�r�r�r7r�r�rr�r�rr�r�)rZ
exp_methodr�r�r�r�rrr�test_call_dispatch_func�s
z6SimpleXMLRPCDispatcherTestCase.test_call_dispatch_funcc	Cs@tj��}|jddd�|�td��|�dd�WdQRXdS)z2Calls explicitly registered function which is NoneNr�)�name)�param)rmr�r�r��assertRaisesRegex�	Exceptionr�)rr�rrr�test_registered_func_is_none�s
z;SimpleXMLRPCDispatcherTestCase.test_registered_func_is_nonec	Cs>tj��}|�t��|�td��|�dd�WdQRXdS)z>Attempts to call nonexistent function on a registered instancer�)r�N)rmr�r�r�r/r�r�r�)rr�rrr�test_instance_has_no_func�s
z8SimpleXMLRPCDispatcherTestCase.test_instance_has_no_funcc	Cs2tj��}|�td��|�dd�WdQRXdS)z2Calls a function that the dispatcher cannot locater�)r�N)rmr�r�r�r�r�)rr�rrr�test_cannot_locate_func�s
z6SimpleXMLRPCDispatcherTestCase.test_cannot_locate_funcN)r*r+r,r�r�r�r�r�r�r�r�rrrrr�esr�c@seZdZdd�ZdS)�HelperTestCasecCs:|�t�d�d�|�t�d�d�|�t�d�d�dS)Nza&bza&amp;bza<bza&lt;bza>bza&gt;b)rr�escape)rrrr�test_escape�szHelperTestCase.test_escapeN)r*r+r,r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�
FaultTestCasecCs4t�dd�}|�t|�d�|�t|�t|��dS)NrNz
Test Faultz<Fault 42: 'Test Fault'>)r�Faultr�reprr&)r�frrr�	test_repr�szFaultTestCase.test_reprcCsjt�dd�}t�|f�}t�|�\\}}|�|ddd��|�|d�t���|�}|�tjtj|�dS)NrNz
Test Fault)�	faultCode�faultString)rr�r
rrrLr7)rr�rZnewfr rrr�test_dump_fault�szFaultTestCase.test_dump_faultcCs,|�ttjjtd�|�tj�td��dS)N�__add�title)r7�AttributeErrorrmr��resolve_dotted_attributer&rv)rrrr�test_dotted_attribute�sz#FaultTestCase.test_dotted_attributeN)r*r+r,r�r�r�rrrrr��s
r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�DateTimeTestCasecCsdt�d��P}t�dddddddddg	�}||_t��}t��}|�t	|�t�
d	|��WdQRXdS)
Nztime.localtimei���r��1��z%Y%m%dT%H:%M:%S)rZpatch�timeZstruct_timeZreturn_value�	localtimerrrr&�strftime)rZlocaltime_mockZtime_structr�r3rrr�test_default�s
zDateTimeTestCase.test_defaultc	Cs0d}t�|�}|�t|�t�dt�|���dS)Ngl]�ޮ��Az%Y%m%dT%H:%M:%S)rrrr&r�r�r�)rr'r3rrr�	test_time�s

zDateTimeTestCase.test_timecCs"d}t�|�}|�t|�d�dS)N)	i���	r�&�2r>�rz20070609T10:38:50)rrrr&)rr'r3rrr�test_time_tuple�s
z DateTimeTestCase.test_time_tuplecCs0t�d�}t�|�}|�t|�t�d|��dS)Ngl]�ޮ��Az%Y%m%dT%H:%M:%S)r�r�rrrr&r�)rr'r3rrr�test_time_struct�s

z!DateTimeTestCase.test_time_structcCs2t�dddddd�}t�|�}|�t|�d�dS)Ni�r	rr:r=r>z20070102T03:04:05)rrrrr&)rr'r3rrr�test_datetime_datetime�s
z'DateTimeTestCase.test_datetime_datetimecCs>t�dddddd�}t�|�}dt|�}|�t|�|�dS)Ni�r	rr:r=r>z%<DateTime '20070102T03:04:05' at %#x>)rrr�idrr�)rr'r3�valrrrr��s
zDateTimeTestCase.test_reprc
CsVd}t��}|�|�t�t�dddddd��}|�||�t�|�}|�||�dS)Nz 20070908T07:11:13  i�r��r�r�
)rr�decoderrZ	_datetime)rr'�t1Ztrefr4rrr�test_decode�s

zDateTimeTestCase.test_decodec	Cs�tj��}t�|���}|�||k�|�||k�|tjdd�}|�||k�|�||k�|�d�}|�||k�|�||k�t�|���}|�||k�|�||k�|�d�}|��}|�	t
��|dkWdQRX|�	t
��||kWdQRX|�	t
��|t|�kWdQRX|�	t
��||kWdQRX|�	t
��|td�kWdQRX|�	t
��||kWdQRX|�	t
��|t|�kWdQRX|�	t
��||kWdQRXdS)Nr=)Zsecondsz%Y%m%dT%H:%M:%S�asciii�)
r�nowrrZ	timetuplervZ	timedeltar�rWr7r;r[rO)rr�ZdtimeZthenZdstrZ
dtime_thenZdbytesZdtuplerrr�test_comparison	s>


z DateTimeTestCase.test_comparisonN)r*r+r,r�r�r�r�r�r�r�r�rrrrr��s

r�c@s$eZdZdd�Zdd�Zdd�ZdS)�BinaryTestCasecCst��}|�t|�d�dS)N�)rrYrr&)rr3rrrr�7szBinaryTestCase.test_defaultcCs(d}t�|�}|�t|�t|d��dS)Nsabc123��zlatin-1)rrYrr&)rr'r3rrr�test_string;s
zBinaryTestCase.test_stringcCsZd}t�|�}t��}|�|�|�t|�t|d��t�|�}|�t|�t|d��dS)Nsabc123��zlatin-1)�base64ZencodebytesrrYr�rr&Z_binary)rr'Zder�r4rrrr�@s


zBinaryTestCase.test_decodeN)r*r+r,r�r�r�rrrrr�0sr�c
Cs0Gdd�d�}Gdd�dtjj�}|s.tjj}|d||ddd�}z�y�|��|j��\aadttfa	|�
�|��|��|�
t�|�
d	d
�d�|j
dd
��}|j
dd�dd��}|�}	|j|	dd�|��x|dkr�|��|d8}q�WWntjk
�rYnXWd|j��da|��XdS)Nc@s*eZdZdd�Zdd�ZGdd�d�ZdS)z&http_server.<locals>.TestInstanceClasscSs||S)Nr)rr0r1rrr�divRsz*http_server.<locals>.TestInstanceClass.divcSs|dkrdSdS)Nr�zThis is the div functionr)rr�rrr�_methodHelpUsz2http_server.<locals>.TestInstanceClass._methodHelpc@seZdZedd��ZdS)z.http_server.<locals>.TestInstanceClass.FixturecSsdS)N�42rrrrr�getDataZsz6http_server.<locals>.TestInstanceClass.Fixture.getDataN)r*r+r,�staticmethodr�rrrr�FixtureYsr�N)r*r+r,r�r�r�rrrr�TestInstanceClassQsr�c@seZdZdd�ZdS)z#http_server.<locals>.MyXMLRPCServercSs |j��\}}|�d�||fS)NT)r��accept�setblocking)rr�portrrr�get_request_s
z/http_server.<locals>.MyXMLRPCServer.get_requestN)r*r+r,r�rrrr�MyXMLRPCServer^sr�)�	localhostrF)rT�logRequests�bind_and_activatezhttp://%s:%dcSs|S)Nr)r0rrr�<lambda>x�zhttp_server.<locals>.<lambda>utêštcSsdS)zThis is my functionTrrrrr�my_functionysz http_server.<locals>.my_function�add)r�cSs||S)Nr)r0r1rrr�_}szhttp_server.<locals>._T)Zallow_dotted_namesrr	)rmr��SimpleXMLRPCServer�SimpleXMLRPCRequestHandler�server_bindr��getsockname�ADDR�PORT�URL�server_activate� register_introspection_functions�register_multicall_functionsr��powr��setr��timeout�close)
�evt�numrequests�requestHandlerrTr�r��servr�r�ZtestInstancerrr�http_serverPs:





r
cCsxGdd�d�}dd�}Gdd�dtjj�}|s6tjj}Gdd�d|�}Gd	d
�d
�}|d|ddd
�}|j�d�|��z�y�|j��\aa	dtt	fa
|��ddg}	x.|	D]&}
|�|
tj�
��}|��|��q�W|�|	d��t�|�|	d��dd�d�|�d|��|��x |dk�r:|��|d8}�qWWntjk
�rVYnXWd|j��da	|��XdS)Nc@seZdZdd�Zdd�ZdS)z,http_multi_server.<locals>.TestInstanceClasscSs||S)Nr)rr0r1rrrr��sz0http_multi_server.<locals>.TestInstanceClass.divcSs|dkrdSdS)Nr�zThis is the div functionr)rr�rrrr��sz8http_multi_server.<locals>.TestInstanceClass._methodHelpN)r*r+r,r�r�rrrrr��sr�cSsdS)zThis is my functionTrrrrrr��sz&http_multi_server.<locals>.my_functionc@seZdZdd�ZdS)z)http_multi_server.<locals>.MyXMLRPCServercSs |j��\}}|�d�||fS)NT)r�r�r�)rrr�rrrr��s
z5http_multi_server.<locals>.MyXMLRPCServer.get_requestN)r*r+r,r�rrrrr��sr�c@seZdZgZdS)z+http_multi_server.<locals>.MyRequestHandlerN)r*r+r,Z	rpc_pathsrrrr�MyRequestHandler�src@seZdZddd�ZdS)z+http_multi_server.<locals>.BrokenDispatcherNcSstd��dS)Nzbroken dispatcher)�RuntimeError)rr_Zdispatch_method�pathrrr�_marshaled_dispatch�sz?http_multi_server.<locals>.BrokenDispatcher._marshaled_dispatch)NN)r*r+r,rrrrr�BrokenDispatcher�sr)r�rF)r�r�r:zhttp://%s:%dz/fooz/foo/barrr	cSs||S)Nr)r0r1rrrr��r�z#http_multi_server.<locals>.<lambda>r�z
/is/broken)rmr�ZMultiPathXMLRPCServerr�r�r�r�r�r�r�r�r�Zadd_dispatcherr�rrZget_dispatcherr�rrr�rr)rrrr�r�r�rrr	�pathsr
r'rrr�http_multi_server�s@



rcCs^y(|jdks|jdkrdS|j�d�}Wntk
rDt|�}YnX|rZd|��krZdSdS)z�Returns True if the given ProtocolError is the product of a server-side
       exception caused by the 'temporarily unavailable' response sometimes
       given by operations on non-blocking sockets.r
NTzX-exceptionztemporarily unavailable)Zerrcoderxryr�r&�lower)�eZexc_messrrr�is_unavailable_exception�srcs|sdd�S�fdd�}|S)NcSs|S)Nr)�funcrrrr��r�z)make_request_and_skipIf.<locals>.<lambda>cs�fdd�}|S)Nc
sTyt�t���Wn2tjtfk
rD}zt|�s4�Wdd}~XYnXt����dS)N)	rrsr�r��
ProtocolErrorrur�unittestZSkipTest)rr)�reasonrr�make_request_and_skip�szImake_request_and_skipIf.<locals>.decorator.<locals>.make_request_and_skipr)rr)rrr�	decorator�sz*make_request_and_skipIf.<locals>.decoratorr)Z	conditionrrr)rr�make_request_and_skipIf�s	rc@s,eZdZdZdZee�Zdd�Zdd�Z	dS)�BaseServerTestCaseNr	cCs`dtjj_t��|_|j|j|jf}tj	|j
|d�}|��|�|j
�|j��|j��dS)NT)r�r�)rmr�r��_send_traceback_headerr��Eventr�
request_countrr��
threadFuncr�r�r��wait�clear)r�	serv_argsr�rrr�setUp�s


zBaseServerTestCase.setUpcCs|j��dtjj_dS)NF)rr!rmr�r�r)rrrr�tearDowns
zBaseServerTestCase.tearDown)
r*r+r,rrr�r
r r$r%rrrrr�s
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
ejj
dkd�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�SimpleServerTestCasecCsry"t�t�}|�|�dd�d�WnJtjtfk
rl}z&t|�s\|�d|t	|dd�f�Wdd}~XYnXdS)Nr�r�i�z%s
%srxr�)
rrsr�rrrrur�fail�getattr)rr�rrrr�test_simple1s
z!SimpleServerTestCase.test_simple1cCs~d}d}y&t�t�}|�|�||�||�WnJtjtfk
rx}z&t|�sh|�d|t	|dd�f�Wdd}~XYnXdS)NuPŷtuhơnz%s
%srxr�)
rrsr�rr�rrurr'r()r�start_string�
end_stringr�rrrr�
test_nonasciis
z"SimpleServerTestCase.test_nonasciicCs�d}d}y*tjtdd�}|�|�||�||�WnLtjtjfk
r~}z&t|�sn|�	d|t
|dd�f�Wdd}~XYnXdS)Nu€�¤ziso-8859-15)rTz%s
%srxr�)rrsr�rr�rr��errorrr'r()rr*r+r�rrrr�test_client_encoding'sz)SimpleServerTestCase.test_client_encodingcCsvy$tjtdd�}|�|�d�d�WnLtjtjfk
rp}z&t|�s`|�	d|t
|dd�f�Wdd}~XYnXdS)Nr�)rTrNz%s
%srxr�)rrsr�rttêštrr�r.rr'r()rr�rrrr�test_nonascii_methodname5sz-SimpleServerTestCase.test_nonascii_methodnamecCsJtj�tt�}|�dd�|��}|��|�|j	d�|�|j
d�dS)NZPOSTz/this-is-not-validi�z	Not Found)r|rn�HTTPConnectionr�r�ZrequestZgetresponserr�statusr)r�connr�rrr�test_404?szSimpleServerTestCase.test_404cCs�tddddddddd	d
g
�}y(t�t�}|j��}|�t|�|�WnJtjtfk
r�}z&t	|�s~|�
d|t|dd
�f�Wdd}~XYnXdS)Nrr�r�r�utêštzsystem.listMethodszsystem.methodHelpzsystem.methodSignaturezsystem.multicallr�z%s
%srxr�)rrrsr��systemZlistMethodsrrrurr'r()rZexpected_methodsr�Zmethrrrr�test_introspection1Js

z(SimpleServerTestCase.test_introspection1cCsvy&t�t�}|j�d�}|�|d�WnJtjtfk
rp}z&t|�s`|�	d|t
|dd�f�Wdd}~XYnXdS)Nr�zThis is the div functionz%s
%srxr�)rrsr�r5�
methodHelprrrurr'r()rr�Zdivhelprrrr�test_introspection2Zs
z(SimpleServerTestCase.test_introspection2rz)Docstrings are omitted with -O2 and abovecCsvy&t�t�}|j�d�}|�|d�WnJtjtfk
rp}z&t|�s`|�	d|t
|dd�f�Wdd}~XYnXdS)Nr�zThis is my functionz%s
%srxr�)rrsr�r5r7rrrurr'r()rr�Z
myfunctionrrrr�test_introspection3fs
z(SimpleServerTestCase.test_introspection3cCsvy&t�t�}|j�d�}|�|d�WnJtjtfk
rp}z&t|�s`|�	d|t
|dd�f�Wdd}~XYnXdS)Nr�zsignatures not supportedz%s
%srxr�)rrsr�r5ZmethodSignaturerrrurr'r()rr�Zdivsigrrrr�test_introspection4ts
z(SimpleServerTestCase.test_introspection4cCs�ylt�t�}t�|�}|�dd�|�dd�|�dd�|�\}}}|�|d�|�|d�|�|d�WnJtjt	fk
r�}z&t
|�s�|�d	|t|d
d�f�Wdd}~XYnXdS)Nrr:r�r��rNr>i�z%s
%srxr�)
rrsr��	MultiCallr�rr�rrrurr'r()rr��	multicallZ
add_resultZ
pow_resultZ
div_resultrrrr�test_multicall�s

z#SimpleServerTestCase.test_multicallcCs�yRt�t�}t�|�}|��|�}|�|jddd�|�|jddd�WnJtjtfk
r�}z&t	|�s�|�
d|t|dd�f�Wdd}~XYnXdS)	Nrr�r	r�z@<class 'Exception'>:method "this_is_not_exists" is not supportedz%s
%srxr�)rrsr�r<Zthis_is_not_existsrZresultsrrurr'r()rr�r=rrrrr�test_non_existing_multicall�s


z0SimpleServerTestCase.test_non_existing_multicallcCs4|�ttjjtd�|�tj�td��|��dS)Nr�r�)r7r�rmr�r�r&rvr))rrrrr��sz*SimpleServerTestCase.test_dotted_attributecCs,t�dttf�}|j��}|�|d�dS)Nzhttp://%s:%d/RPC2r�)rrsr�r�r�r�r)rr�r_rrr�test_allow_dotted_names_true�s
z1SimpleServerTestCase.test_allow_dotted_names_truecCs*t�dttf�}|�|�dd�d�dS)Nzhttp://%s:%d/RPC2rd�éuaé)rrsr�r�rr�)rr�rrr�test_unicode_host�sz&SimpleServerTestCase.test_unicode_hostcCs8tj�tt�}|�dt�dt�d��d��|��dS)Nz@POST /RPC2 HTTP/1.0
Content-Length: 100

bye HTTP/1.1
Host: �:z2
Accept-Encoding: identity
Content-Length: 0

r�)r|rnr1r�r��sendrWr)rr3rrr�test_partial_post�sz&SimpleServerTestCase.test_partial_postc	CsJt�t��$}|�dd�|�|d�jd�WdQRX|�|d�jd�dS)Nrr:�	transport)NN)rrsr�r�ZassertNotEqual�_connectionr)rr�rrr�test_context_manager�sz)SimpleServerTestCase.test_context_managerc	CsTy&t�t��}|�dd�WdQRXWntjk
r<YnX|�|d�jd�dS)NrrdrF)NN)rrsr�r�r�rrG)rr�rrr�!test_context_manager_method_error�sz6SimpleServerTestCase.test_context_manager_method_errorN)r*r+r,r)r,r/r0r4r6r8rrG�flags�optimizer9r:r>r?r�r@rBrErHrIrrrrr&s$





r&c@s"eZdZeddd��Zdd�ZdS)�SimpleServerEncodingTestCaseNcCst|||d�dS)Nziso-8859-15)r
)rrrrTrrrr �sz'SimpleServerEncodingTestCase.threadFunccCs�d}d}y&t�t�}|�|�||�||�WnLtjtjfk
rz}z&t|�sj|�	d|t
|dd�f�Wdd}~XYnXdS)Nu€r-z%s
%srxr�)rrsr�rr�rr�r.rr'r()rr*r+r�rrrr�test_server_encoding�s
z1SimpleServerEncodingTestCase.test_server_encoding)NN)r*r+r,r�r rMrrrrrL�srLc@s0eZdZee�ZdZdd�Zdd�Zdd�Z	dS)	�MultiPathServerTestCasercCs:t�td�}|�|�dd�d�|�tj|jdd�dS)Nz/foor�r�i�)rrsr�rrr7r�r�)rr�rrr�
test_path1�sz"MultiPathServerTestCase.test_path1cCs:t�td�}|�|�dd�d�|�tj|jdd�dS)Nz/foo/barr�r��)rrsr�rr�r7r�r)rr�rrr�
test_path2�sz"MultiPathServerTestCase.test_path2cCs&t�td�}|�tj|jdd�dS)Nz
/is/brokenr�r�)rrsr�r7r�r�)rr�rrr�
test_path3�sz"MultiPathServerTestCase.test_path3N)
r*r+r,r�rr rrOrQrRrrrrrN�s
rNc@s,eZdZGdd�dejj�ZeZdd�ZdS)�BaseKeepaliveServerTestCasec@s,eZdZejjZdZgZdd�Z	dd�Z
dS)z*BaseKeepaliveServerTestCase.RequestHandlerzHTTP/1.1cCs(|j�g�t|j�d|_|j�|�S)Nr	)�
myRequestsr?r}�reqidx�parentClass�handle)rrrrrWsz1BaseKeepaliveServerTestCase.RequestHandler.handlecCs$|j�|�}|j|j�|j�|S)N)rV�handle_one_requestrTrUr?Zraw_requestline)rrrrrrX
sz=BaseKeepaliveServerTestCase.RequestHandler.handle_one_requestN)r*r+r,rmr�r�rVr�rTrWrXrrrrr�s
r�cCsg|j_t�|�S)N)r�rTrr$)rrrrr$sz!BaseKeepaliveServerTestCase.setUpN)	r*r+r,rmr�r�r�rr$rrrrrS�s
rSc@seZdZdd�ZdS)�KeepaliveServerTestCase1cCs�t�t�}|�|�dd�d�|�|�dd�d�|�|�dd�d�|d��|�t|jj�d�|�t|jjd�d�dS)Nr�r�i�rr	r
r)	rrsr�rrr}r�rT�assertGreaterEqual)rr�rrr�test_twos

z!KeepaliveServerTestCase1.test_twoN)r*r+r,r[rrrrrYsrYc@s eZdZdZdd�Zdd�ZdS)�KeepaliveServerTestCase2rcCs�t�t�}|�|�dd�d�|�|�dd�d�|�|�dd�d�|d��|�|�dd�d�|�|�dd�d�|�|�dd�d�|d��|�t|jj�d�|�t|jjd�d�|�t|jjd�d�dS)Nr�r�i�rrr
���)	rrsr�rrr}r�rTrZ)rr�rrr�
test_close.s


z#KeepaliveServerTestCase2.test_closecCs`t�t�}|�|�dd�d�|d���|�|�dd�d�|d��|�t|jj�d�dS)Nr�r�i�rFrr)	rrsr�rrrr}r�rT)rr�rrr�test_transportAs

z'KeepaliveServerTestCase2.test_transportN)r*r+r,rr^r_rrrrr\*sr\z
requires gzipc@sVeZdZGdd�dejj�ZeZGdd�dej	�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
S)�GzipServerTestCasec@s eZdZejjZdZdd�ZdS)z!GzipServerTestCase.RequestHandlerzHTTP/1.1cCst|jd�|j_|j�|�S)Nzcontent-length)rIrx�	__class__�content_lengthrVr�)rrrrr�Tsz)GzipServerTestCase.RequestHandler.do_POSTN)	r*r+r,rmr�r�rVr�r�rrrrr�Psr�c@s eZdZdZdd�Zdd�ZdS)zGzipServerTestCase.TransportFcCs t|�dd��|_tj�||�S)Nzcontent-lengthr)rIZ	getheader�response_lengthrro�parse_response)rr�rrrrd]sz+GzipServerTestCase.Transport.parse_responsecCs"|jr|�dd�tj�|||�S)NzContent-Encoding�gzip)�	fake_gzipZ	putheaderrro�send_content)rZ
connectionZbodyrrrrgasz)GzipServerTestCase.Transport.send_contentN)r*r+r,rfrdrgrrrrroZsrocCst�|�dS)N)rr$)rrrrr$gszGzipServerTestCase.setUpcCsv|��}d|_tjt|d�}|�|�dd�d�|jj}d|_|�|�dd�d�|jj}|�	||k�|d��dS)N)rFr�r�i�rr)
ro�encode_thresholdrrsr�rrr�rbrv)rr3r�rdrerrr�test_gzip_requestjsz$GzipServerTestCase.test_gzip_requestc	Cs`|��}d|_d|_tjt|d�}|�tjt�	d��}|�|�
dd�WdQRX|d��dS)NT)rFz\b400\br�r�r)rorhrfrrsr�r�r�re�compiler)rr3r��cmrrr�test_bad_gzip_requestvsz(GzipServerTestCase.test_bad_gzip_requestcCs�|��}tjt|d�}|jj}d|j_|�|�dd�d�|j}d|j_|�|�dd�d�|d��|j}||j_|�	||k�dS)N)rFr�r�i�rr)
rorrsr�rrhrrrcrv)rr3r��oldrdrerrr�test_gzip_response�s
z%GzipServerTestCase.test_gzip_responseN)r*r+r,rmr�r�r�rrror$rirmrorrrrr`Ls
r`c@seZdZdd�ZdS)�GzipUtilTestCasec	Cszd}d|}t�|�}t�|�}|�t|�|�d|d}t�|�}|�td��t�|�WdQRXtj|dd�dS)Ni@�r	z#max gzipped payload length exceededr
)Z
max_decode)rZgzip_encodeZgzip_decoderr}r�rk)rZmax_gzip_decoder_ZencodedZdecodedrrr�test_gzip_decode_limit�s


z'GzipUtilTestCase.test_gzip_decode_limitN)r*r+r,rrrrrrrp�srpc@s$eZdZdd�Zdd�Zdd�ZdS)�ServerProxyTestCasecCstj�|�d|_dS)Nzhttp://fake.localhost)r�TestCaser$r�)rrrrr$�szServerProxyTestCase.setUpcCs"t�|j�}|�|d��d�dS)Nr)rrsr�r)rr�rrrr^�szServerProxyTestCase.test_closecCs,t��}tj|j|d�}|�|d�|�dS)N)rFrF)rrorsr�r)rr3r�rrrr_�sz"ServerProxyTestCase.test_transportN)r*r+r,r$r^r_rrrrrs�srscseZdZd�fdd�	Z�ZS)�FailingMessageClassNcs"|��}|dkrdSt��||�S)Nzcontent-lengthzI am broken)r�superry)r�keyZfailobj)rarrry�szFailingMessageClass.get)N)r*r+r,ry�
__classcell__rr)rarru�sruc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�FailingServerTestCasecCsNt��|_|jdf}tjt|d�}|��|�|j�|j��|j�	�dS)Nr	)r�r�)
r�rrr�r
r�r�r�r!r")rr#r�rrrr$�s


zFailingServerTestCase.setUpcCs*|j��dtjj_tjj}|tjj	_
dS)NF)rr!rmr�r�rr|rn�HTTPMessager��MessageClass)rZ
default_classrrrr%�s

zFailingServerTestCase.tearDowncCs�tjjj}|�|d�dtjj_y"t�t�}|�|�dd�d�WnJtj	t
fk
r�}z&t|�s||�d|t
|dd�f�Wdd}~XYnXdS)	NFTr�r�i�z%s
%srxr�)rmr�r�rrrrsr�rrrurr'r()rZflagvalr�rrrr�
test_basic�s


z FailingServerTestCase.test_basicc
Cs�ttjj_yt�t�}|�dd�Wnftj	t
fk
r�}zBt|�szt|d�rz|�
|j�d�dk�|�
|j�d�dk�Wdd}~XYnX|�d�dS)Nr�r�rxzX-exceptionzX-tracebackzProtocolError not raised)rurmr�r�r{rrsr�rrrur�hasattrrvrxryr')rr�rrrr�test_fail_no_info�s

(z'FailingServerTestCase.test_fail_no_infoc
Cs�ttjj_dtjj_yt�t	�}|�
dd�Wnhtjtfk
r�}zDt
|�s�t|d�r�d}|�|j�d�|�|�|j�d�dk	�Wdd}~XYnX|�d�dS)	NTr�r�rxz5invalid literal for int() with base 10: 'I am broken'zX-exceptionzX-tracebackzProtocolError not raised)rurmr�r�r{r�rrrsr�rrrurr}rrxryrvr')rr�rZexpected_errrrr�test_fail_with_info�s


(z)FailingServerTestCase.test_fail_with_infoN)r*r+r,r$r%r|r~rrrrrry�s
	ry�utf-8ccs4tj}tjt��|d�t_ztjVWd|t_XdS)zhA variation on support.captured_stdout() which gives a text stream
    having a `buffer` attribute.
    )rTN)rG�stdout�io�
TextIOWrapper�BytesIO)rTZorig_stdoutrrr�captured_stdouts
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�CGIHandlerTestCasecCstj��|_dS)N)rmr��CGIXMLRPCRequestHandler�cgi)rrrrr$szCGIHandlerTestCase.setUpcCs
d|_dS)N)r�)rrrrr%szCGIHandlerTestCase.tearDownc
Cs�t���~}d|d<t|jjd��}|j��WdQRX|�d�|��}|��d}d�	|��dd��}|�
|d	�|�
|d
�WdQRXdS)NZGETZREQUEST_METHOD)rTrr	� rr=Z400zBad Request)r�EnvironmentVarGuardr�r�rTr��seekrz�splitr�r)r�env�data_outrWr2�messagerrr�test_cgi_get"s

zCGIHandlerTestCase.test_cgi_getcCs�d}t���b}t|jjd��H}t���4}|�|�|�d�tt	|��|d<|j�
�WdQRXWdQRXWdQRX|�d�|��}|�t
jt
j|dd��||�d�d�}|�tt�d|��d��t	|��dS)	Naw<?xml version='1.0'?>
        <methodCall>
            <methodName>test_method</methodName>
            <params>
                <param>
                    <value><string>foo</string></value>
                </param>
                <param>
                    <value><string>bar</string></value>
                </param>
            </params>
        </methodCall>
        )rTrZCONTENT_LENGTH�,z<?xmlzContent-Length: (\d+)r	)rr�r�r�rTZcaptured_stdinr~r�r&r}r�rzr7rr�r�findrrIrj�search�group)rr_r�r�Zdata_inrWZcontentrrr�test_cgi_xmlrpc_response4s




(
z+CGIHandlerTestCase.test_cgi_xmlrpc_responseN)r*r+r,r$r%r�r�rrrrr�sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�UseBuiltinTypesTestCasecs�g�_d}t�dddddd�}t�||fd�}�fd	d
�}tjjdddd�}|�|�|�|���	t
�j�d
��j\}}��	�j||g���t|�tj���t|�t
�dS)Nsmy dog has fleasi�r>�����foobarcs�j�|�dS)N)�log�extend)r�)rrrr�isz>UseBuiltinTypesTestCase.test_use_builtin_types.<locals>.foobarT)rQrTrr)r�rrr
rmr�r�r�rrr}rrrZ)rZexpected_bytesZ
expected_dateZ	marshaledr��handlerZmybytesZmydater)rr�test_use_builtin_typesas


z.UseBuiltinTypesTestCase.test_use_builtin_typescCstjjdd�}|�|j�dS)NT)r)rmr�r�rvr)rr�rrr�*test_cgihandler_has_use_builtin_types_flaguszBUseBuiltinTypesTestCase.test_cgihandler_has_use_builtin_types_flagcCs(tjjddd�}|��|�|j�dS)N)r�rT)r)rmr�r�r�rvr)rr�rrr�,test_xmlrpcserver_has_use_builtin_types_flagyszDUseBuiltinTypesTestCase.test_xmlrpcserver_has_use_builtin_types_flagN)r*r+r,r�r�r�rrrrr�_sr�cCs.t�tttttttt	t
ttt
ttttt�dS)N)rZrun_unittestrr�r�r�r�r�r&rLrYr\r`rprNrsryr�r�rrrr�	test_main�s
r��__main__)NN)N)r�)?r�rrirGr�rrZ
xmlrpc.clientrnrZ
xmlrpc.serverrmZhttp.clientr|Zhttp.serverr�r�rjr��
contextlibZtestrrerrrYr[rrrtrr�r�r�r�r�r�r�r�r
rrrrr&rLrNrSrYr\ZskipIfr`rprsrzrury�contextmanagerr�r�r�Zreap_threadsr�r*rrrr�<module>s�
=WW
@
CJ"C
ND!