
9Vc           @@  s  d  d l  m Z d  d l Z d  d l Z d  d l 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 d  d
 l m Z d  d l m Z e j e  Z d e f d     YZ d   Z d d d  Z d   Z d S(   i    (   t   absolute_importN(   t   Commandt   SUCCESS(   t   PipXmlrpcTransport(   t   PyPI(   t   get_terminal_size(   t
   indent_log(   t   CommandError(   t   NO_MATCHES_FOUND(   t   pkg_resources(   t   xmlrpc_clientt   SearchCommandc           B@  s;   e  Z d  Z d Z d Z d Z d   Z d   Z d   Z RS(   s@   Search for PyPI packages whose name or summary contains <query>.t   searchs   
      %prog [options] <query>s   Search PyPI for packages.c      
   O@  s^   t  t |   j | |   |  j j d d d d d d t j d d |  j j d	 |  j  d  S(
   Ns   --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(    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/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   R   t   transform_hitst   Nonet   syst   stdoutt   isattyR   t   print_resultsR   R   (   R   t   optionsR   t   queryt	   pypi_hitst   hitsR   (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyt   run'   s    c         C@  sj   | j  } |  j |  L } t | |  } t j | |  } | j i | d 6| d 6d  } | SWd  QXd  S(   Nt   namet   summaryt   or(   R   t   _build_sessionR   R
   t   ServerProxyR   (   R   R%   R$   t	   index_urlt   sessiont	   transportt   pypiR'   (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyR   7   s    	 (	   t   __name__t
   __module__t   __doc__R)   t   usageR*   R   R(   R   (    (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyR      s   		c         C@  s  i  } x |  D] } | d } | d } | d } | d } | d k rP d } n  | | j   k r i | d 6| d 6| g d 6| d 6| | <q | | d j |  | t | | d  k r | | | d <| | | d <q q Wt | j   d d	   d
 t } | 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   _pypi_orderingi    t   versionst   scoret   keyc         S@  s   |  d S(   NR9   (    (   t   x(    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyt   <lambda>b   s    t   reverseN(   R   t   keyst   appendt   highest_versiont   sortedt   valuest   True(   R'   t   packagest   hitR)   R*   R6   R9   t   package_list(    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyR   @   s.    



	
		c      	   C@  s  |  s
 d  S| d  k r3 t d   |  D  d } n  g  t j D] } | j ^ q= } x0|  D](} | d } | d pv d } | d  k	 r t j | | | d  } d d | d	 j |  } n  d
 | j |  | f } y t	 j
 |  | | k rlt j |  }	 t   ] t | d  }
 |	 j |
 k r@t	 j
 d |	 j  n# t	 j
 d |	 j  t	 j
 d |
  Wd  QXn  WqY t k
 rqY XqY Wd  S(   Nc         s@  s   |  ] } t  | d   Vq d S(   R)   N(   t   len(   t   .0RE   (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pys	   <genexpr>l   s    i   R)   R*   t    i   s   
t    i   s   %s - %sR8   s   INSTALLED: %s (latest)s   INSTALLED: %ss   LATEST:    %s(   R   t   maxR	   t   working_sett   project_namet   textwrapt   wrapt   joint   ljustt   loggert   infot   get_distributionR   R@   R6   t   UnicodeEncodeError(   R'   t   name_column_widthR   t   pt   installed_packagesRE   R)   R*   t   linet   distt   latest(    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyR#   h   s4    

c         C@  s%   t  t t |  d t j d t   S(   NR:   R=   (   t   nextt   iterRA   R	   t   parse_versionRC   (   R8   (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyR@      s    (    t
   __future__R    t   loggingR    RN   t   pip.basecommandR   R   t   pip.downloadR   t	   pip.indexR   t	   pip.utilsR   t   pip.utils.loggingR   t   pip.exceptionsR   t   pip.status_codesR   t   pip._vendorR	   t   pip._vendor.six.movesR
   t	   getLoggerR2   RR   R   R   R   R#   R@   (    (    (    s0   /tmp/pip-build-5Z5nTX/pip/pip/commands/search.pyt   <module>   s"   +	( 