
    Dfe                        d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZ ddlmZ g dZ G d d          Zd Z G d de          ZeZ  G d de          Z!d Z"d Z#ddZ$ G d d          Z%e&dk    rddl'Z' e'j(                     dS dS )z
Web application
(from web.py)
    N)isclass)BytesIO   )browser
httpserverutils)webapi)wsgi)
debugerror)	iteritems)lstrips)urlparse	urlencodeunquote)reload)applicationauto_applicationsubdir_applicationsubdomain_applicationloadhook
unloadhookautodelegatec                       e Zd ZdZdi dfdZd Zd Zd Zd Zd	 Z	d
 Z
	 	 	 	 	 	 ddZd Zd Zd Zd Zd Zd Zd Zd Zd Zg fdZd Zd Zd Zd Zd ZdS ) r   a  
    Application to delegate requests based on path.

        >>> urls = ("/hello", "hello")
        >>> app = application(urls, globals())
        >>> class hello:
        ...     def GET(self): return "hello"
        >>>
        >>> app.request("/hello").data
        'hello'
     Nc                     | t           j                            dd          }                     |           | _        g  _                             t           j                                                  t           j
                             |rd fd}t          j        ||           ||           fd}                     t          t                                           r.r, |                                  t          |                                  r;dt          j        v r/	 t!                                  d S # t"          $ r Y d S w xY wd S d S d S )NdebugFc                      t           j        d         } t          | dd           }|oAt          j                            t          j                            |                    d         S )N__main____file__r   )sysmodulesgetattrospathsplitextbasename)modfiles     >/var/www/media/lib/python3.11/site-packages/web/application.pymain_module_namez.application.__init__.<locals>.main_module_name@   sV    k*-T  K 0 01A1A$1G1G H H KK    c                     |                      d          |                      d          }}||dS |dk    r
             }|S )z(find name of the module name from fvars.r   __name__Nr   )get)fvarsr(   namer*   s      r)   modnamez%application.__init__.<locals>.modnameG   sR    "YYz22EIIj4I4Id<4<4:%% ,+--Dr+   c                      t          dddg          } t          | d          }|r#| j        _                            |           dS dS )z%loadhook to reload mapping and fvars.N )
