ó
äq™^c           @@  sW  d  d l  m Z d  d l Z d  d l Z d  d l 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  d l m Z d  d	 l m Z 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  d l m  Z  e j! e" ƒ Z# d e e f d „  ƒ  YZ$ d „  Z% d d d „ Z' d „  Z( d S(   i    (   t   absolute_importN(   t   OrderedDict(   t   pkg_resources(   t   parse(   t   xmlrpc_client(   t   Command(   t   SessionCommandMixin(   t   NO_MATCHES_FOUNDt   SUCCESS(   t   CommandError(   t   PyPI(   t   PipXmlrpcTransport(   t   get_terminal_size(   t
   indent_log(   t   write_outputt   SearchCommandc           B@  s5   e  Z d  Z d Z e Z d „  Z d „  Z d „  Z RS(   s@   Search for PyPI packages whose name or summary contains <query>.s   
      %prog [options] <query>c         O@  sa   t  t |  ƒ j | | Ž  |  j j d d d d d d d t j d d	 ƒ|  j j d
 |  j ƒ d  S(   Ns   -is   --indext   destt   indext   metavart   URLt   defaultt   helps3   Base URL of Python Package Index (default %default)i    (	   t   superR   t   __init__t   cmd_optst
   add_optionR
   t   pypi_urlt   parsert   insert_option_group(   t   selft   argst   kw(    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR   %   s    			c         C@  s|   | s t  d ƒ ‚ n  | } |  j | | ƒ } t | ƒ } d  } t j j ƒ  r^ t ƒ  d } n  t | d | ƒ| rx t	 St
 S(   Ns)   Missing required argument (search query).i    t   terminal_width(   R	   t   searcht   transform_hitst   Nonet   syst   stdoutt   isattyR   t   print_resultsR   R   (   R   t   optionsR   t   queryt	   pypi_hitst   hitsR    (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyt   run0   s    c         C@  s]   | j  } |  j | ƒ } t | | ƒ } t j | | ƒ } | j i | d 6| d 6d ƒ } | S(   Nt   namet   summaryt   or(   R   t   get_default_sessionR   R   t   ServerProxyR!   (   R   R)   R(   t	   index_urlt   sessiont	   transportt   pypiR+   (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR!   @   s    	 (	   t   __name__t
   __module__t   __doc__t   usaget   Truet   ignore_require_venvR   R,   R!   (    (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR      s   		c         C@  s¿   t  ƒ  } x£ |  D]› } | d } | d } | d } | | j ƒ  k rk i | d 6| d 6| g d 6| | <q | | d j | ƒ | t | | d ƒ k r | | | d <q q Wt | j ƒ  ƒ S(   s¼   
    The list from pypi is really a list of versions. We want a list of
    packages with the list of versions stored inline. This converts the
    list from pypi into one we can use.
    R-   R.   t   versiont   versions(   R   t   keyst   appendt   highest_versiont   listt   values(   R+   t   packagest   hitR-   R.   R<   (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR"   K   s    	


c      	   C@  sò  |  s
 d  S| d  k re t g  |  D]5 } t | d ƒ t t | j d d g ƒ ƒ ƒ ^ q  ƒ d } n  g  t j D] } | j ^ qo } xg|  D]_} | d } | d p¨ d } t | j d d g ƒ ƒ } | d  k	 r| | d }	 |	 d k rt j	 | |	 ƒ } d	 d
 | d j
 | ƒ } qn  d | d | | f | f }
 yš t |
 ƒ | | k rÕt j | ƒ } t ƒ  c | j | k rt d | j ƒ n< t d | j ƒ t | ƒ j r¿t d | ƒ n t d | ƒ Wd  QXn  Wq‹ t k
 réq‹ Xq‹ Wd  S(   NR-   R=   t   -i   R.   t    i   i
   s   
t    i   s	   %-*s - %ss   %s (%s)s   INSTALLED: %s (latest)s   INSTALLED: %ss=   LATEST:    %s (pre-release; install with "pip install --pre")s   LATEST:    %s(   R#   t   maxt   lenR@   t   getR   t   working_sett   project_namet   textwrapt   wrapt   joinR   t   get_distributionR   R<   t   parse_versiont   pret   UnicodeEncodeError(   R+   t   name_column_widthR    RD   t   pt   installed_packagesR-   R.   t   latestt   target_widtht   linet   dist(    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR'   g   sB    ?

!


c         C@  s   t  |  d t ƒS(   Nt   key(   RH   RQ   (   R=   (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyR@      s    ()   t
   __future__R    t   loggingR$   RM   t   collectionsR   t   pip._vendorR   t   pip._vendor.packaging.versionR   RQ   t   pip._vendor.six.movesR   t   pip._internal.cli.base_commandR   t   pip._internal.cli.req_commandR   t   pip._internal.cli.status_codesR   R   t   pip._internal.exceptionsR	   t   pip._internal.models.indexR
   t   pip._internal.network.xmlrpcR   t   pip._internal.utils.compatR   t   pip._internal.utils.loggingR   t   pip._internal.utils.miscR   t	   getLoggerR6   t   loggerR   R"   R#   R'   R@   (    (    (    s:   /tmp/pip-build-aSgKnK/pip/pip/_internal/commands/search.pyt   <module>   s*   -	)