B
    u9a‚  ã               @   sn   d dl mZ d dlZd dlZd dlZd dlmZ d dlZdd„ Z	dd„ Z
G dd	„ d	ejƒZed
krje ¡  dS )é    )ÚDocXMLRPCServerN)Úsupportc                s   | sdd„ S ‡ fdd„}|S )Nc             S   s   | S )N© )Úfuncr   r   ú$/usr/lib/python3.7/test_docxmlrpc.pyÚ<lambda>   ó    z)make_request_and_skipIf.<locals>.<lambda>c                s   ‡ fdd„}|S )Nc                s&   | j  dd¡ | j  ¡  t ˆ ¡‚d S )NÚGETú/)ÚclientÚrequestÚgetresponseÚunittestZSkipTest)Úself)Úreasonr   r   Úmake_request_and_skip   s    
zImake_request_and_skipIf.<locals>.decorator.<locals>.make_request_and_skipr   )r   r   )r   r   r   Ú	decorator   s    z*make_request_and_skipIf.<locals>.decoratorr   )Z	conditionr   r   r   )r   r   Úmake_request_and_skipIf   s    r   c              C   sÀ   t ddd} y˜|  d¡ |  d¡ |  d¡ G dd„ dtƒ}|  ¡  |  |ƒ ¡ d	d
„ }tdœdd„}G dd„ dƒ}|  |¡ |  dd„ ¡ |  |¡ |  |ƒ ¡ | S    |  	¡  ‚ Y nX d S )N)Z	localhostr   F)ZlogRequestsz"DocXMLRPCServer Test DocumentationzDocXMLRPCServer Test DocszmThis is an XML-RPC server's documentation, but the server can be used by POSTing to /RPC2. Try self.add, too.c               @   s   e Zd Zdd„ ZdS )zmake_server.<locals>.TestClassc             S   s
   || _ d S )N)Úarg)r   r   r   r   r   Útest_method#   s    z*make_server.<locals>.TestClass.test_methodN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   Ú	TestClass"   s   r   c             S   s   | | S )Nr   )ÚxÚyr   r   r   Úadd*   s    zmake_server.<locals>.add)r   c             S   s   | S )Nr   )r   r   r   r   Ú
annotation2   s    zmake_server.<locals>.annotationc               @   s   e Zd Zedœdd„ZdS )z(make_server.<locals>.ClassWithAnnotation)r   c             S   s   |  ¡ S )N)Údecode)r   r   r   r   r   Úmethod_annotation7   s    z:make_server.<locals>.ClassWithAnnotation.method_annotationN)r   r   r   Úbytesr   r   r   r   r   ÚClassWithAnnotation6   s   r!   c             S   s   | | S )Nr   )r   r   r   r   r   r   ;   r   zmake_server.<locals>.<lambda>)
r   Zset_server_titleZset_server_nameZset_server_documentationÚobjectZ register_introspection_functionsZregister_instanceÚintZregister_functionÚserver_close)Úservr   r   r   r!   r   r   r   Úmake_server   s(    



r&   c               @   sx   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zee	j
jdkdƒdd„ ƒZee	j
jdkdƒdd„ ƒZdd„ Zdd„ ZdS )ÚDocXMLRPCHTTPGETServerc             C   sL   dt _tƒ | _tj| jjd| _| j ¡  | jj	d }t
j d| ¡| _d S )NT)Útargeté   zlocalhost:%d)r   Ú_send_traceback_headerr&   r%   Ú	threadingZThreadZserve_foreverÚthreadÚstartZserver_addressÚhttpr   ZHTTPConnection)r   ZPORTr   r   r   ÚsetUpD   s    
zDocXMLRPCHTTPGETServer.setUpc             C   s2   | j  ¡  dt_| j ¡  | j ¡  | j ¡  d S )NF)	r   Úcloser   r*   r%   Zshutdownr,   Újoinr$   )r   r   r   r   ÚtearDownO   s
    


zDocXMLRPCHTTPGETServer.tearDownc             C   sD   | j  dd¡ | j  ¡ }|  |jd¡ |  | d¡d¡ | ¡  d S )Nr	   r
   éÈ   zContent-typez	text/html)r   r   r   ÚassertEqualÚstatusÚ	getheaderÚread)r   Úresponser   r   r   Útest_valid_get_responseX   s
    
z.DocXMLRPCHTTPGETServer.test_valid_get_responsec             C   sD   | j  dd¡ | j  ¡ }|  |jd¡ |  | d¡d¡ | ¡  d S )Nr	   z/spami”  zContent-typez
text/plain)r   r   r   r4   r5   r6   r7   )r   r8   r   r   r   Útest_invalid_get_responseb   s
    