__import__r"   __dict__r/   init_mapping)r'   mappingmapping_namemodule_nameselfs     r)   reload_mappingz,application.__init__.<locals>.reload_mappingV   s^     dD2$??!#|T:: /!$DJ%%g...../ /r+   r   )webconfigr.   r6   r/   
processorsadd_processorr   _loadr   _unloadr   dictfindReloaderr    argvr4   ImportError)	r:   r7   r/   
autoreloadr1   r;   r*   r8   r9   s	   `     @@@r)   __init__zapplication.__init__4   s   77J'"""
8DJ//000:dl33444 .	L L L
 
 
 
 
 !>%99L!'%..K/ / / / / / / x

33444 = =    ""8N#;#;<<<  !! jCH&<&<//1122222"   DD[.	 .	T &<&<s    E 
E'&E'c                 N    t           j        j                            |            d S N)r<   ctx	app_stackappendr:   s    r)   r@   zapplication._loadn   s!      &&&&&r+   c                 r   t           j        j        d d         t           j        _        t           j        j        r{t           j                            d          }|r\|j        t           j        _        |j        t           j        _        |j        t           j        _        |j        t           j        _        d S d S d S )N_oldctx)r<   rJ   rK   r.   homehomepathr$   fullpath)r:   oldctxs     r)   rA   zapplication._unloadq   s    G-crc27 	3W[[++F 3%{#)? %{#)?   	3 	33 3r+   c                 B    t           j                                         d S rI   )r   ThreadedDict	clear_allrM   s    r)   _cleanupzapplication._cleanup}   s     	$$&&&&&r+   c                 T    t          t          j        |d                    | _        d S )N   )listr   groupr7   )r:   r7   s     r)   r6   zapplication.init_mapping   s!    EK3344r+   c                 >    | j                             ||f           d S rI   )r7   rL   )r:   pattern	classnames      r)   add_mappingzapplication.add_mapping   s#    Wi011111r+   c                 :    | j                             |           dS )a  
        Adds a processor to the application.

            >>> urls = ("/(.*)", "echo")
            >>> app = application(urls, globals())
            >>> class echo:
            ...     def GET(self, name): return name
            ...
            >>>
            >>> def hello(handler): return "hello, " +  handler()
            ...
            >>> app.add_processor(hello)
            >>> app.request("/web.py").data
            'hello, web.py'
        N)r>   rL   )r:   	processors     r)   r?   zapplication.add_processor   s     " 	y)))))r+   /GET0.0.0.0:8080Fc           
      (   t          |          }|j        }	|j        }
|
pd}d|v r	|d         }ni }t          ||||	|t	          |                    }|pi }|                                D ]3\  }}||d|                                                    dd          z   <   4d|v r|                    d          |d<   d	|v r|                    d	          |d
<   |dvrf|pd}t          |t                    rt          |          }n|}t          |                    d                    |d<   d|vrt          |          |d<   t          j                    fd} |                                 ||          }d                    |          _        S )a  Makes request to this application for the specified path and method.
        Response will be a storage object with data, status and headers.

            >>> urls = ("/hello", "hello")
            >>> app = application(urls, globals())
            >>> class hello:
            ...     def GET(self):
            ...         web.header('Content-Type', 'text/plain')
            ...         return "hello"
            ...
            >>> response = app.request("/hello")
            >>> response.data
            'hello'
            >>> response.status
            '200 OK'
            >>> response.headers['Content-Type']
            'text/plain'

        To use https, use https=True.

            >>> urls = ("/redirect", "redirect")
            >>> app = application(urls, globals())
            >>> class redirect:
            ...     def GET(self): raise web.seeother("/foo")
            ...
            >>> response = app.request("/redirect")
            >>> response.headers['Location']
            'http://0.0.0.0:8080/foo'
            >>> response = app.request("/redirect", https=True)
            >>> response.headers['Location']
            'https://0.0.0.0:8080/foo'

        The headers argument specifies HTTP headers as a mapping object
        such as a dict.

            >>> urls = ('/ua', 'uaprinter')
            >>> class uaprinter:
            ...     def GET(self):
            ...         return 'your user-agent is ' + web.ctx.env['HTTP_USER_AGENT']
            ...
            >>> app = application(urls, globals())
            >>> app.request('/ua', headers = {
            ...      'User-Agent': 'a small jumping bean/1.0 (compatible)'
            ... }).data
            'your user-agent is a small jumping bean/1.0 (compatible)'

        r3   env)	HTTP_HOSTREQUEST_METHOD	PATH_INFOQUERY_STRINGHTTPSHTTP_-_HTTP_CONTENT_LENGTHCONTENT_LENGTHHTTP_CONTENT_TYPECONTENT_TYPE)HEADrd   utf-8z
wsgi.inputc                 L    | _         t          |          _        |_        d S rI   )statusdictheadersheader_items)rw   ry   responses     r)   start_responsez+application.request.<locals>.start_response  s&    $HO#G}}H$+H!!!r+   r+   )r   r$   queryrx   stritemsupperreplacepop
isinstancer   r   encodelenr<   storagewsgifuncjoindata)r:   	localpartmethodr   hostry   httpskw_pr$   maybe_queryr}   rg   kvqr|   r{   s                    @r)   requestzapplication.request   s   v i  wh!rB;;U)CCC!e**
 
 
 -RMMOO 	; 	;DAq9:C!''))++C55566 C''$'GG,A$B$BC !#%%"%''*=">">C((:2D$%% dOO '(9(9 : :Cs**(+A$%;==	, 	, 	, 	, 	,
 t}}sN33r+   c                 *    t          j        |           S rI   )r   
AppBrowserrM   s    r)   r   zapplication.browser
  s    !$'''r+   c                     |                      | j        t          j        j                  \  }}|                     || j        |          S rI   )_matchr7   r<   rJ   r$   	_delegater/   )r:   fnargss      r)   handlezapplication.handle  s7    ;;t|SW\::D~~b$*d333r+   c                 2      fd  j                   S )Nc                 B    	  r" d          dd          c}  | fd          S                                  S # t          j        $ r  t          t          f$ r   t          t          j                    t          j                   	                                xY w)Nr   r   c                                  S rI   r   )processr>   s   r)   <lambda>zEapplication.handle_with_processors.<locals>.process.<locals>.<lambda>  s    WWZ%8%8 r+   )r(   )
r   r<   	HTTPErrorKeyboardInterrupt
SystemExitprint	traceback
format_excr   internalerror)r>   pr   r:   s   ` r)   r   z3application.handle_with_processors.<locals>.process  s    + )$.qM:abb>MAz188888999;;==(=   %z2   +i*,,39====((***s   #< < A"B)r>   )r:   r   s   `@r)   handle_with_processorsz"application.handle_with_processors  s6    	+ 	+ 	+ 	+ 	+ 	+  wt'''r+   c                 <     d  fd}|D ]} ||          }|S )z8Returns a WSGI-compatible function for this application.c                 t    	 t          |           }n# t          $ r d}Y nw xY wt          j        |g|           S )ziPeeps into an iterator by doing an iteration
            and returns an equivalent iterator.
            r3   )nextStopIteration	itertoolschain)iterator
firstchunks     r)   peepz"application.wsgifunc.<locals>.peep'  sN     !(^^

       


  ?J<:::s    !!c                 Z   	                                  	                    |            	 t          j        j                                        t          j        j        k    rt          j                    	                                }|rt          |d          r |          }n|g}n$# t          j	        $ r}|j
        g}Y d }~nd }~ww xY wd } ||          }t          j        j        t          j        j        }} |||           	fd}t          j        | |                      S )N__next__c              3      K   | D ]@}t          |t                    r|V  t          |                              d          V  Ad S )Nru   )r   bytesr~   r   )resultrs     r)   build_resultz8application.wsgifunc.<locals>.wsgi.<locals>.build_resultG  s]       5 5A!!U++ 5!!ffmmG444444	5 5r+   c               3   <   K                                      dV  d S )Nr+   )rX   rM   s   r)   cleanupz3application.wsgifunc.<locals>.wsgi.<locals>.cleanupS  s!      					r+   )rX   loadr<   rJ   r   r   nomethodr   hasattrr   r   rw   ry   r   r   )
