ó
è¾bc           @   sÙ   d  Z  d d l Z d d l Z d d l Z d d l Z d d l m Z m Z m Z m Z d „  Z	 d e j
 f d „  ƒ  YZ d d d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   sK  Self documenting XML-RPC Server.

This module can be used to create XML-RPC servers that
serve pydoc-style documentation in response to HTTP
GET requests. This documentation is dynamically generated
based on the functions and methods registered with the
server.

This module is built upon the pydoc and SimpleXMLRPCServer
modules.
iÿÿÿÿN(   t   SimpleXMLRPCServert   SimpleXMLRPCRequestHandlert   CGIXMLRPCRequestHandlert   resolve_dotted_attributec         C   s^   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d	 d
 ƒ }  |  S(   Nt   &s   &amp;t   <s   &lt;t   >s   &gt;t   "s   &quot;s   's   &#x27;(   t   replace(   t   s(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   _html_escape_quote   s    t   ServerHTMLDocc           B   sD   e  Z d  Z d i  i  i  d „ Z d i  i  i  d d „ Z d „  Z RS(   s7   Class used to generate pydoc HTML document for a serverc         C   sÑ  | p |  j  } g  } d } t j d ƒ } x€| j | | ƒ }	 |	 sI Pn  |	 j ƒ  \ }
 } | j | | | |
 !ƒ ƒ |	 j ƒ  \ } } } } } } | rË | | ƒ j d d ƒ } | j d | | f ƒ nØ | rd t | ƒ } | j d | | | ƒ f ƒ n¢ | r7d t | ƒ } | j d | | | ƒ f ƒ nl | | | d !d	 k rp| j |  j	 | | | | ƒ ƒ n3 | rŠ| j d
 | ƒ n | j |  j	 | | ƒ ƒ | } q- W| j | | | ƒ ƒ d j
 | ƒ S(   sƒ   Mark up some plain text, given a context of symbols to look for.
        Each context dictionary maps object names to anchor names.i    sM   \b((http|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?((?:\w|\.)+))\bR   s   &quot;s   <a href="%s">%s</a>s'   http://www.rfc-editor.org/rfc/rfc%d.txts(   http://www.python.org/dev/peps/pep-%04d/i   t   (s   self.<strong>%s</strong>t    (   t   escapet   ret   compilet   searcht   spant   appendt   groupsR   t   intt   namelinkt   join(   t   selft   textR   t   funcst   classest   methodst   resultst   heret   patternt   matcht   startt   endt   allt   schemet   rfct   pept   selfdott   namet   url(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   markup$   s8       "
c         C   sŒ  | r | j  p d d | } d }	 d |  j | ƒ |  j | ƒ f }
 t j | ƒ rš t j | j ƒ \ } } } } t j | d | | | d |  j ƒ} nT t j | ƒ rè t j | ƒ \ } } } } t j | | | | d |  j ƒ} n d } t	 | t
 ƒ r | d p