z0DocXMLRPCHTTPGETServer.test_invalid_get_responsec             C   s,   | j  dd¡ | j  ¡ }|  d| ¡ ¡ d S )Nr	   r
   sU   <dl><dt><a name="-&lt;lambda&gt;"><strong>&lt;lambda&gt;</strong></a>(x, y)</dt></dl>)r   r   r   ÚassertInr7   )r   r8   r   r   r   Útest_lambdak   s    
z"DocXMLRPCHTTPGETServer.test_lambdaé   z)Docstrings are omitted with -O2 and abovec             C   s,   | j  dd¡ | j  ¡  ¡ }|  d|¡ d S )Nr	   r
   sM  <dl><dt><a name="-add"><strong>add</strong></a>(x, y)</dt><dd><tt>Add&nbsp;two&nbsp;instances&nbsp;together.&nbsp;This&nbsp;follows&nbsp;<a href="http://www.python.org/dev/peps/pep-0008/">PEP008</a>,&nbsp;but&nbsp;has&nbsp;nothing<br>
to&nbsp;do&nbsp;with&nbsp;<a href="http://www.rfc-editor.org/rfc/rfc1952.txt">RFC1952</a>.&nbsp;Case&nbsp;should&nbsp;matter:&nbsp;pEp008&nbsp;and&nbsp;rFC1952.&nbsp;&nbsp;Things<br>
that&nbsp;start&nbsp;with&nbsp;http&nbsp;and&nbsp;ftp&nbsp;should&nbsp;be&nbsp;auto-linked,&nbsp;too:<br>
<a href="http://google.com">http://google.com</a>.</tt></dd></dl>)r   r   r   r7   r;   )r   r8   r   r   r   Útest_autolinkingy   s
    		z'DocXMLRPCHTTPGETServer.test_autolinkingc             C   s,   | j  dd¡ | j  ¡  ¡ }|  d|¡ d S )Nr	   r
   sÕ  <dl><dt><a name="-system.methodHelp"><strong>system.methodHelp</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodHelp">system.methodHelp</a>('add')&nbsp;=&gt;&nbsp;"Adds&nbsp;two&nbsp;integers&nbsp;together"<br>
&nbsp;<br>
Returns&nbsp;a&nbsp;string&nbsp;containing&nbsp;documentation&nbsp;for&nbsp;the&nbsp;specified&nbsp;method.</tt></dd></dl>
<dl><dt><a name="-system.methodSignature"><strong>system.methodSignature</strong></a>(method_name)</dt><dd><tt><a href="#-system.methodSignature">system.methodSignature</a>('add')&nbsp;=&gt;&nbsp;[double,&nbsp;int,&nbsp;int]<br>
&nbsp;<br>
Returns&nbsp;a&nbsp;list&nbsp;describing&nbsp;the&nbsp;signature&nbsp;of&nbsp;the&nbsp;method.&nbsp;In&nbsp;the<br>
above&nbsp;example,&nbsp;the&nbsp;add&nbsp;method&nbsp;takes&nbsp;two&nbsp;integers&nbsp;as&nbsp;arguments<br>
and&nbsp;returns&nbsp;a&nbsp;double&nbsp;result.<br>
&nbsp;<br>
This&nbsp;server&nbsp;does&nbsp;NOT&nbsp;support&nbsp;system.methodSignature.</tt></dd></dl>)r   r   r   r7   r;   )r   r8   r   r   r   Útest_system_methods‘   s
    z*DocXMLRPCHTTPGETServer.test_system_methodsc             C   s,   | j  dd¡ | j  ¡ }|  d| ¡ ¡ d S )Nr	   r
   s-   Try&nbsp;self.<strong>add</strong>,&nbsp;too.)r   r   r   r;   r7   )r   r8   r   r   r   Útest_autolink_dotted_methods®   s    
z3DocXMLRPCHTTPGETServer.test_autolink_dotted_methodsc             C   sH   | j  dd¡ | j  ¡ }tjjdkr(dnd}|  d| d | ¡ ¡ d S )Nr	   r
   r=   r   s5   <dd><tt>Use&nbsp;function&nbsp;annotations.</tt></dd>sJ   <dl><dt><a name="-annotation"><strong>annotation</strong></a>(x: int)</dt>se   </dl>
<dl><dt><a name="-method_annotation"><strong>method_annotation</strong></a>(x: bytes)</dt></dl>)r   r   r   ÚsysÚflagsÚoptimizer;   r7   )r   r8   Z	docstringr   r   r   Útest_annotations·   s    

z'DocXMLRPCHTTPGETServer.test_annotationsN)r   r   r   r/   r2   r9   r:   r<   r   rA   rB   rC   r>   r?   r@   rD   r   r   r   r   r'   C   s   	
		r'   Ú__main__)Zxmlrpc.serverr   Zhttp.clientr.   rA   r+   Ztestr   r   r   r&   ZTestCaser'   r   Úmainr   r   r   r   Ú<module>   s   - 