rg   
start_respr   er   rw   ry   r   r   r:   s
           r)   r
   z"application.wsgifunc.<locals>.wsgi5  s:   MMOOOIIcNNN"7>''))SW^;;,..(4466 &gfj99 &!T&\\FF$XF= " " "&"5 5 5 "\&))F!gncgoGFJvw'''     ?67799555s   A>B+ +C:CCr   )r:   
middlewarer
   mr   s   `   @r)   r   zapplication.wsgifunc$  sW    	; 	; 	;"	6 "	6 "	6 "	6 "	6 "	6H  	 	A1T77DDr+   c                 :    t          j         | j        |           S )a  
        Starts handling requests. If called in a CGI or FastCGI context, it will follow
        that protocol. If called from the command line, it will start an HTTP
        server on the port named in the first command line argument, or, if there
        is no argument, on port 8080.

        `middleware` is a list of WSGI middleware which is applied to the resulting WSGI
        function.
        )r
   runwsgir   )r:   r   s     r)   runzapplication.run^  s     |MDM:6777r+   c                 v    t           j        r,t           j                                         dt           _        dS dS )z%Stops the http server started by run.N)r   serverstoprM   s    r)   r   zapplication.stopj  s:     	%""$$$ $J	% 	%r+   c                      | j         | }	 ddlm}  ||          S # t          $ r4 t          j                                                            |          cY S w xY w)z
        Return a CGI handler. This is mostly useful with Google App Engine.
        There you can just do:

            main = app.cgirun()
        r   run_wsgi_app)r    google.appengine.ext.webapp.utilr   rE   wsgirefhandlers
CGIHandlerr   )r:   r   wsgiappr   s       r)   cgirunzapplication.cgirunp  s}      $-,	>EEEEEE<((( 	> 	> 	>#..0044W=====	>s    ;AAc                 h    | j         | }	 t          j        dd         }|d         }|d         }|dk    rt          d          |dk    r|S |dk    rddlm}  ||          S t          d	          # t          $ r4 t          j        	                                
                    |          cY S w xY w)
aI  
        Starts the program in a way that will work with Google app engine,
        no matter which version you are using (2.5 / 2.7)

        If it is 2.5, just normally start it with app.gaerun()

        If it is 2.7, make sure to change the app.yaml handler to point to the
        global variable that contains the result of app.gaerun()

        For example:

        in app.yaml (where code.py is where the main code is located)

            handlers:
            - url: /.*
              script: code.app

        Make sure that the app variable is globally accessible
        NrZ   r   r   z2Google App Engine only supports python 2.5 and 2.7      r   z/Not a supported platform, use python 2.5 or 2.7)r   r    version_infoEnvironmentErrorr   r   rE   r   r   r   r   )r:   r   r   versionmajorminorr   s          r)   gaerunzapplication.gaerun  s    (  $-,	>&rr*GAJEAJEzz&H  
 zz!IIIIII#|G,,,&E    	> 	> 	>#..0044W=====	>s   A A3 A3 $A3 3;B10B1c                     t           j        }|                                 d|_        g |_        d|_        |x|_        |_        |                    d          |_	        |                    d          dv r|d         |_
        n9|                    dd                                          dv rd|_
        nd	|_
        |j
        d
z   |                    dd          z   |_        t          j                            d|                    dd                    |_        |j        |j        z   |_        |j        |_        |                    d          |_        |                    d          |_        	 t'          |                    d          d                              d          |_        n*# t,          $ r |                    d          |_        Y nw xY w|                    dd                              d          r_t1          |                    d                              d          d         |j                  |_        t5          |j                  |_        |                    d          rd|                    dd          z   |_        nd|_        |j        |j        z   |_        t;          |          D ]3\  }}t=          |t&                    r|                    dd          ||<   4d|_        g |_        dS )zInitializes ctx using env.z200 OKr3   rh   zwsgi.url_scheme)httpr   rl   )ontrue1r   r   z://z	[unknown]REAL_SCRIPT_NAMESCRIPT_NAMEREMOTE_ADDRri   rj   latin1utf8SERVER_SOFTWARE)z	lighttpd/znginx/REQUEST_URI?r   rk   ru   r   N) r<   rJ   clearrw   ry   outputenvironrg   r.   r   protocollower
homedomainr#   rR   rQ   realhomeipr   r   decoder$   UnicodeDecodeError
startswithr   splitr   r}   rS   r   r   rK   )r:   rg   rJ   r   r   s        r)   r   zapplication.load  s   g		

 ##cg77;''77$%%):::01CLLWWWb!!''))-@@@"CLL!CL-[0Q0QQz~~&8#''-QS:T:TUU>CL0 x''WW-..
	,SWW[118<<CCFKKCHH! 	, 	, 	,ww{++CHHH	, 77$b))445LMM 	)sww}55;;C@@CS\RRCH sx((CH77>"" 	cggnb999CIICIx#)+cNN 	6 	6DAq !U## 6'955A 
s   0;F, ,$GGc                    fd}|t          j                    t          |t                    r|                                S t          |          r ||          S t          |t                    r|                    d          rt|                    dd          d         }t           j	        j
        dk    r/t           j	        j                            dd          }|r|d|z   z  }t          j        |          d	|v r=|                    d	d          \  }}t          |d d dg          }t!          ||          }n||         } ||          S t#          |d
          r
 |            S t          j                    S )Nc                     t           j        j        }|dk    rt          | |          sd}t          | |          st          j        |           t           |             |          } | S )Nrt   rd   )r<   rJ   r   r   r   r"   )clsmethtocallr   s      r)   handle_classz+application._delegate.<locals>.handle_class  sk    7>Dv~~gc4&8&8~3%% (l3'''SSUUD))F64= r+   z	redirect  r   rd   rk   r3   r   .__call__)r<   notfoundr   r   r   r   r~   r   r   rJ   r   rg   r.   redirectrsplitr4   r"   r   )	r:   fr/   r   r   urlxr'   r   s	      `     r)   r   zapplication._delegate  s~   	! 	! 	! 	! 	! 9,.. ;'' 	"++---QZZ 	"<??"3 	"||K(( ggc1ooa(7>U**;;A 'sQwl3'''88C++S dD2$77c3''Ah<$$$Q
## 	"133J<>>!r+   c                     |D ]\  t          t                    r#|                              r fd}|d fc S =t          t                    rt	          j        dd|          \  }n+t	          j        dd                              |          }|r"d |                                D             fc S dS )Nc                  0                                    S rI   )_delegate_sub_application)patr:   whats   r)   r   z$application._match.<locals>.<lambda>  s     > >sD I I r+   ^z\Zc                     g | ]}|S r   r   .0r  s     r)   
<listcomp>z&application._match.<locals>.<listcomp>      999Aa999r+   NN)	r   r   r   r~   r   re_subm
re_compilematchgroups)r:   r7   valuer  r   r  r  s   `    @@r)   r   zapplication._match  s      	: 	:IC$,, 	J##C(( IIIIIIAd7NNND#&& J$}}->eLLff))ccc*;<<BB5II :999999999:zr+   c                    t          j        t           j                  t           j        _        t           j        xj        |z  c_        t           j        xj        |z  c_        t           j        j        t          |          d         t           j        _        t           j        j        t          |          d         t           j        _        |	                                S )a  Deletes request to sub application `app` rooted at the directory `dir`.
        The home, homepath, path and fullpath values in web.ctx are updated to mimic request
        to the subapp and are restored after it is handled.

        @@Any issues with when used with yield?
        N)
r<   r   rJ   rP   rQ   rR   r$   r   rS   r   )r:   dirapps      r)   r  z%application._delegate_sub_application  s     +cg..Cw|CHHJJ/7+CHHJJ7))+++r+   c                     | t           j        j        v rDt           j        j                            |           }|dk    rt           j        j        |dz
           S d S d S )Nr   r   )r<   rJ   rK   index)r:   r  s     r)   get_parent_appzapplication.get_parent_app*  sT    37$$$G%++D11Eqyyw(33 %$yr+   c                 |    |                                  }|r|                                S t          j                    S )z.Returns HTTPError with '404 not found' message)r  r   r<   	_NotFoundr:   parents     r)   r   zapplication.notfound0  s7    $$&& 	#??$$$=??"r+   c                     |                                  }|r|                                S t          j                            d          rt                      S t          j                    S )z3Returns HTTPError with '500 internal error' messager   )r  r   r<   r=   r.   r   _InternalErrorr  s     r)   r   zapplication.internalerror8  s\    $$&& 	('')))Z^^G$$ 	(<<%'''r+   )rc   rd   Nre   NF)r-   
__module____qualname____doc__rG   r@   rA   rX   r6   r`   r?   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r   r+   r)   r   r   %   s       
 
  " 8 8 8 8t' ' '
