ó
^\kdc           @   sô   d  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 m	 Z	 d d l
 m Z d d l m Z m Z d d l m Z d e j f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s   Base option parser setupiÿÿÿÿN(   t	   strtobool(   t   ConfigParsert   string_types(   t   default_config_file(   t   get_terminal_sizet   get_prog(   t   pkg_resourcest   PrettyHelpFormatterc           B   s\   e  Z d  Z d „  Z d „  Z d d d „ Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 RS(   s4   A prettier/less verbose help formatter for optparse.c         O   sC   d | d <d | d <t  ƒ  d d | d <t j j |  | | Ž d  S(   Ni   t   max_help_positioni   t   indent_incrementi    i   t   width(   R   t   optparset   IndentedHelpFormattert   __init__(   t   selft   argst   kwargs(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR      s    

c         C   s   |  j  | d d ƒ S(   Ns    <%s>s   , (   t   _format_option_strings(   R   t   option(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   format_option_strings   s    s    <%s>s   , c         C   s¶   g  } | j  r& | j | j  d ƒ n  | j rF | j | j d ƒ n  t | ƒ d k rk | j d | ƒ n  | j ƒ  r© | j pŒ | j j ƒ  } | j | | j ƒ  ƒ n  d j	 | ƒ S(   s  
        Return a comma-separated list of option strings and metavars.

        :param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
        :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
        :param optsep:  separator
        i    i   t    (
   t   _short_optst   appendt
   _long_optst   lent   insertt   takes_valuet   metavart   destt   lowert   join(   R   R   t   mvarfmtt   optsept   optsR   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR      s    		c         C   s   | d k r d S| d S(   Nt   OptionsR   s   :
(    (   R   t   heading(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   format_heading3   s    c         C   s#   d |  j  t j | ƒ d ƒ } | S(   sz   
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        s   
Usage: %s
s     (   t   indent_linest   textwrapt   dedent(   R   t   usaget   msg(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   format_usage8   s    c         C   sy   | rq t  |  j d ƒ r! d } n d } | j d ƒ } | j ƒ  } |  j t j | ƒ d ƒ } d | | f } | Sd Sd  S(   Nt   maint   Commandst   Descriptions   
s     s   %s:
%s
R   (   t   hasattrt   parsert   lstript   rstripR%   R&   R'   (   R   t   descriptiont   label(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   format_description@   s    	c         C   s   | r
 | Sd Sd  S(   NR   (    (   R   t   epilog(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   format_epilogR   s    c         C   s3   g  | j  d ƒ D] } | | ^ q } d j | ƒ S(   Ns   
(   t   splitR   (   R   t   textt   indentt   linet	   new_lines(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR%   Y   s    &(   t   __name__t
   __module__t   __doc__R   R   R   R$   R*   R4   R6   R%   (    (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR      s   						t   UpdatingDefaultsHelpFormatterc           B   s   e  Z d  Z d „  Z RS(   s£   Custom help formatter for use in ConfigOptionParser that updates
    the defaults before expanding them, allowing them to show up correctly
    in the help listingc         C   s;   |  j  d  k	 r( |  j  j |  j  j ƒ n  t j j |  | ƒ S(   N(   R/   t   Nonet   update_defaultst   defaultsR   R   t   expand_default(   R   R   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRC   c   s    (   R<   R=   R>   RC   (    (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR?   ^   s   t   CustomOptionParserc           B   s    e  Z d  „  Z e d „  ƒ Z RS(   c         O   s6   |  j  | | Ž  } |  j j ƒ  |  j j | | ƒ | S(   s*   Insert an OptionGroup at a given position.(   t   add_option_groupt   option_groupst   popR   (   R   t   idxR   R   t   group(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   insert_option_groupj   s    c         C   s2   |  j  } x! |  j D] } | j | j  ƒ q W| S(   s<   Get a list of all options, including those in option groups.(   t   option_listRF   t   extend(   R   t   rest   i(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   option_list_alls   s    
(   R<   R=   RJ   t   propertyRO   (    (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRD   i   s   		t   ConfigOptionParserc           B   sb   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 d	 „  Z
 d
 „  Z RS(   ss   Custom option parser which updates its defaults by checking the
    configuration files and environmental variablesc         O   sx   t  j ƒ  |  _ | j d ƒ |  _ |  j ƒ  |  _ |  j rO |  j j |  j ƒ n  |  j s^ t ‚ t	 j
 j |  | | Ž d  S(   Nt   name(   R   t   RawConfigParsert   configRG   RR   t   get_config_filest   filest   readt   AssertionErrorR   t   OptionParserR   (   R   R   R   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyR   �   s    	c         C   sN   t  j j d t ƒ } | t  j k r( g  S| rG t  j j | ƒ rG | g St g S(   Nt   PIP_CONFIG_FILE(   t   ost   environt   gett   Falset   devnullt   patht   existsR   (   R   t   config_file(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRU   Š   s    c         C   sU   y | j  | | ƒ SWn: t j k
 rP t j ƒ  d } d | GHt j d ƒ n Xd  S(   Ni   s*   An error occurred during configuration: %si   (   t   check_valueR   t   OptionValueErrort   syst   exc_infot   exit(   R   R   t   keyt   valt   e(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   check_default’   s    	c         C   s,  i  } x6 d |  j  f D]% } | j |  j |  j | ƒ ƒ ƒ q W| j |  j |  j ƒ  ƒ ƒ xÊ | j ƒ  D]¼ \ } } |  j | ƒ } | d k	 rh | s› qh n  | j d k r¹ t	 | ƒ } n  | j d k rÿ | j
 ƒ  } g  | D] } |  j | | | ƒ ^ qÛ } n |  j | | | ƒ } | | | j <qh qh W| S(   s¢   Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).t   globalt
   store_truet   store_falset   countR   N(   s
   store_trues   store_falses   count(   RR   t   updatet   normalize_keyst   get_config_sectiont   get_environ_varst   itemst
   get_optionR@   t   actionR    R7   Rk   R   (   R   RB   RT   t   sectionRh   Ri   R   t   v(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRA   š   s"    #+c         C   sY   i  } xL | D]D \ } } | j  d d ƒ } | j d ƒ sG d | } n  | | | <q W| S(   s™   Return a config dictionary with normalized keys regardless of
        whether the keys were specified in environment variables or in config
        filest   _t   -s   --s   --%s(   t   replacet
   startswith(   R   Rt   t
   normalizedRh   Ri   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRq   ·   s    c         C   s&   |  j  j | ƒ r" |  j  j | ƒ Sg  S(   s    Get a section of a configuration(   RT   t   has_sectionRt   (   R   RR   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRr   Ã   s    t   PIP_c         c   sS   xL t  j j ƒ  D]; \ } } | j | ƒ r | j | d ƒ j ƒ  | f Vq q Wd S(   s@   Returns a generator with all environmental vars with prefix PIP_R   N(   R[   R\   Rt   R|   R{   R   (   R   t   prefixRh   Ri   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRs   É   s    c         C   sž   |  j  s t j |  j ƒ S|  j |  j j ƒ  ƒ } x] |  j ƒ  D]O } | j | j ƒ } t	 | t
 ƒ r> | j ƒ  } | j | | ƒ | | j <q> q> Wt j | ƒ S(   s‹   Overridding to make updating the defaults after instantiation of
        the option parser possible, update_defaults() does the dirty work.(   t   process_default_valuesR   t   ValuesRB   RA   t   copyt   _get_all_optionsR]   R   t
   isinstanceR   t   get_opt_stringRc   (   R   RB   R   t   defaultt   opt_str(    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   get_default_valuesÏ   s    	 c         C   s(   |  j  t j ƒ |  j d d | ƒ d  S(   Ni   s   %s
(   t   print_usageRe   t   stderrRg   (   R   R)   (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   errorÞ   s    (   R<   R=   R>   R   RU   Rk   RA   Rq   Rr   Rs   R‰   RŒ   (    (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyRQ   }   s   								(   R>   Re   R   R[   R&   t   distutils.utilR    t   pip.backwardcompatR   R   t   pip.locationsR   t   pip.utilR   R   t   pip._vendorR   R   R   R?   RY   RD   RQ   (    (    (    s5   /var/www/testScraper/venv/build/pip/pip/baseparser.pyt   <module>   s   O