ó
çiõ\c           @   sÔ   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l m Z d Z d e f d „  ƒ  YZ d e	 f d „  ƒ  YZ
 d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e  j f d „  ƒ  YZ d e  j f d „  ƒ  YZ d S(   iÿÿÿÿN(   t
   UsageErrort   file_or_dirt   Parserc           B   sŒ   e  Z d  Z d Z d d d „ Z d „  Z d d d „ Z d „  Z d d „ Z	 d „  Z
 d d „ Z d d	 „ Z d d
 „ Z d d d „ Z RS(   sÅ    Parser for command line arguments and ini-file values.

    :ivar extra_info: dict of generic param -> value to display in case
        there's an error processing the command line arguments.
    c         C   sO   t  d d |  ƒ|  _ g  |  _ | |  _ | |  _ i  |  _ g  |  _ i  |  _ d  S(   Ns   custom optionst   parser(   t   OptionGroupt
   _anonymoust   _groupst   _processoptt   _usaget   _inidictt	   _ininamest
   extra_info(   t   selft   usaget
   processopt(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   __init__   s    					c         C   s)   |  j  r% | j r% |  j  | ƒ q% n  d  S(   N(   R   t   dest(   R   t   option(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   processoption   s    		t    c         C   s   x$ |  j  D] } | j | k r
 | Sq
 Wt | | d |  ƒ} d } x0 t |  j  ƒ D] \ } } | j | k rR PqR qR W|  j  j | d | ƒ | S(   sØ   get (or create) a named option Group.

        :name: name of the option group.
        :description: long description for --help output.
        :after: name of other group, used for ordering --help output.

        The returned group object has an ``addoption`` method with the same
        signature as :py:func:`parser.addoption
        <_pytest.config.Parser.addoption>` but will be shown in the
        respective group in the output of ``pytest. --help``.
        R   i    i   (   R   t   nameR   t	   enumeratet   insert(   R   R   t   descriptiont   aftert   groupt   it   grp(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   getgroup$   s    c         O   s   |  j  j | | Ž  d S(   s   register a command line option.

        :opts: option names, can be short or long options.
        :attrs: same attributes which the ``add_option()`` function of the
           `argparse library
           <http://docs.python.org/2/library/argparse.html>`_
           accepts.

        After command line parsing options are available on the pytest config
        object via ``config.option.NAME`` where ``NAME`` is usually set
        by passing a ``dest`` attribute, for example
        ``addoption("--long", dest="NAME", ...)``.
        N(   R   t	   addoption(   R   t   optst   attrs(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   ;   s    c         C   s|   d d l  m } |  j ƒ  |  _ | |  j ƒ g  | D]- } t | t j j ƒ rZ t | ƒ n | ^ q3 } |  j j	 | d | ƒS(   Niÿÿÿÿ(   t   try_argcompletet	   namespace(
   t   _pytest._argcompleteR    t
   _getparsert	   optparsert
   isinstancet   pyt   patht   localt   strt
   parse_args(   R   t   argsR!   R    t   x(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   parseK   s
    :c   
      C   sÔ   d d l  m } t |  |  j d |  j ƒ} |  j |  j g } xw | D]o } | j rE | j pc | j	 } | j
 | ƒ } x< | j D]. } | j ƒ  } | j ƒ  }	 | j | |	 Ž  q WqE qE W| | j t d d ƒ_ | S(   Niÿÿÿÿ(   t   filescompletert   progt   nargst   *(   R"   R.   t   MyOptionParserR   R/   R   R   t   optionsR   R   t   add_argument_groupt   namesR   t   add_argumentt   FILE_OR_DIRt	   completer(
   R   R.   R$   t   groupsR   t   desct   arggroupR   t   nt   a(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR#   S   s    	c         C   sR   |  j  | d | ƒ} x- | j j ƒ  D] \ } } t | | | ƒ q% Wt | t ƒ S(   NR!   (   R-   t   __dict__t   itemst   setattrt   getattrR7   (   R   R+   R   R!   t   parsedoptionR   t   value(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   parse_setoptiond   s    c         C   s   |  j  | d | ƒd S(   sZ   parses and returns a namespace object with known arguments at this
        point.
        R!   i    (   t   parse_known_and_unknown_args(   R   R+   R!   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   parse_known_argsj   s    c         C   sY   |  j  ƒ  } g  | D]- } t | t j j ƒ r: t | ƒ n | ^ q } | j | d | ƒS(   s   parses and returns a namespace object with known arguments, and
        the remaining arguments unknown at this point.
        R!   (   R#   R%   R&   R'   R(   R)   RF   (   R   R+   R!   R$   R,   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyRE   p   s    :c         C   s<   | d k s t ‚ | | | f |  j | <|  j j | ƒ d S(   s“   register an ini-file option.

        :name: name of the ini-variable
        :type: type of the variable, can be ``pathlist``, ``args``, ``linelist``
               or ``bool``.
        :default: default value if no ini-file option exists but is queried.

        The value of ini-variables can be retrieved via a call to
        :py:func:`config.getini(name) <_pytest.config.Config.getini>`.
        t   pathlistR+   t   linelistt   boolN(   NRG   R+   RH   RI   (   t   Nonet   AssertionErrorR	   R
   t   append(   R   R   t   helpt   typet   default(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   addinix   s    N(   t   __name__t
   __module__t   __doc__RJ   R/   R   R   R   R   R-   R#   RD   RF   RE   RP   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR      s   				t   ArgumentErrorc           B   s    e  Z d  Z d „  Z d „  Z RS(   s_   
    Raised if an Argument instance is created with invalid or
    inconsistent arguments.
    c         C   s   | |  _  t | ƒ |  _ d  S(   N(   t   msgR)   t	   option_id(   R   RU   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   Ž   s    	c         C   s(   |  j  r d |  j  |  j f S|  j Sd  S(   Ns   option %s: %s(   RV   RU   (   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   __str__’   s    	(   RQ   RR   RS   R   RW   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyRT   ˆ   s   	t   Argumentc           B   s]   e  Z d  Z i e d 6e d 6e d 6e d 6Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z RS(
   sô   class that mimics the necessary behaviour of optparse.Option

    it's currently a least effort implementation
    and ignoring choices and integer prefixes
    https://docs.python.org/3/library/optparse.html#optparse-standard-option-types
    t   intt   stringt   floatt   complexc         O   sÏ  | |  _  g  |  _ g  |  _ | j d ƒ |  _ d | j d ƒ pB d k ra t j d t d d ƒn  y | d } Wn t k
 r‚ n¤ Xt	 | t
 j ƒ r| d	 k rÜ t j d
 | | f t d d ƒt | d d ƒ | d <n1 t j d | | f t d d ƒt j | | d <| d |  _ n	 | |  _ y | d |  _ Wn t k
 rJn X|  j | ƒ |  j sË|  j r|  j d d j d d ƒ |  _ qËy |  j d d |  _ WqËt k
 rÇt d |  ƒ ‚ qËXn  d S(   s3   store parms in private vars for use in add_argumentR   s   %defaultRM   R   sH   pytest now uses argparse. "%default" should be changed to "%(default)s" t
   stackleveli   RN   t   choices±   `type` argument to addoption() is the string %r. For choices this is optional and can be omitted,  but when supplied should be a type (for example `str` or `int`). (options: %s)i   t   choicesi    s€   `type` argument to addoption() is the string %r,  but when supplied should be a type (for example `str` or `int`). (options: %s)RO   i   t   -t   _i   s   need a long or short optionN(   t   _attrst   _short_optst
   _long_optst   getR   t   warningst   warnt   DeprecationWarningt   KeyErrorR%   t   sixt   string_typesRN   RX   t   _typ_mapRO   t   _set_opt_stringst   replacet
   IndexErrorRT   (   R   R5   R   t   typ(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   £   sR    			


			#c         C   s   |  j  |  j S(   N(   Rc   Rd   (   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR5   ß   s    c         C   s¯   d j  ƒ  } |  j r( | j |  j ƒ n  x< | D]4 } y t |  | ƒ |  j | <Wq/ t k
 rb q/ Xq/ W|  j j d ƒ r¨ |  j d } | j d d ƒ } | |  j d <n  |  j S(   Ns   default dest helpRM   s   %defaults   %(default)s(   t   splitR   RL   RA   Rb   t   AttributeErrorRe   Rn   (   R   R   t   attrR=   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   â   s    	c         C   sá   xÚ | D]Ò } t  | ƒ d k  r5 t d | |  ƒ ‚ q t  | ƒ d k r | d d k od | d d k s} t d | |  ƒ ‚ n  |  j j | ƒ q | d d !d k o° | d d k sÉ t d | |  ƒ ‚ n  |  j j | ƒ q Wd	 S(
   s]   directly from optparse

        might not be necessary as this is passed to argparse later oni   s>   invalid option string %r: must be at least two characters longi    R`   i   sM   invalid short option string %r: must be of the form -x, (x any non-dash char)s   --sG   invalid long option string %r: must start with --, followed by non-dashN(   t   lenRT   Rc   RL   Rd   (   R   R   t   opt(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyRm   ó   s&     #c         C   sÚ   g  } |  j  r, | d t |  j  ƒ g 7} n  |  j rR | d t |  j ƒ g 7} n  | d t |  j ƒ g 7} t |  d ƒ r˜ | d t |  j ƒ g 7} n  t |  d ƒ rÄ | d t |  j ƒ g 7} n  d j d	 j | ƒ ƒ S(
   Ns   _short_opts: s   _long_opts: s   dest: RN   s   type: RO   s	   default: s   Argument({})s   , (	   Rc   t   reprRd   R   t   hasattrRN   RO   t   formatt   join(   R   R+   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   __repr__  s    		(   RQ   RR   RS   RY   R)   R[   R\   Rl   R   R5   R   Rm   Rz   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyRX   ™   s   "	<			R   c           B   s5   e  Z d  d d „ Z d „  Z d „  Z e d „ Z RS(   R   c         C   s(   | |  _  | |  _ g  |  _ | |  _ d  S(   N(   R   R   R3   R   (   R   R   R   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR     s    			c         O   sa   t  | ƒ j d „  |  j Dƒ ƒ } | r; t d | ƒ ‚ n  t | | Ž  } |  j | d t ƒd S(   sE   add an option to this group.

        if a shortened version of a long option is specified it will
        be suppressed in the help. addoption('--twowords', '--two-words')
        results in help showing '--two-words' only, but --twowords gets
        accepted **and** the automatic destination is in args.twowords
        c         s   s(   |  ] } | j  ƒ  D] } | Vq q d  S(   N(   R5   (   t   .0Ru   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pys	   <genexpr>-  s    s   option names %s already addedt
   shortupperN(   t   sett   intersectionR3   t
   ValueErrorRX   t   _addoption_instancet   False(   R   t   optnamesR   t   conflictR   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   $  s    c         O   s&   t  | | Ž  } |  j | d t ƒd  S(   NR|   (   RX   R€   t   True(   R   R‚   R   R   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt
   _addoption4  s    c         C   s|   | sL xC | j  D]5 } | d d k r | d j ƒ  r t d ƒ ‚ q q Wn  |  j rh |  j j | ƒ n  |  j j | ƒ d  S(   Ni    R`   i   s   lowercase shortoptions reserved(   Rc   t   islowerR   R   R   R3   RL   (   R   R   R|   Ru   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR€   8  s     	N(   RQ   RR   RJ   R   R   R…   R   R€   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR     s   		R2   c           B   s/   e  Z d d d  „ Z d „  Z d d d „ Z RS(   c      
   C   sP   | s i  } n  | |  _  t j j |  d | d | j d t d t ƒ| |  _ d  S(   NR/   R   t   add_helpt   formatter_class(   t   _parsert   argparset   ArgumentParserR   R   R   t   DropShorterLongHelpFormatterR   (   R   R   R   R/   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   C  s    				c         C   sX   d |  j  | f } t |  j d ƒ r> d | |  j j f } n  t |  j ƒ  | ƒ ‚ d S(   s1   Transform argparse error message into UsageError.s   %s: error: %st   _config_source_hints   %s (%s)N(   R/   Rw   R‰   R   R    t   format_usage(   R   t   messageRU   (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   errorR  s    c         C   sÎ   |  j  | | ƒ \ } } | rÊ x | D]ˆ } | r% | d d k r% d d j | ƒ g } x: t |  j j ƒ  ƒ D]# \ } } | j d | | f ƒ qm W|  j d j | ƒ ƒ q% q% Wt | t ƒ j	 | ƒ n  | S(   s'   allow splitting of positional argumentsi    R`   s   unrecognized arguments: %st    s     %s: %ss   
(
   RF   Ry   t   sortedR   R?   RL   R   RA   R7   t   extend(   R   R+   R!   t   argvt   argt   linest   kt   v(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR*   [  s    "N(   RQ   RR   RJ   R   R   R*   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR2   B  s   		RŒ   c           B   s   e  Z d  Z d „  Z RS(   sƒ  shorten help for long options that differ only in extra hyphens

    - collapse **long** options that are the same except for extra hyphens
    - special action attribute map_long_option allows surpressing additional
      long options
    - shortcut if there are only two options and one of them is a short one
    - cache result on action object as this is called at least 2 times
    c         C   s@  t  j j |  | ƒ } | r/ | d d k r/ | St | d d  ƒ } | rK | S| j d ƒ } t | ƒ d k r¥ t | d ƒ d k s˜ t | d ƒ d k r¥ | | _ | Sg  } t | d i  ƒ } | d  k rÒ i  } n  i  } xÅ | D]½ } t | ƒ d k sß | d d k rqß n  | j d	 ƒ s2t	 d
 | |  ƒ ‚ n  | d }	 |	 j ƒ  d | k rß |	 j
 d d ƒ }
 |
 | k sŒt | |
 ƒ t |	 ƒ k  rœ|	 | |
 <qœqß qß Wx„ | D]| } t | ƒ d k sÏ| d d k rß| j | ƒ n  | d | j | j
 d d ƒ ƒ k r§| j | j
 d d d ƒ ƒ q§q§Wd j | ƒ | _ | j S(   Ni    R`   t   _formatted_action_invocations   , i   i   t   map_long_optionR‘   s   --s)   long optional argument without "--": [%s]R   t   =(   RŠ   t   HelpFormattert   _format_action_invocationRA   RJ   Rq   Rt   R™   t
   startswithRT   Rn   RL   Re   Ry   (   R   t   actiont   orgstrt   resR3   t   return_listt
   option_mapt
   short_longR   t   xxoptiont	   shortened(    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyR   s  sD    >		"
"%#(   RQ   RR   RS   R   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyRŒ   i  s   (   RŠ   Rf   R&   Rj   t   _pytest.config.exceptionsR    R7   t   objectR   t	   ExceptionRT   RX   R   R‹   R2   Rœ   RŒ   (    (    (    s8   lib/python2.7/site-packages/_pytest/config/argparsing.pyt   <module>   s   {„%'