3 
3 
3' ' '
5 5 52 2 2* * ** m m m m^( ( (4 4 4( ( (&8 8 8t
8 
8 
8% % %> > >"-> -> ->^5 5 5n (* "" "" "" ""H  ", , ,4 4 4# # #( ( ( ( (r+   r   c                       fd}|S )Nc                     t          |                                           }|                    dd            |                    dd             | j        | j        |          S )Nr5   __weakref__)varscopyr   r-   	__bases__)r   bodymclss     r)   	decoratorz!with_metaclass.<locals>.decoratorD  sX    Cyy~~T"""%%%tCL#-666r+   r   )r+  r,  s   ` r)   with_metaclassr-  C  s$    7 7 7 7 7 r+   c                       e Zd ZdZd ZdS )r   a  Application similar to `application` but urls are constructed
    automatically using metaclass.

        >>> app = auto_application()
        >>> class hello(app.page):
        ...     def GET(self): return "hello, world"
        ...
        >>> class foo(app.page):
        ...     path = '/foo/.*'
        ...     def GET(self): return "foo"
        >>> app.request("/hello").data
        'hello, world'
        >>> app.request('/foo/bar').data
        'foo'
    c                      t                                            G  fddt                    }t          |           G d d                      }| _        d S )Nc                       e Zd Z fdZdS )+auto_application.__init__.<locals>.metapagec                     t                               | |||           |                    dd|z             }|                    ||            d S d S )Nr$   rc   )typerG   r.   r`   )klassr0   basesattrsr$   r:   s        r)   rG   z4auto_application.__init__.<locals>.metapage.__init__f  s^    eT5%888yyt44 #$$T511111 $#r+   N)r-   r!  r"  rG   rM   s   r)   metapager1  e  s.        2 2 2 2 2 2 2r+   r7  c                       e Zd ZdZdS )'auto_application.__init__.<locals>.pageN)r-   r!  r"  r$   r   r+   r)   pager9  o  s        DDDr+   r:  )r   rG   r3  r-  r:  )r:   r7  r:  s   `  r)   rG   zauto_application.__init__b  s    T"""	2 	2 	2 	2 	2 	2 	2t 	2 	2 	2 
	!	!	 	 	 	 	 	 	 
"	!	 			r+   N)r-   r!  r"  r#  rG   r   r+   r)   r   r   N  s-         &    r+   r   c                       e Zd ZdZd Zd ZdS )r   aM  
    Application to delegate requests based on the host.

        >>> urls = ("/hello", "hello")
        >>> app = application(urls, globals())
        >>> class hello:
        ...     def GET(self): return "hello"
        >>>
        >>> mapping = (r"hello\.example\.com", app)
        >>> app2 = subdomain_application(mapping)
        >>> app2.request("/hello", host="hello.example.com").data
        'hello'
        >>> response = app2.request("/hello", host="something.example.com")
        >>> response.status
        '404 Not Found'
        >>> response.data
        'not found'
    c                     t           j        j                            d          d         }|                     | j        |          \  }}|                     || j        |          S )N:r   )r<   rJ   r   r   r   r7   r   r/   )r:   r   r   r   s       r)   r   zsubdomain_application.handle  sO    w|!!#&&q);;t|T22D~~b$*d333r+   c                 "   |D ]\  }}t          |t                    r t          j        d|z   dz   ||          \  }}n-t          j        d|z   dz                                 |          }|r"|d |                                D             fc S dS )Nr	  $c                     g | ]}|S r   r   r  s     r)   r  z0subdomain_application._match.<locals>.<listcomp>  r  r+   r  )r   r~   r   r  r  r  r  )r:   r7   r  r  r  r   s         r)   r   zsubdomain_application._match  s      	: 	:IC$$$ H$}S3Y_dEJJff)#)c/::@@GG :999999999:zr+   N)r-   r!  r"  r#  r   r   r   r+   r)   r   r   z  s<         ,4 4 4
	 	 	 	 	r+   r   c                       fd}|S )z
    Converts a load hook into an application processor.

        >>> app = auto_application()
        >>> def f(): "something done before handling request"
        ...
        >>> app.add_processor(loadhook(f))
    c                 ,                   |             S rI   r   )handlerhs    r)   rb   zloadhook.<locals>.processor  s    	wyyr+   r   )rD  rb   s   ` r)   r   r     s$         r+   c                        fd} fd|S )z
    Converts an unload hook into an application processor.

        >>> app = auto_application()
        >>> def f(): "something done after handling request"
        ...
        >>> app.add_processor(unloadhook(f))
    c                     	  |             }n#                 xY w|rt          |d          r |          S               |S )Nr   )r   )rC  r   rD  wraps     r)   rb   zunloadhook.<locals>.processor  sc    	WYYFF	ACCC 	gfj11 	4<<ACCCMs   
 c              3   v    K    fd}t                      	 	  |            V  n# t          $ r Y d S w xY w )Nc                  D    	 t                    S #                  xY wrI   )r   )rD  r   s   r)   	next_hookz+unloadhook.<locals>.wrap.<locals>.next_hook  s+    F||#s    )iterr   )r   rJ  rD  s   ` r)   rG  zunloadhook.<locals>.wrap  sy      	 	 	 	 	 	 f	ikk!!!!    	s   ) 
77r   )rD  rb   rG  s   ` @r)   r   r     sC               r+   r3   c                       fd}|S )a0  
    Returns a method that takes one argument and calls the method named prefix+arg,
    calling `notfound()` if there isn't one. Example:

        urls = ('/prefs/(.*)', 'prefs')

        class prefs:
            GET = autodelegate('GET_')
            def GET_password(self): pass
            def GET_privacy(self): pass

    `GET_password` would get called for `/prefs/password` while `GET_privacy` for
    `GET_privacy` gets called for `/prefs/privacy`.

    If a user visits `/prefs/password/change` then `GET_password(self, '/change')`
    is called.
    c                    d|v r%|                     dd          \  }}|z   }d|z   g}n|z   }g }t          | |          r5	  t          | |          | S # t          $ r t	          j                    w xY wt	          j                    )Nrc   r   )r   r   r"   	TypeErrorr<   r   )r:   argfirstrestfuncr   prefixs         r)   internalzautodelegate.<locals>.internal  s    #::))C++KE4E>D$J<DDC<DD4 	!%*wtT**D11 % % %lnn$% ,.. s   A A4r   )rS  rT  s   ` r)   r   r     s#    &! ! ! ! !" Or+   c                   d    e Zd ZdZ	 ej                            d          rdZndZd Zd Z	d Z
dS )	rC   z[Checks to see if any loaded modules have changed on disk and,
    if so, reloads them.
    javaz	$py.classz.pycc                     i | _         d S rI   )mtimesrM   s    r)   rG   zReloader.__init__  s    r+   c                     t          t          j                                                  }|D ]}|                     |           d S rI   )r[   r    r!   valuescheck)r:   sys_modulesr'   s      r)   r   zReloader.__call__  sG    3;--//00 	 	CJJsOOOO	 	r+   c                 Z   |rt          |d          r|j        sd S 	 t          j        |j                  j        }n# t
          t          f$ r Y d S w xY w|j                            | j        j	                  r`t          j
                            |j        d d                   r4t          t          j        |j        d d                   j        |          }|| j        vr|| j        |<   d S | j        |         |k     r-	 t          |           || j        |<   d S # t          $ r Y d S w xY wd S )Nr   rO   )r   r   r#   statst_mtimeOSErrorIOErrorendswith	__class__SUFFIXr$   existsmaxrX  r   rE   )r:   r'   mtimes      r)   r[  zReloader.check  sW     	Z00 	S\ 	F	GCL))2EE! 	 	 	FF	<  !677 	DBGNNL"=
 =
 	D SbS 122;UCCEdk!!$DK[%%s#(C      	 &%s!   < AA?D 
D('D(N)r-   r!  r"  r#  r    platformr   rd  rG   r   r[  r   r+   r)   rC   rC     st          +
|v&&     
    r+   rC   r   )r3   ))r#  r   r#   r    r   wsgiref.handlersr   inspectr   ior   r3   r   r   r   r	   r<   r
   r   
py3helpersr   r   urllib.parser   r   r   	importlibr   __all__r   r-  r   r   r   r   r   r   rC   r-   doctesttestmodr   r+   r)   <module>rr     sS   
     				 



                     ( ( ( ( ( ( ( ( ( (             " " " " " " ! ! ! ! ! !       5 5 5 5 5 5 5 5 5 5        [( [( [( [( [( [( [( [(|  % % % % %{ % % %R ! % % % % %K % % %P  "( ( (V$ $ $ $N) ) ) ) ) ) ) )X zNNNGO r+   