| } | d pd } n t j | ƒ } |
 | |	 oL|  j d |	 ƒ } |  j | |  j | | | ƒ } | o{d	 | } d
 | | f S(   s;   Produce HTML documentation for a function or method object.R   t   -s$   <a name="%s"><strong>%s</strong></a>i   t   formatvalues   (...)i    s'   <font face="helvetica, arial">%s</font>s   <dd><tt>%s</tt></dd>s   <dl><dt>%s</dt>%s</dl>
(   t   __name__R   t   inspectt   ismethodt
   getargspect   im_funct   formatargspecR,   t
   isfunctiont
   isinstancet   tuplet   pydoct   getdoct   greyR*   t	   preformat(   R   t   objectR(   t   modR   R   R   t   clt   anchort   notet   titlet   argst   varargst   varkwt   defaultst   argspect	   docstringt   declt   doc(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt
   docroutineM   s6    c         C   s  i  } x6 | j  ƒ  D]( \ } } d | | | <| | | | <q W|  j | ƒ } d | } |  j | d d ƒ } |  j | |  j | ƒ }	 |	 o’ d |	 }	 | d |	 } g  }
 t | j  ƒ  ƒ } x3 | D]+ \ } } |
 j |  j | | d | ƒƒ qÂ W| |  j d d d	 t	 j
 |
 ƒ ƒ } | S(
   s1   Produce HTML documentation for an XML-RPC server.s   #-s)   <big><big><strong>%s</strong></big></big>s   #ffffffs   #7799ees   <tt>%s</tt>s
   <p>%s</p>
R   t   Methodss   #eeaa77(   t   itemsR   t   headingR*   R9   t   sortedR   RH   t
   bigsectionR6   R   (   R   t   server_namet   package_documentationR   t   fdictt   keyt   valuet   headt   resultRG   t   contentst   method_items(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt	   docserverw   s"    
#	N(   R-   t
   __module__t   __doc__t   NoneR*   RH   RW   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR   !   s
   ))t   XMLRPCDocGeneratorc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s…   Generates documentation for an XML-RPC server.

    This class is designed as mix-in and should not
    be constructed directly.
    c         C   s   d |  _  d |  _ d |  _ d  S(   Ns   XML-RPC Server DocumentationsG   This server exports the following methods through the XML-RPC protocol.(   RN   t   server_documentationt   server_title(   R   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   __init__—   s    		c         C   s   | |  _  d S(   s8   Set the HTML title of the generated server documentationN(   R]   (   R   R]   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   set_server_titleŸ   s    c         C   s   | |  _  d S(   s7   Set the name of the generated HTML server documentationN(   RN   (   R   RN   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   set_server_name¤   s    c         C   s   | |  _  d S(   s3   Set the documentation string for the entire server.N(   R\   (   R   R\   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   set_server_documentation©   s    c         C   s{  i  } x/|  j  ƒ  D]!} | |  j k r8 |  j | } nò |  j d k	 rd d g } t |  j d ƒ r~ |  j j | ƒ | d <n  t |  j d ƒ r© |  j j | ƒ | d <n  t | ƒ } | d k rÊ | } q*t |  j d ƒ sy t |  j | ƒ } Wqt	 k
 r| } qXq*| } n d s*t
 d ƒ ‚ | | | <q Wt ƒ  } | j |  j |  j | ƒ } t |  j ƒ } | j | | ƒ S(	   s  generate_html_documentation() => html documentation for the server

        Generates HTML documentation for the server using introspection for
        installed functions and instances that do not implement the
        _dispatch method. Alternatively, instances can choose to implement
        the _get_method_argstring(method_name) method to provide the
        argument string used in the documentation and the
        _methodHelp(method_name) method to provide the help text used
        in the documentation.t   _get_method_argstringi    t   _methodHelpi   t	   _dispatchsA   Could not find method in self.functions and no instance installedN(   NN(   t   system_listMethodsR   t   instanceRZ   t   hasattrRb   Rc   R5   R   t   AttributeErrort   AssertionErrorR   RW   RN   R\   R
   R]   t   page(   R   R   t   method_namet   methodt   method_infot
   documentert   documentationR?   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   generate_html_documentation®   s<    				(   R-   RX   RY   R^   R_   R`   Ra   Rp   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR[      s   				t   DocXMLRPCRequestHandlerc           B   s   e  Z d  Z d „  Z RS(   sè   XML-RPC and documentation request handler class.

    Handles all HTTP POST requests and attempts to decode them as
    XML-RPC requests.

    Handles all HTTP GET requests and interprets them as requests
    for documentation.
    c         C   s€   |  j  ƒ  s |  j ƒ  d S|  j j ƒ  } |  j d ƒ |  j d d ƒ |  j d t t | ƒ ƒ ƒ |  j ƒ  |  j	 j
 | ƒ d S(   s}   Handles the HTTP GET request.

        Interpret all HTTP GET requests as requests for server
        documentation.
        NiÈ   s   Content-types	   text/htmls   Content-length(   t   is_rpc_path_validt
   report_404t   serverRp   t   send_responset   send_headert   strt   lent   end_headerst   wfilet   write(   R   t   response(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   do_GETì   s    

(   R-   RX   RY   R}   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyRq   â   s   t   DocXMLRPCServerc           B   s&   e  Z d  Z e d e d e d „ Z RS(   sŽ   XML-RPC and HTML documentation server.

    Adds the ability to serve server documentation to the capabilities
    of SimpleXMLRPCServer.
    i   c         C   s0   t  j |  | | | | | | ƒ t j |  ƒ d  S(   N(   R    R^   R[   (   R   t   addrt   requestHandlert   logRequestst
   allow_nonet   encodingt   bind_and_activate(    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR^     s    N(   R-   RX   RY   Rq   t   FalseRZ   t   TrueR^   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR~   þ   s   	t   DocCGIXMLRPCRequestHandlerc           B   s    e  Z d  Z d „  Z d „  Z RS(   sJ   Handler for XML-RPC data and documentation requests passed through
    CGIc         C   s5   |  j  ƒ  } d GHd t | ƒ GHHt j j | ƒ d S(   s}   Handles the HTTP GET request.

        Interpret all HTTP GET requests as requests for server
        documentation.
        s   Content-Type: text/htmls   Content-Length: %dN(   Rp   Rx   t   syst   stdoutR{   (   R   R|   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt
   handle_get  s
    c         C   s   t  j |  ƒ t j |  ƒ d  S(   N(   R   R^   R[   (   R   (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR^      s    (   R-   RX   RY   RŠ   R^   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyR‡     s   	(    (   RY   R6   R.   R   Rˆ   R    R   R   R   R
   t   HTMLDocR   R[   Rq   R~   R‡   (    (    (    s%   /usr/lib/python2.7/DocXMLRPCServer.pyt   <module>   s   "		oR