
˥WJc           @   sE  d  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 Z d d k l	 Z
 l Z l Z d d k l Z d d k l Z d d k l Z l Z d d k Z d d k l Z l Z l Z l Z d d k l Z d d	 k l Z l Z d d
 k  l! Z! d d k" l# Z# d d k$ l% Z% d d k& l' Z' e i( e)  Z* d Z+ d   Z, d e f d     YZ- d e- f d     YZ. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d e- f d     YZ4 d e. f d     YZ5 d e5 f d     YZ6 d   Z	 d    Z7 d!   Z8 d"   Z9 d d d d# d$ d g Z: d S(%   s<  
Controller Classes, dispatch methods and helper functions for controller operation.

This module contains the main classes which describe Turbogears2 Controllers.
These Controllers are handled by the Dispatch functions which are also provided here.

Lastly, url definition and browser redirection are defined here.
iN(   t   urlt   configt   request(   t   WSGIController(   t   abort(   t   NotAuthorizedErrort   not_anonymous(   t	   HTTPFoundt   HTTPNotFoundt   HTTPExceptiont   HTTPClientError(   t   render(   t   exposet
   allow_only(   t
   setup_i18n(   t   flash(   t   Request(   t   HTTPUnauthorizeds   CUSTOM/LEAVEc          C   s6   t  i i   }  t |  d  p t   |  _ n |  i S(   s   
    Returns a set containing the names of the currently configured template
    engines from the active application's globals
    t   tg_configured_engines(   t   pylonst   app_globalst   _current_objt   hasattrt   setR   (   t   g(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   _configured_engines*   s    t   DecoratedControllerc           B   sb   e  Z d  Z d   Z d   Z d   Z d   Z d
 d  Z d   Z	 d   Z
 d   Z d	   Z RS(   s&  
    DecoratedController takes action on the decorated controller methods
    created by the decorators in tg.decorators.

    The decorators in tg.decorators create an attribute named 'decoration' on
    the controller method, creating rules as to:

    1) how to validate the request,
    2) how to render the response,
    3) allowing hooks to be registered to happen:

        a) before validation
        b) before the controller method is called
        c) before the rendering takes place, and
        d) after the rendering has happened.
    c         O   s\   t  |  d  o/ |  i d  j	 o |  i } t |  |   }  n t t |   i | |   d  S(   NR   (   R   R   t   Nonet   superR   t   __init__(   t   selft   argst   kwargst	   predicate(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   G   s     	c         O   s   d S(   s  
        Override this method to define any action you would like taken
        before the controller code is executed.  This is particularly useful
        for defining a Controller-wide specification (all methods) for things like:
        setting up variables/objects in the template context,
        restricting access, or other tasks which should be executed
        before the controller method is called.
        N(    (   R   R   t   kw(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt
   __before__O   s    c         O   s   d S(   s  Override this method to define what you would like to run after the
        template has been rendered. This method will
        always be run after your method, even if it raises an Exception or redirects.

        An example use-case would be a runtime-specific template change,
        you where would want to change the template back to the originally
        decorated template after you have temporarily changed it.
        N(    (   R   R   R"   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt	   __after__Y   s    c         C   s{   y |  i  i } Wn# t j
 o h  |  i  _ } n Xy | | i } Wn- t j
 o! t i |  } | | i <n X| S(   N(   t	   __class__t   _cached_argspecst   AttributeErrort   im_funct   KeyErrort   inspectt
   getargspec(   R   t   funct   cached_argspecst   argspec(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   _get_argspecb   s    c         C   sf  |  i    |  i t i _ | p g  } yd | j o | d t i i d <n | i i d | |  x5 t i d g   D]! } | i |  o | | =qw qw W| i	   } |  i
 |  } | d d } | oT t |  oG xD t |  D]2 \ } }	 | t |  j o Pn | | | |	 <q Wn |  i | |  } | t i _ | i i d | |  | d d } | oi xf t |  D]T \ } }	 | t |  j o Pn | | }
 |
 | j o | |
 | | <| |
 =qvqvWn | | t |    } Wn9 t i i j
 o' } |  i | | | |  \ } } n X| i i d | | |  |  i | |  } | i i d |  | S(	   s  
        _perform_call is called by _inspect_call in Pylons' WSGIController.

        Any of the before_validate hook, the validation, the before_call hook,
        and the controller method can return a FormEncode Invalid exception,
        which will give the validation error handler the opportunity to provide
        a replacement decorated controller method and output that will
        subsequently be rendered.

        This allows for validation to display the original page or an
        abbreviated form with validation errors shown on validation failure.

        The before_render hook provides a place for functions that are called
        before the template is rendered. For example, you could use it to
        add and remove from the dictionary returned by the controller method,
        before it is passed to rendering.

        The after_render hook can act upon and modify the response out of
        rendering.
        t	   tg_formatt   before_validatet   ignore_parametersi    i   t   before_callt   before_rendert   after_render(   t   _initialize_validation_contextt   start_responseR   R   t   headerst
   decorationt	   run_hooksR   t   gett   copyR/   t	   enumeratet   lent   _perform_validatet   ct   form_valuest   dictt
   formencodet   apit   Invalidt   _handle_validation_errorst   _render_response(   R   t
   controllert   paramst	   remaindert   ignoret   validate_paramsR.   t   argvarst   it   vart   namet   outputt   invt   response(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   _perform_calln   sX    
   
	c      
   C   s  t  | i d d  } | d j o | St d d h t t  d 6 } h  } t | i t  o h  } xh | i i	   D]W \ } } y# | i
 | i |  |  | | <Wqu t i i j
 o }	 |	 | | <qu Xqu Wx5 | i   D]' \ }
 } |
 | j o | | |
 <q q W| o. t i i t i i |  | d d |  qn t | i t i  o | i i
 | |  } no t | i d  o/ t  | d t  o | i i | | |  } n- t | i d  o | i i | |  } n | S(	   sW  
        Validation is stored on the "validation" attribute of the controller's
        decoration.

        If can be in three forms:

        1) A dictionary, with key being the request parameter name, and value a
           FormEncode validator.

        2) A FormEncode Schema object

        3) Any object with a "validate" method that takes a dictionary of the
           request variables.

        Validation can "clean" or otherwise modify the parameters that were
        passed in, not just raise an exception.  Validation exceptions should
        be FormEncode Invalid objects.
        t
   validationt   statet   _t
   error_dictt   validatet   needs_controllerN(    (   t   getattrR9   R   t   typet   staticmethodt   pylons_formencode_gettextt
   isinstancet
   validatorsRB   t	   iteritemst	   to_pythonR;   RC   RD   RE   t   itemst   schemat   format_compound_errort   SchemaR   t   FalseRY   (   R   RH   RI   RU   RV   t
   new_paramst   errorst   fieldt	   validatorRR   t   paramt   param_value(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR?      s>    	  	c         C   sK  | i  i t i  \ } } } } | t j o | t i i d <n t | t  p | St i i	   } t i
 i	   } t i i d t  }	 | d j o | S|	 p d | j o_ t i i	   }
 | t   j o< t t  i d h   } |
 i | |  t   i |  qn | i i d  | _ t i d o | d j p d o | t i _ n t d	 |  } t | t  o | i |  n x | D] } | i |  qW| i i d
  o9 | i d } | | d <| | d <| | d <| | d <n |	 p d | j o( |
 i d | d | d t d |  } n t d | d | d |  } | S(   s  
        Render response takes the dictionary returned by the
        controller calls the appropriate template engine. It uses
        information off of the decoration object to decide which engine
        and template to use, and removes anything in the exclude_names
        list from the returned dictionary.

        The exclude_names functionality allows you to pass variables to
        some template rendering engines, but not others. This behavior
        is particularly useful for rendering engines like JSON or other
        "web service" style engines which don't use and explicit
        template, or use a totally generic template.

        All of these values are populated into the context object by the
        expose decorator.
        s   Content-Typet   use_legacy_renderert   jsons   buffet.template_optionss   repoze.who.identityt   use_toscawidgetst   genshit   makot   tmpl_contexts   paste.testings   paste.testing_variablest	   namespacet   template_namet   exclude_namest   controller_outputt   engine_namet   include_pylons_variablest   template_varst   template_engineN(   R9   t   lookup_template_engineR   R   t   CUSTOM_CONTENT_TYPERS   R8   R_   RB   R   Rs   R   R;   t   TrueR   t   buffetR   t   preparet   addt   environt   identityt   twt	   frameworkt   default_viewt   updatet   popR   Rg   t	   tg_render(   R   RH   RS   t   content_typeRx   Ru   Rv   t   reqRs   Rn   R   t   template_optionsRt   RP   t   testing_variablest   result(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyRG     sP    !" 


	c   
      C   sG  | t  i _ h  t  i _ | i   i d  } xo | D]g } | i d  } t |  d j o! | d i   t  i i d <q4 n | d i   t  i i | d <q4 W| i t  i _	 | i
 i i } | d j o | } | | t |    }	 nU t | d  o) | i | j o | | t |    }	 n | | i | t |   }	 | |	 f S(   sf  
        Sets up pylons.c.form_values and pylons.c.form_errors to assist
        generating a form with given values and the validation failure
        messages.

        The error handler in decoration.validation.error_handler is called. If
        an error_handler isn't given, the original controller is used as the
        error handler instead.
        s   
t   :i   i    t	   _the_formt   im_selfN(   R   R@   t   validation_exceptiont   form_errorst   __str__t   splitR>   t   stript   valueRA   R9   RU   t   error_handlerR   RB   R   R   (
   R   RH   RJ   RI   t	   exceptiont
   error_listt   errort   field_valueR   RQ   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyRF   j  s&     " c         C   s   h  t  i _ h  t  i _ d  S(   N(   R   R@   R   RA   (   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR6     s    N(   t   __name__t
   __module__t   __doc__R   R#   R$   R/   R   RT   R?   RG   RF   R6   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   5   s   		
			M	X	W	+t   ObjectDispatchControllerc           B   s2   e  Z d  Z d d  Z d   Z d d d  Z RS(   s  
    Object dispatch (also "object publishing") means that each portion of the
    URL becomes a lookup on an object.  The next part of the URL applies to the
    next object, until you run out of URL.  Processing starts on a "Root"
    object.

    Thus, /foo/bar/baz become URL portion "foo", "bar", and "baz".  The
    dispatch looks for the "foo" attribute on the Root URL, which returns
    another object.  The "bar" attribute is looked for on the new object, which
    returns another object.  The "baz" attribute is similarly looked for on
    this object.

    Dispatch does not have to be directly on attribute lookup, objects can also
    have other methods to explain how to dispatch from them.  The search ends
    when a decorated controller method is found.

    The rules work as follows:

    1) If the current object under consideration is a decorated controller
       method, the search is ended.

    2) If the current object under consideration has a "default" method, keep a
       record of that method.  If we fail in our search, and the most recent
       method recorded is a "default" method, then the search is ended with
       that method returned.

    3) If the current object under consideration has a "lookup" method, keep a
       record of that method.  If we fail in our search, and the most recent
       method recorded is a "lookup" method, then execute the "lookup" method,
       and start the search again on the return value of that method.

    4) If the URL portion exists as an attribute on the object in question,
       start searching again on that attribute.

    5) If we fail our search, try the most recent recorded methods as per 2 and
       3.
    c         C   s   | d j o t i i i d  d } n | i d  } t |  |  \ } } | o$ d i | t |    t i _	 n | t i _	 | o | d d j o | i
   n | | t i i i   f S(   s   
        Returns a tuple (controller, remainder, params)

        :Parameters:
          url
            url as string
        t   /i   it    N(   R   R   R   t   pathR   t   _object_dispatcht   joinR>   R@   t   controller_urlR   RI   t   mixed(   R   R    t   url_pathRH   RJ   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   _get_routing_info  s    	$c         C   s   |  i  | i d   \ } } } | i } | d j p | d j og | d j o$ t | i d  o | i i |   S| d j o$ t | i d  o | i i |   Sd  St i	 |  | | d | S(   NR    R#   R$   RJ   (
   R   R;   R   R   t   im_classR   R#   R$   R   RT   (   R   R,   R   RH   RJ   RI   t	   func_name(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyRT     s    !	  R   c         K   s   d S(   s   
        This function does not do anything.  It is a placeholder that allows
        Routes to accept this controller as a target for its routing.
        N(    (   R   R    R7   R    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   routes_placeholder  s    N(   R   R   R   R   R   RT   R   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s   %	c         C   sJ   t  |  d  o |  i } n |  GH|  } t  | d  o | i   n d S(   s   this function checks if a controller has a 'alow_only' attribute and if
    it is the case, test that this require predicate can be evaled to True.
    It will raise a Forbidden exception if the predicate is not valid.
    R   t   _check_securityN(   R   R   R   (   t   objt   klass_instance(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   _check_controller_auth  s    c      	   C   s  | } d  t i _ d  t i _ | o~ d | d j om | d } t i |  \ } } | oC | i d  } | | } | |  | d <| t i _ | t i _ q n g  } xt o y/ t	 |  | |  \ }  }	 } t
 |  |	 |  SWq t j
 o }
 t i d |     q t j
 o } | i d j o | i  n | p | i  n | i   \ } }  }	 } | d j o t
 |  |	 |  S|  |   \ }  } t |  q q Xq Wd  S(   Nt   .is   a 401 error occured for obj: %si  t   default(   R   R   R   t   response_typet   response_extt	   mimetypest
   guess_typet   rfindR~   t   _find_objectt   _find_restful_dispatchR   t   logt   debugR	   t
   status_intR   R   t   list(   R   R   RJ   t   last_remaindert	   mime_typet   encodingt   extension_spott	   extensiont   notfound_handlerst   parentt   httpet   eRP   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s@    

 
c         C   s   t  |   t i |   o t |  t  o |  | f St i i i   } } t i i	 } d | j o# | d o | d i   } q n | o | d d j o | d  } n | oet
 |  } | d j o | d d j o{ | d j o | d } n | d j o! t
 |  d j o | d  } n | d j o! t
 |  d j o | d  } qnL| d j o6 | d d	 j o% d	 } | d j o | d  } qn	| d j o | d
 j p | d j o t |  d  o t |  d  } t
 t i |  d  d } | | }	 t
 |	  d j o< t |  |	 d  o( t t t |  |	 d  |	 d g     St |  | d  o( t t t |  | d  | d g     St   i  n | oj t |  | d  oV | d d j oE t i |   o |    }  n t t t |  | d  | d g     Sn | oJ | d j o= t |  d  o- t |  i d  o |  i i i o
 d } n t
 |  d j o#| d j ot |  d  ot |  i d  o |  i i i o t
 |  d j o
 d } qt |  d  } t
 t i |  d  d } | | } t
 |  d j o< t |  | d  o( t t t |  | d  | d g     St |  d  o! t i |  i  d o
 d } qt   i  n | d j oJ | d	 j o= t |  d  o- t |  i d  o |  i i i o
 d } n | d
 j oJ | d	 j o= t |  d  o- t |  i d  o |  i i i o
 d } n t |  |  ou t |  |  }
 t |
 d  oF |
 i i o9 t i |   o |    }  n | |  _ t |  |  }  qt   i  n! t |  t  o t   i  n |  | f S(   Nt   _methodiR   i   t   newt   editR;   i   t   deletet   postt   putt   get_onei    t   get_allR9   t
   get_deletet   post_delete(   s   newR   (   s   newR   (   R   R*   t   isclassR_   t   RestControllerR   R   t   methodt   lowerRI   R>   R   R[   R+   R   R   R   R   R   R9   t   exposedR   R   R   R   (   R   R   RJ   t   request_methodR   RI   t   remainder_lenR,   t   arg_lent   new_remaindert   possible_rest_method(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   '  s    
"  7
'((,,H
S

'('
M
M
	c         C   s  d  } xt o|  d  j o t   i  n t |   t |   o |  | | f S| p$ t |  d j ob | d d j oQ t | t  o t	 |  } n t
 |  d d   } t |  o | |  | f Sn t
 |  d d   } t |  o | i d | |  | f  n t
 |  d d   } | oO t |  d j o | d d j o* t |  o | i d | |  | f  n | p t   i  n |  } y- t
 |  | d i d  d   }  | d } Wq	 t j
 o t   i  q	 Xq	 Wd  S(   Ni   i    R   t   indexR   t   lookups   utf-8(   R   R~   R   R   R   t   _iscontrollerR>   R_   t   tupleR   R[   t   appendt   encodet   UnicodeEncodeError(   R   RJ   R   R   R   R   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s8     
,9c         C   s4   t  |  d  p t St  |  d  p t S|  i i S(   Nt   __call__R9   (   R   Rg   R9   R   (   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s
    R   c           B   s3   e  Z d  Z d e f d     YZ e d    Z RS(   s  A Decorated Controller that dispatches in a RESTful Manner.

    This controller was designed to follow Representational State Transfer protocol, also known as REST.
    The goal of this controller method is to provide the developer a way to map
    RESTful URLS to controller methods directly, while still allowing Normal Object Dispatch to occur.

    Here is a brief rundown of the methods which are called on dispatch along with an example URL.

    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | Method          | Description                                                  | Example Method(s) / URL(s)                 |
    +=================+==============================================================+============================================+
    | get_one         | Display one record.                                          | GET /movies/1                              |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | get_all         | Display all records in a resource.                           | GET /movies/                               |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | get             | A combo of get_one and get_all.                              | GET /movies/                               |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | GET /movies/1                              |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | new             | Display a page to prompt the User for resource creation.     | GET /movies/new                            |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | edit            | Display a page to prompt the User for resource modification. |  GET /movies/1/edit                        |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | post            | Create a new record.                                         | POST /movies/                              |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | put             | Update an existing record.                                   | POST /movies/1?_method=PUT                 |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | PUT /movies/1                              |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | post_delete     | Delete an existing record.                                   | POST /movies/1?_method=DELETE              |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | DELETE /movies/1                           |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | get_delete      | Display a delete Confirmation page.                          | GET /movies/1/delete                       |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | delete          | A combination of post_delete and get_delete.                 | GET /movies/delete                         |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | DELETE /movies/1                           |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | DELETE /movies/                            |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | POST /movies/1/delete                      |
    |                 |                                                              +--------------------------------------------+
    |                 |                                                              | POST /movies/delete                        |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+

    You may note the ?_method on some of the URLs.  This is basically a hack because exiting browsers
    do not support the PUT and DELETE methods.  Just note that if you decide to use a this resource with a web browser,
    you will likely have to add a _method as a hidden field in your forms for these items.  Also note that RestController differs
    from TGController in that it offers no index, default, or lookup.  It is intended primarily for  resource management.

    :References:

      `Controller <../main/Controllers.html>`_  A basic overview on how to write controller methods.

      `CrudRestController <../main/Extensions/Crud/index.html>`_  A way to integrate ToscaWdiget Functionality with RESTful Dispatch.

    R9   c           B   s   e  Z d  Z e Z RS(   s^   This is here so that the Object Dispatcher will recognize this class as an exposed controller.(   R   R   R   R~   R   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR9     s   c         C   s  t  |  d  p |  i d  j o t i d t i i  t Sy  |  i } | i	 t i i
  Wn t j
 o } t |  } t  |  d  o |  i |  n t   i t i
  o d } d } n d } d } | t i _ t | d | t | d	 | n Xd  S(
   NR   s&   No controller-wide authorization at %st   _failed_authorizationi  R   i  t   warningt   statust   comment(   R   R   R   R   R   R   R   R   R~   t   check_authorizationR   R   t   unicodeR   R   t   is_metRS   R   R   R   (   t   clsR!   R   t   reasont   codeR   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s&    !		
(   R   R   R   t   objectR9   t   classmethodR   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s   :t   TGControllerc           B   s    e  Z d  Z d   Z d   Z RS(   s  
    TGController is a specialized form of ObjectDispatchController that forms the
    basis of standard TurboGears controllers.  The "Root" controller of a standard
    tg project must be a TGController.

    This controller can be used as a baseclass for anything in the
    object dispatch tree, but it MUST be used in the Root controller
    and any controller which you intend to do object dispatch from
    using Routes.

    This controller has a few reserved method names which provide special functionality.

    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | Method          | Description                                                  | Example URL(s)                             |
    +=================+==============================================================+============================================+
    | index           | The root of the controller.                                  | /                                          |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | default         | A method to call when all other methods have failed.         | /movies                                    |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+
    | lookup          | Allows the developer to return a                             | /location/23.35/2343.34/elevation          |
    |                 | Controller instance for further dispatch.                    |                                            |
    +-----------------+--------------------------------------------------------------+--------------------------------------------+


    :References:

      `Controller <../main/Controllers.html>`_  A basic overview on how to write controller methods.

    c   
   	   C   s\  t    d  } t | t  o d | j o | d } n y |  i |  \ } } } | i } | p
 g  } n | d j p | d j og | d j o$ t | i d  o | i i	 |   S| d j o$ t | i d  o | i i
 |   Sd  St i |  | | d | } WnK t j
 o? }	 |	 } | i d j o | i i d d   n t | _ n X| S(   NR    R#   R$   RJ   i0  s   Content-Type(   R   R   R_   RB   R   R   R   R   R   R#   R$   R   RT   R	   R   R8   R   R~   t
   _exception(
   R   R,   R   t   routingArgsRH   RJ   RI   R   R   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyRT   .  s.    	
  c         C   s  t  |  d  p |  i d  j o t i d t i i  t Sy  |  i } | i	 t i i
  Wn t j
 o } t |  } t  |  d  o |  i |  n t   i t i
  o d } d } n d } d } | t i _ t | d | t | d	 | n Xd  S(
   NR   s&   No controller-wide authorization at %sR   i  R   i  R   R   R   (   R   R   R   R   R   R   R   R   R~   R   R   R   R   R   R   R   RS   R   R   R   (   R   R!   R   R   R   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   N  s&    !		
(   R   R   R   RT   R   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s   	 t   WSGIAppControllerc           B   s5   e  Z d  Z d d  Z e   d    Z d   Z RS(   s7   
    A controller you can use to mount a WSGI app.
    c         C   s6   | |  _  | |  _ t t i d <t t |   i   d  S(   Nt   make_body_seekable(   t   appR   R~   R   R   R   R   R   (   R   R   R   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   m  s    		c         O   s   t  i i   } | i   } t | i i d  i d   t |  } x t |  D] } | i	   qS W| i p t
 | i d  n | i i d  |  i | i | i  S(   s   
        This method is called whenever a request reaches this controller.
        It prepares the WSGI environment and delegates the request to the
        WSGI app.
        R   i    (   R   R   R   R<   R>   t	   path_infoR   R   t   xranget   path_info_popt   redirectt	   body_filet   seekt   delegateR   R7   (   R   R   R"   R   t   new_reqt   to_popRN   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   v  s    + 
c         C   s   |  i  | |  S(   s   
        Delegates the request to the WSGI app.

        Override me if you need to update the environ, mangle response, etc...
        (   R   (   R   R   R7   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s    N(   R   R   R   R   R   R   R   R   (    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR   i  s   	c          O   sC  t  |   }  t |  d t   o d i |  d  |  d <n |  o t |  d t  o t | i d  t  o. | d i   } | d =| i |  | } n t |   d j oS t |  d t  o? |  d i   } | o | i |  n | } |  i	 d  n t |  d t
  o |  d i d  |  d <q6n t |  |   S(   s  Generate an absolute URL that's specific to this application.

    The URL function takes a string, appends the SCRIPT_NAME and adds url
    parameters for all of the other keyword arguments passed in.

    For backwards compatibility you can also pass in a params dictionary
    which is turned into url params, or you can send in a a list of
    strings as the first argument, which will be joined with /'s to
    make a url string.

    In general tg.url is just a proxy for pylons.url which is in turn
    a proxy for routes url_for function.  This means that if the first
    argument is not a basestring but a method that has been routed to,
    the standard routes url_for reverse lookup system will be used.
    i    u   /RI   i   i   t   utf8(   R   R_   R   t
   basestringR;   RB   R<   R   R>   R   R   R   t
   pylons_url(   R   R    RI   (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR      s$    
'c          O   s2   t  |  |   t d t  |  |    i } |  d S(   s  Generate an HTTP redirect.

    The function raises an exception internally,
    which is handled by the framework. The URL may be either absolute (e.g.
    http://example.com or /myfile.html) or relative. Relative URLs are
    automatically converted to absolute URLs. Parameters may be specified,
    which are appended to the URL. This causes an external redirect via the
    browser; if the request is POST, the browser will issue GET for the
    second request.
    t   locationN(   R    R   R   (   R   R    t   found(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR     s    c         C   s   |  t  i i t  i i  S(   N(   R   R   R   R7   (   t   wsgi_app(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   use_wsgi_app  s    c         C   s   d d k  l } d d k l } | |   } | |  j oX y t i i } Wn t j
 o } |   } n X| p |   } n | i |   } n | S(   Ni(   t   ugettext(   t   NullTranslations(   t   pylons.i18nR  t   gettextR  R   R@   t   formencode_translationR'   (   R   t   pylons_gettextR  t   transt   fetranst	   attrerror(    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyR^     s    R    R   (;   R   t   loggingt   warningst   urlparset   urllibR   R*   RC   R   R    R   R   R   t   pylons.controllersR   t   pylons.controllers.utilR   t   repoze.what.predicatesR   R   R   t   tg.exceptionsR   R   R	   R
   t	   tg.renderR   R   t   tg.decoratorsR   R   t   tg.i18nR   t   tg.flashR   t   webobR   t	   webob.excR   t	   getLoggerR   R   R}   R   R   R   R   R   R   R   R   R   R   R   R   R  R^   t   __all__(    (    (    sl   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears2-2.0.1-py2.6.egg/tg/controllers.pyt   <module>	   sN   "	 eS		-	Z	+	\Z)	&				