ó
~¾^Yc           @@  s4  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 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   OrderedDict(   t   PipXmlrpcTransport(   t   PyPI(   t   get_terminal_size(   t
   indent_log(   t   CommandError(   t   NO_MATCHES_FOUND(   t   parse(   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@  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(    (    s0   /tmp/pip-build-QubATO/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-QubATO/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-QubATO/pip/pip/commands/search.pyR   9   s    	 (	   t   __name__t
   __module__t   __doc__R+   t   usageR,   R   R*   R   (    (    (    s0   /tmp/pip-build-QubATO/pip/pip/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,   R8   (    (    s0   /tmp/pip-build-QubATO/pip/pip/commands/search.pyR    B   s    	


c         C@  së  |  s
 d  S| d  k rc t g  |  D]3 } t | d ƒ t | j d d g ƒ d ƒ ^ q  ƒ d } n  g  t j D] } | j ^ qm } xb|  D]Z} | d } | d p¦ d } | j d d g ƒ d } | d  k	 r| | d }	 |	 d	 k rt j | |	 ƒ } d
 d | d j	 | ƒ } qn  d | d | | f | f }
 y— t
 j |
 ƒ | | k rÎt j | ƒ } t ƒ  ] t | d ƒ } | j | k r¢t
 j d | j ƒ n# t
 j d | j ƒ t
 j d | ƒ Wd  QXn  Wq‰ t k
 râq‰ Xq‰ Wd  S(   NR+   R9   t   -iÿÿÿÿi   R,   t    i   i
   s   
t    i   s	   %-*s - %ss   %s (%s)s   INSTALLED: %s (latest)s   INSTALLED: %ss   LATEST:    %s(   R!   t   maxt   lent   getR   t   working_sett   project_namet   textwrapt   wrapt   joint   loggert   infot   get_distributionR   R<   R8   t   UnicodeEncodeError(   R)   t   name_column_widthR   R@   t   pt   installed_packagesR+   R,   R8   t   target_widtht   linet   distt   latest(    (    s0   /tmp/pip-build-QubATO/pip/pip/commands/search.pyR%   ^   s>    =

!
c         C@  s   t  |  d t ƒS(   Nt   key(   RD   t   parse_version(   R9   (    (    s0   /tmp/pip-build-QubATO/pip/pip/commands/search.pyR<   „   s    (%   t
   __future__R    t   loggingR"   RI   t   pip.basecommandR   R   t
   pip.compatR   t   pip.downloadR   t
   pip.modelsR   t	   pip.utilsR   t   pip.utils.loggingR   t   pip.exceptionsR   t   pip.status_codesR	   t   pip._vendor.packaging.versionR
   RX   t   pip._vendorR   t   pip._vendor.six.movesR   t	   getLoggerR4   RL   R   R    R!   R%   R<   (    (    (    s0   /tmp/pip-build-QubATO/pip/pip/commands/search.pyt   <module>   s&   +	&