3

Q'íc–ã@säddlmZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZejeƒZGdd„deƒZ dd„Z!ddd„Z"dd„Z#dS)é)Úabsolute_importN)ÚCommandÚSUCCESS)ÚOrderedDict)ÚPipXmlrpcTransport)ÚPyPI)Úget_terminal_size)Ú
indent_log)ÚCommandError)ÚNO_MATCHES_FOUND)Úparse)Ú
pkg_resources)Ú
xmlrpc_clientcs<eZdZdZdZdZdZ‡fdd„Zdd„Zd	d
„Z	‡Z
S)Ú
SearchCommandz@Search for PyPI packages whose name or summary contains <query>.Úsearchz
      %prog [options] <query>zSearch PyPI for packages.cs@tt|ƒj||Ž|jjddddtjdd|jjd|jƒdS)Nz-iz--indexÚindexÚURLz3Base URL of Python Package Index (default %default))ÚdestÚmetavarÚdefaultÚhelpr)	ÚsuperrÚ__init__Úcmd_optsÚ
add_optionrÚpypi_urlÚparserÚinsert_option_group)ÚselfÚargsÚkw)Ú	__class__©ú2/tmp/pip-build-l_bcah40/pip/pip/commands/search.pyrszSearchCommand.__init__cCsT|stdƒ‚|}|j||ƒ}t|ƒ}d}tjjƒr<tƒd}t||d|rPtSt	S)Nz)Missing required argument (search query).r)Úterminal_width)
r
rÚtransform_hitsÚsysÚstdoutÚisattyrÚ
print_resultsrr)rÚoptionsrÚqueryÚ	pypi_hitsÚhitsr$r"r"r#Úrun)s

zSearchCommand.runcCsH|j}|j|ƒ.}t||ƒ}tj||ƒ}|j||dœdƒ}|SQRXdS)N)ÚnameÚsummaryÚor)rÚ_build_sessionrrÚServerProxyr)rr+r*Ú	index_urlÚsessionÚ	transportÚpypir-r"r"r#r9s
zSearchCommand.search)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/Úusager0rr.rÚ
__classcell__r"r")r!r#rsrcCsŠtƒ}xv|D]n}|d}|d}|d}||jƒkrH|||gdœ||<q||dj|ƒ|t||dƒkr|||d<qWt|jƒƒS)z¼
    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/r0Úversion)r/r0Úversionsr?)rÚkeysÚappendÚhighest_versionÚlistÚvalues)r-ÚpackagesÚhitr/r0r>r"r"r#r%Bs
r%cCsT|sdS|dkr&tdd„|Dƒƒd}dd„tjDƒ}x|D]}|d}|dpVd}|jdd	gƒd}|dk	r¨||d}|dkr¨tj||ƒ}d
d|dj|ƒ}d|d||f|f}	yvtj|	ƒ||kr2tj	|ƒ}
t
ƒHt|dƒ}|
j|krtjd|
jƒntjd|
jƒtjd|ƒWdQRXWq>t
k
rJYq>Xq>WdS)NcSs.g|]&}t|dƒt|jddgƒdƒ‘qS)r/r?ú-ééÿÿÿÿ)ÚlenÚget)Ú.0rFr"r"r#ú
<listcomp>csz!print_results.<locals>.<listcomp>écSsg|]
}|j‘qSr")Úproject_name)rLÚpr"r"r#rMgsr/r0Úr?rGrHéé
Ú
ú éz	%-*s - %sz%s (%s)zINSTALLED: %s (latest)z
INSTALLED: %sz
LATEST:    %srI)Úmaxr
Úworking_setrKÚtextwrapÚwrapÚjoinÚloggerÚinfoÚget_distributionr	rBr>ÚUnicodeEncodeError)r-Úname_column_widthr$Úinstalled_packagesrFr/r0r>Útarget_widthÚlineÚdistÚlatestr"r"r#r)^s>


r)cCst|tdS)N)Úkey)rWÚ
parse_version)r?r"r"r#rB„srB)NN)$Ú
__future__rÚloggingr&rYÚpip.basecommandrrÚ
pip.compatrÚpip.downloadrÚ
pip.modelsrÚ	pip.utilsrÚpip.utils.loggingr	Úpip.exceptionsr
Úpip.status_codesrZpip._vendor.packaging.versionrrgÚpip._vendorr
Zpip._vendor.six.movesrÚ	getLoggerr8r\rr%r)rBr"r"r"r#Ú<module>s&
+
&