U
    kuf                     @   sX   d dl m Z  d dlZd dlZddlmZ dd Zddd	ZdddZG dd de	Z
dS )    )datetimeN   )	HTTPErrorc                 C   sj   t | }|jdkr$t|j|jdt|jdrFtjj	
|j }ntjj	
|j}|d}|dS )zE
    Query the PyPI RSS feed and return a list
    of XML items.
    i,  )status_codereasondecodechannelitem)requestsgetr   r   r   hasattrcontentxmletreeElementTree
fromstringr   findfindall)pypi_serverresponsetreer    r   ./tmp/pip-unpacked-wheel-pz57x_63/yarg/parse.py_get!   s    


r   3https://pypi.python.org/pypi?%3Aaction=packages_rssc                 C   sV   t | }g }|D ]@}|d j d |d j|d j|d jd}|t| q|S )a  
    Constructs a request to the PyPI server and returns a list of
    :class:`yarg.parse.Package`.

    :param pypi_server: (option) URL to the PyPI server.

        >>> import yarg
        >>> yarg.newest_packages()
        [<Package yarg>, <Package gray>, <Package ragy>]
    r   r         )nameurldescriptiondater   textsplitappendPackage)r   itemsir	   i_dictr   r   r   newest_packages2   s    r)   *https://pypi.python.org/pypi?%3Aaction=rssc                 C   s\   t | }g }|D ]F}|d j \}}|||d j|d j|d jd}|t| q|S )a  
    Constructs a request to the PyPI server and returns a list of
    :class:`yarg.parse.Package`.

    :param pypi_server: (option) URL to the PyPI server.

        >>> import yarg
        >>> yarg.latest_updated_packages()
        [<Package yarg>, <Package gray>, <Package ragy>]
    r   r      r   )r   versionr   r   r    r!   )r   r&   r'   r	   r   r,   r(   r   r   r   latest_updated_packagesI   s    r-   c                   @   s\   e Zd ZdZdd Zdd Zedd Zedd	 Zed
d Z	edd Z
edd ZdS )r%   z
    A PyPI package generated from the RSS feed information.

    :param pypi_dict: A dictionary retrieved from the PyPI server.
    c                 C   s
   || _ d S )N_content)selfZ	pypi_dictr   r   r   __init__i   s    zPackage.__init__c                 C   s   d | jS )Nz<Package {0}>)formatr   r0   r   r   r   __repr__l   s    zPackage.__repr__c                 C   s
   | j d S )
            >>> package = yarg.newest_packages()[0]
            >>> package.name
            u'yarg'
            >>> package = yarg.latest_updated_packages()[0]
            >>> package.name
            u'yarg'
        r   r.   r3   r   r   r   r   o   s    
zPackage.namec                 C   s   d| j krdS | j d S )r5   r,   Nr.   r3   r   r   r   r,   {   s    

zPackage.versionc                 C   s
   | j d S )a  
        This is only available for :meth:`yarg.latest_updated_packages`, for
        :meth:`yarg.newest_packages` will return `None`

            >>> package = yarg.latest_updated_packages()[0]
            >>> package.url
            u'http://pypi.python.org/pypi/yarg'
        r   r.   r3   r   r   r   r      s    
zPackage.urlc                 C   s   t | jd dS )a  
            >>> package = yarg.newest_packages()[0]
            >>> package.date
            datetime.datetime(2014, 8, 9, 8, 40, 20)
            >>> package = yarg.latest_updated_packages()[0]
            >>> package.date
            datetime.datetime(2014, 8, 9, 8, 40, 20)
        r    z%d %b %Y %H:%M:%S %Z)r   strptimer/   r3   r   r   r   r       s    
zPackage.datec                 C   s
   | j d S )a  
            >>> package = yarg.newest_packages()[0]
            >>> package.description
            u'Some random summary stuff'
            >>> package = yarg.latest_updated_packages()[0]
            >>> package.description
            u'Some random summary stuff'
        r   r.   r3   r   r   r   r      s    
zPackage.descriptionN)__name__
__module____qualname____doc__r1   r4   propertyr   r,   r   r    r   r   r   r   r   r%   b   s   



r%   )r   )r*   )r   xml.etree.ElementTreer   r
   
exceptionsr   r   r)   r-   objectr%   r   r   r   r   <module>   s    
 
