Ńņ
ė{½Jc           @   s;  d  Z  d d d d d d d d d	 g	 Z d
 d k Z d
 d k Z d
 d k Z d
 d k Z d
 d k Z d
 d k Z d
 d k Z d
 d k	 l
 Z
 l Z d
 d k Z d
 d k Z d
 d k l Z l Z l Z d
 d k l Z l Z d
 d k l Z e i d  d
 d k l Z l Z l Z l Z d
 d k l Z l Z d
 d k l  Z  l! Z! l" Z" d a$ g  Z% g  Z& d a' e i( d  Z) d   Z* e* e i+ i, _* e i- Z. d d  Z- e- e _- d d  Z/ d   Z0 d   Z1 d   Z2 d   Z3 d e f d     YZ4 e1 e i5 j o e i5 i6 e1  n e2 e i7 j o e i7 i6 e2  n d S(   s3   Things to do when the TurboGears server is started.t   call_on_startupt   call_on_shutdownt   reloader_threadt   start_bonjourt   stop_bonjourt   start_servert   startTurboGearst   stopTurboGearst   webpathi’’’’N(   t   abspatht   exists(   t   _cputilt   requestt   server(   t   wsgiAppt   CPHTTPRequest(   t   CherryPyWSGIServert
   TurboGears(   t   configt   databaset	   schedulert   view(   t   hub_registryt   EndTransactionsFilter(   t   NestedVariablesFiltert   SafeMultipartFiltert   VirtualPathFiltert    s   turbogears.startupc            sü  d   } h  } t  i d d      d j o
 d GHd Sx½t i i i o¬  oM t   f d   t i	 i
    } g  } | D] } | t i	 | q~ ~ } n t | t i	 i    } x,t d   t d   |   D]} | i d  p | d	 j o qÖ n | } | i d
  o | d  } n y t i |  i }	 Wne t j
 oY }
 | i d
  o3 |
 d t i j o y t i |  WqqXn t i d  n X| | j o |	 | | <qÖ n |	 | | j o t i d  qÖ qÖ Wt i |   q; Wd S(   s÷   Monkeypatch for the reloader provided by CherryPy.

    This reloader is designed to reload a single package. This is
    more efficient and, more important, compatible with zipped
    libraries that may not provide access to the individual files.c         S   s6   t  |  d  o" t  |  i d  o |  i i Sn |  S(   Nt
   __loader__t   archive(   t   hasattrR   R   (   t   module(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyt   archive_selector7   s    s   autoreload.packagesĶ   TurboGears requires autoreload.package to be set. It can be an empty value, which will use CherryPy's default behavior which is to check every module. Setting an actual package makes the check much faster.Nc            s   |  i     S(    (   t
   startswith(   t   modname(   t   package(    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyt   <lambda>G   s    c         S   s   |  S(    (    (   t   v(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR$   L   s    c         S   s   t  |  d  d  S(   t   __file__N(   t   getattrt   None(   t   m(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR$   M   s    s   .kids   <string>s   .pyci’’’’i    i   (   R   t   getR(   t   cherrypyt   libt
   autoreloadt   RUN_RELOADERt   filtert   syst   modulest   keyst   mapt   valuest   endswitht   ost   statt   st_mtimet   OSErrort   errnot   ENOENTt   unlinkt   exitt   timet   sleep(   t   freqR    t   mtimest   modnamest   _[1]R"   t   modlistt   filenamet   orig_filenamet   mtimet   e(    (   R#   sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR   0   sH    	 , $  
c         C   s3   t  |   } y | t _ Wn t j
 o n X| S(   N(   t   old_object_trailR   t   object_trailt   AttributeError(   t   object_patht   trail(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyt   get_object_traili   s    c   	   	   C   s.  t  o d St t d d  p d S|  p# t i i }  |  |  i d   }  n t i d d  } t	 t i d   } t i d  } |  d | } d	 } d
 d | | | | g g d d | | d | | d g g g } xR | D]J \ } } t
 |  o1 t i t i | | g |  a  t i t  PqÜ qÜ Wd S(   sÖ   Register the TurboGears server with the Bonjour framework.

    Currently only Unix-like systems are supported where either the 'avahi'
    daemon (Linux etc.) is available or the 'dns-sd' program (Mac OS X).

    Nt   roott   .s   server.socket_hostR   s   server.socket_ports   server.environments   : s
   _http._tcps   /usr/bin/avahi-publish-services   -Hs   /usr/bin/dns-sds   -Rs   path=/(   t
   DNS_SD_PIDR'   R+   R(   RO   t
   __module__t   findR   R*   t   strR
   R6   t   spawnvt   P_NOWAITt   atexitt   registerR   (	   R#   t   hostt   portt   envt   namet   typet   cmdst   cmdt   args(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR   u   s(    % c           C   s=   t  p d Sy t i t  t i  Wn t j
 o n Xd S(   s4   Stop the bonjour publishing daemon if it is running.N(   RQ   R6   t   killt   signalt   SIGTERMR9   (    (    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR      s    c          C   s:  t  i }  t i } t t i  i d d <|  d  pó |  d  ok t i   } | i	 t i
  t i d  } t i t i  } | i	 t i
  | i |  | i |  n |  d  } | od t i d  } d | _ t i d	  } t i |  } | i	 t i  | i |  | i |  q&n t  i h h t d
 6t | t d   d 6t d 6d 6 t  i h h t d
 6t | t d   d 6t d 6d 6 |  d d d d# j o/ t  i h h t d 6|  d d  d 6d 6 n t i   t i   |  d  p d a t t d d#  o© t t i d  p g  t i _  n t! t  t"   t#   t$   g } xK t i i  D]< } x3 | D]+ } | i% | i% j o | i& |  PqwqwWqjWt i i  i' |  n t i( d  a t o t i) d  o t d 7a n |  d d#  }	 |	 p |  d  d j o t* |	  n |  d  o t+ i,   n t i- d  }
 x |
 D] } y | i.   } Wn+ t/ j
 o } t0 i1 d | |  q^n Xt | d  o= y | i2   Wqļt/ j
 o } t0 i1 d  | |  qļXq^q^Wx t3 D] } |   qśW|  d! t  o t4 i5   t0 i6 d"  n d# S($   s¹  Handles TurboGears tasks when the CherryPy server starts.

    This performs the following initialization tasks (in given order):

    * Adds a static filter for TurboGears's static files (URL '/tg_static').
    * Adds a static filter for TurboGears's JavaScript files (URL '/tg_js').
    * Adds the decoding filter to the root URL ('/') if enabled in the
      configuration.
    * Loads the template engines and the base templates.
    * Adds the CherryPy request filters to the root controller.
    * Turns off CherryPy's logging filter when in development mode and turns on
      stdlib logging.
    * Registers the server with the Bonjour framework, if available.
    * Calls 'turbogears.database.bind_metadata' when using SQLAlchemy.
    * Loads all turbogears.extensions entry points and calls their
      'start_extension' method.
    * Calls the callables registered in 'turbogears.call_on_startup'.
    * Starts the TurboGears scheduler.

    t   developments   log_debug_info_filter.ons   tg.new_style_loggings   server.log_to_screens.   %(asctime)s %(name)s %(levelname)s %(message)ss   server.log_files   turbogears.accessi    s   %(message)ss   static_filter.ont   statics   static_filter.dirs
   /tg_statics	   static/jss   /tg_jss   decoding_filter.ont   patht   /s   kid.encodingt   utf8s   decoding_filter.encodings   server.webpathR   RO   t   _cp_filterss
   tg.bonjours   server.environments   sqlalchemy.dburis   turbogears.extensionss2   Error loading TurboGears extension plugin '%s': %st   start_extensions,   Error starting TurboGears extension '%s': %ss   tg.schedulers   Scheduler startedN(7   R   R*   t   pkg_resourcest   resource_filenamet   FalseR+   t   environmentst   loggingt	   getLoggert   setLevelt   DEBUGt	   Formattert   StreamHandlerR0   t   stdoutt   setFormattert
   addHandlert	   propagatet   FileHandlert   INFOt   updatet   TrueR	   t   __name__R(   R   t   load_enginest   loadBaseTemplatesR   R'   R   RO   Ri   R   R   R   R   t	   __class__t   removet   extendt   lstripR5   R   R   t   bind_metadatat   iter_entry_pointst   loadt	   Exceptiont   logt   errorRj   R    R   t   _start_schedulert   info(   t   conft   rfnt   setuplogt   fmtt   handlert   logfilet   extra_filterst	   cp_filtert	   candidatet   bonjoursettingt
   extensionst
   entrypointt   extRH   t   item(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR   ”   s¢    				

	   	
	 
c       	   C   sĄ   x t  D] }  |  i   q Wt  i   t   t i d  } x8 | D]0 } | i   } t | d  o | i   qB qB Wx t	 D] } |   q} Wt
 i d t  o t i   t i d  n d S(   sĒ   Handles TurboGears tasks when the CherryPy server stops.

    Ends all open database transactions, shuts down all extensions, calls user
    provided shutdown functions and stops the scheduler.

    s   turbogears.extensionst   shutdown_extensions   tg.schedulers   Scheduler stoppedN(   R   t   endt   clearR   Rk   R   R   R   R   R   R   R*   Rm   R   t   _stop_schedulerR   R   (   t   hubR   R   R   R   (    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR   #  s"    	 
  
c         C   sA   |  t  _ t i d t  o t i d t    n t i   d  S(   Ns   tg.fancy_exceptionR   (   R+   RO   R   R*   Rm   R   t   startt   SimpleWSGIServer(   RO   (    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR   @  s    	R    c           B   s   e  Z d  Z e Z d   Z RS(   s=   A WSGI server that accepts a WSGI application as a parameter.c         C   sÉ   t  i i } t } | d  d j oW y d d k l } Wn t j
 o q| X| | d h  } t  i i h t d 6 n | d  | d  f } t	 i
 |  | | | d	  | d  d
 | d  d  S(   Ns   server.environmentRd   i’’’’(   t   EvalExceptiont   global_confs   server.throw_errorss   server.socket_hosts   server.socket_ports   server.thread_poolt   request_queue_sizes   server.socket_queue_size(   R+   R   R*   R   t   paste.evalexception.middlewareR”   t   ImportErrorR{   R|   R   t   __init__(   t   selfR   t   wsgi_appR”   t	   bind_addr(    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR¦   L  s    (   R}   RR   t   __doc__R   t   RequestHandlerClassR¦   (    (    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyR    H  s   (8   RŖ   t   __all__RW   R:   Ro   R6   R0   Rb   R>   t   os.pathR	   R
   Rk   R+   R   R   R   t   cherrypy._cpwsgiR   R   t   cherrypy._cpwsgiserverR   t   requiret
   turbogearsR   R   R   R   t   turbogears.databaseR   R   t   turbogears.filtersR   R   R   R(   RQ   R    R   R   Rp   R   R   R,   R-   RN   RI   R   R   R   R   R   R    t   on_start_server_listt   appendt   on_stop_server_list(    (    (    sp   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/startup.pyt   <module>   s\   	"	4		#					