File: //opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyo
�
b�Nc           @   s�  d  Z  d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e k
 r_ e Z n Xd 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 d	 e f d
 �  �  YZ d d d
 g Z d e f d �  �  YZ d �  Z e j d e � d �  Z e j d e � d �  Z d �  Z d �  Z e j d e � d e f d �  �  YZ e d � Z d
 e f d �  �  YZ d d � Z e e e d � Z d S(   sH   
WSGI applications that parse the URL and dispatch to on-disk resources
i����N(   t   request(   t   fileapp(   t
   import_string(   t   httpexceptions(   t   ETAG(   t
   converterst	   NoDefaultc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s@   /opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR      s   t	   URLParsert   StaticURLParsert   PkgResourcesParserc           B   s�   e  Z d  Z i  Z e Z i  Z e e e d d � Z d �  Z	 d �  Z
 d d � Z d �  Z d �  Z
 d �  Z d �  Z e e � Z d	 �  Z d
 �  Z d �  Z RS(
   s	  
    WSGI middleware
    Application dispatching, based on URL.  An instance of `URLParser` is
    an application that loads and delegates to other applications.  It
    looks for files in its directory that match the first part of
    PATH_INFO; these may have an extension, but are not required to have
    one, in which case the available files are searched to find the
    appropriate file.  If it is ambiguous, a 404 is returned and an error
    logged.
    By default there is a constructor for .py files that loads the module,
    and looks for an attribute ``application``, which is a ready
    application object, or an attribute that matches the module name,
    which is a factory for building applications, and is called with no
    arguments.
    URLParser will also look in __init__.py for special overrides.
    These overrides are:
    ``urlparser_hook(environ)``
        This can modify the environment.  Its return value is ignored,
        and it cannot be used to change the response in any way.  You
        *can* use this, for example, to manipulate SCRIPT_NAME/PATH_INFO
        (try to keep them consistent with the original URL -- but
        consuming PATH_INFO and moving that to SCRIPT_NAME is ok).
    ``urlparser_wrap(environ, start_response, app)``:
        After URLParser finds the application, it calls this function
        (if present).  If this function doesn't call
        ``app(environ, start_response)`` then the application won't be
        called at all!  This can be used to allocate resources (with
        ``try:finally:``) or otherwise filter the output of the
        application.
    ``not_found_hook(environ, start_response)``:
        If no file can be found (*in this directory*) to match the
        request, then this WSGI application will be called.  You can
        use this to change the URL and pass the request back to
        URLParser again, or on to some other application.  This
        doesn't catch all ``404 Not Found`` responses, just missing
        files.
    ``application(environ, start_response)``:
        This basically overrides URLParser completely, and the given
        application is used for all requests.  ``urlparser_wrap`` and
        ``urlparser_hook`` are still called, but the filesystem isn't
        searched in any way.
    c   
      K   s�  | r% d d l  }	 |	 j d t � n i  } t j j d k rX | j t j j d � } n  | |  _ | |  _ | t	 k r� | j
 d d � } n  t j | � |  _
 | t	 k r� | j
 d
 d � } n  t j | � |  _ | t	 k r� | j
 d d � } n  t j | � |  _ |  j j �  |  _ | r.|  j j | � n  x� | j �  D]~ \ }
 } |
 j d � sot d |
 | f � � n  |
 t d � j �  } t | t t f � r�t j | � } n  | |  j | <q;Wd S(   s�   
        Create a URLParser object that looks at `directory`.
        `base_python_name` is the package that this directory
        represents, thus any Python modules in this directory will
        be given names under this package.
        i����Nsf   The global_conf argument to URLParser is deprecated; either pass in None or {}, or use make_url_parsert   /t   index_namest   indext   Indext   maint   Maint   hide_extensionss   .pycs   .baks   .py~s   .pyot   ignore_extensionss   constructor s]   Only extra configuration keys allowed are 'constructor .ext = import_expr'; you gave %r (=%r)(   s   indexR   s   mainR   (   s   .pycs   .baks   .py~s   .pyo(    (   t   warningst   warnt   DeprecationWarningt   ost   patht   sept   replacet	   directoryt   base_python_nameR   t   getR   t   aslistR
   R   R   t   global_constructorst   copyt   constructorst   updatet   itemst
   startswitht
   ValueErrort   lent   stript
   isinstancet   strt   unicodeR   t   eval_import(
   t   selft   global_confR   R   R
   R   R   R!   t   constructor_confR   t   namet   valuet   ext(    (    s@   /opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt   __init__V   sD    
		c      
   C   s
  |  j  | d <|  j t k r1 |  j | � |  _ n  | j d d � } | sY |  j | | � S|  j r� t |  j d d  � r� |  j j | � n  | d } | d } |  j	 | � \ } } | s�|  j r#t |  j d d  � r#| j d � |  k	 r#|  j j
 } |  | d <| | d <| | d <| | | � S| d  k r�t j | d � \ }	 }
 |	 spd d	 j
 |  j pfd
 g � }	 n  |  j | | d |	 |  j f � S| d j d
 | � |  j | | d | |  j f � Sn  |  j r�t |  j d d  � r�|  j j | | | � S| | | � Sd  S(   Ns    paste.urlparser.base_python_namet	   PATH_INFOt    t   urlparser_hookt   SCRIPT_NAMEt   not_found_hooks    paste.urlparser.not_found_parsers	   one of %ss   , s   (no index_names defined)s"