
`]c           @  s  d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z yz e Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m  Z  d d l! m" Z" d d	 l# m$ Z$ Wn e% k
 rSe& Z e' Z n Xd d
 l( m) Z) m* Z* d d l+ m, Z, d d l- m. Z. d d l/ m0 Z0 m1 Z1 d d l2 Z2 d d l3 m4 Z4 e4 d e5 f d     Y Z6 e4 d e5 f d     Y Z7 d e5 f d     YZ8 d e8 f d     YZ9 d e8 f d     YZ: d e8 f d     YZ; d e8 f d     YZ< d e8 f d     YZ= d e8 f d      YZ> d! e8 f d"     YZ? d# e8 f d$     YZ@ d% e8 f d&     YZA d' e8 f d(     YZB d) e8 f d*     YZC d+ e8 f d,     YZD d- e8 f d.     YZE d/ e5 f d0     YZF d1 e5 f d2     YZG d3 e5 f d4     YZH d5   ZI d6   ZJ e d7  ZK e d8  ZL d9   ZM d: d;  ZN d<   ZO d=   ZP d>   ZQ d?   ZR eF   ZS eS jT ZT d@   ZU dA   ZV dB   ZW eX dC k rd dD lY mZ ZZ eZ   Z[ e[ j\ dE dF dG dH dI dJ dK dL e[ j\ dM dN dG dO dP dQ dR e& dI dS e[ j\ dT dU dG dV dP dQ dR e& dI dW e[ j\ dX dY dG dZ dP dQ dR e& dI d[ e[ j\ d\ d] dG d^ dR e j] j^ d_  dI d` e[ j_   \ Z` Za eF da e` jb  Zc ea rtx] ea D]U Zd ec jT db ed dc e` je dd e` jf de e` jg df e` jh  Zi ei e& k ofe` jh rmPn  qWn. ec jT dc e` je dd e` jf de e` jg df e` jh  n  d S(g   uH	  
The NLTK corpus and module downloader.  This module defines several
interfaces which can be used to download corpora, models, and other
data packages that can be used with NLTK.

Downloading Packages
====================
If called with no arguments, ``download()`` will display an interactive
interface which can be used to download and install new packages.
If Tkinter is available, then a graphical interface will be shown,
otherwise a simple text interface will be provided.

Individual packages can be downloaded by calling the ``download()``
function with a single argument, giving the package identifier for the
package that should be downloaded:

    >>> download('treebank') # doctest: +SKIP
    [nltk_data] Downloading package 'treebank'...
    [nltk_data]   Unzipping corpora/treebank.zip.

NLTK also provides a number of "package collections", consisting of
a group of related packages.  To download all packages in a
colleciton, simply call ``download()`` with the collection's
identifier:

    >>> download('all-corpora') # doctest: +SKIP
    [nltk_data] Downloading package 'abc'...
    [nltk_data]   Unzipping corpora/abc.zip.
    [nltk_data] Downloading package 'alpino'...
    [nltk_data]   Unzipping corpora/alpino.zip.
      ...
    [nltk_data] Downloading package 'words'...
    [nltk_data]   Unzipping corpora/words.zip.

Download Directory
==================
By default, packages are installed in either a system-wide directory
(if Python has sufficient access to write to it); or in the current
user's home directory.  However, the ``download_dir`` argument may be
used to specify a different installation target, if desired.

See ``Downloader.default_download_dir()`` for more a detailed
description of how the default download directory is chosen.

NLTK Download Server
====================
Before downloading any packages, the corpus and module downloader
contacts the NLTK download server, to retrieve an index file
describing the available packages.  By default, this index file is
loaded from ``https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml``.
If necessary, it is possible to create a new ``Downloader`` object,
specifying a different URL for the package index file.

Usage::

    python nltk/downloader.py [-d DATADIR] [-q] [-f] [-k] PACKAGE_IDS

or::

    python -m nltk.downloader [-d DATADIR] [-q] [-f] [-k] PACKAGE_IDS
i(   t   print_functiont   divisiont   unicode_literalsN(   t   md5(   t   ElementTree(	   t   Tkt   Framet   Labelt   Entryt   Buttont   Canvast   Menut   IntVart   TclError(   t	   showerror(   t   Table(   t   ShowText(   t   string_typest	   text_type(   t   input(   t   urlopen(   t	   HTTPErrort   URLError(   t   python_2_unicode_compatiblet   Packagec           B  sY   e  Z d  Z d d d d d d d d d d e d  Z e d    Z d   Z d   Z	 RS(   u4  
    A directory entry for a downloadable package.  These entries are
    extracted from the XML index file that is downloaded by
    ``Downloader``.  Each package consists of a single file; but if
    that file is a zip file, then it can be automatically decompressed
    when the package is installed.
    u    u   Unknownc         K  s   | |  _  | p | |  _ | |  _ | |  _ t |  |  _ t |  |  _ | |  _ | |  _ |	 |  _	 |
 |  _
 | |  _ | |  _ t j j | j d  d  d } t j j | | |  |  _ t t |   |  _ |  j j |  d  S(   Nu   /ii   (   t   idt   namet   subdirt   urlt   intt   sizet   unzipped_sizet   checksumt   svn_revisiont	   copyrightt   contactt   licenset   authort   ost   patht   splitextt   splitt   joint   filenamet   boolt   unzipt   __dict__t   update(   t   selfR   R   R   R   R   R   R    R!   R"   R#   R$   R%   R-   t   kwt   ext(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   __init__   s     									#c         C  s\   t  |  t  r! t j |   }  n  x+ |  j D]  } t |  j |  |  j | <q+ Wt |  j   S(   N(   t
   isinstanceR   R   t   parset   attribR   R   (   t   xmlt   key(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   fromxml  s
    c         C  s   |  j  | j  k  S(   N(   R   (   R0   t   other(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   __lt__"  s    c         C  s   d |  j  S(   Nu   <Package %s>(   R   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   __repr__%  s    N(
   t   __name__t
   __module__t   __doc__t   Nonet   TrueR3   t   staticmethodR9   R;   R<   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR      s   7	t
   Collectionc           B  s;   e  Z d  Z d d  Z e d    Z d   Z d   Z RS(   u   
    A directory entry for a collection of downloadable packages.
    These entries are extracted from the XML index file that is
    downloaded by ``Downloader``.
    c         K  s>   | |  _  | p | |  _ | |  _ d  |  _ |  j j |  d  S(   N(   R   R   t   childrenR@   t   packagesR.   R/   (   R0   R   RD   R   R1   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   1  s
    			c         C  s   t  |  t  r! t j |   }  n  x+ |  j D]  } t |  j |  |  j | <q+ Wg  |  j d  D] } | j d  ^ q_ } t d | |  j  S(   Nu   itemu   refRD   (	   R4   R   R   R5   R6   R   t   findallt   getRC   (   R7   R8   t   childRD   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR9   C  s    +c         C  s   |  j  | j  k  S(   N(   R   (   R0   R:   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR;   L  s    c         C  s   d |  j  S(   Nu   <Collection %s>(   R   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR<   O  s    N(	   R=   R>   R?   R@   R3   RB   R9   R;   R<   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRC   )  s
   		t   DownloaderMessagec           B  s   e  Z d  Z RS(   uV   A status message object, used by ``incr_download`` to
       communicate its progress.(   R=   R>   R?   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRI   X  s   t   StartCollectionMessagec           B  s   e  Z d  Z d   Z RS(   u<   Data server has started working on a collection of packages.c         C  s   | |  _  d  S(   N(   t
   collection(   R0   RK   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   `  s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRJ   ]  s   t   FinishCollectionMessagec           B  s   e  Z d  Z d   Z RS(   u=   Data server has finished working on a collection of packages.c         C  s   | |  _  d  S(   N(   RK   (   R0   RK   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   g  s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRL   d  s   t   StartPackageMessagec           B  s   e  Z d  Z d   Z RS(   u-   Data server has started working on a package.c         C  s   | |  _  d  S(   N(   t   package(   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   n  s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRM   k  s   t   FinishPackageMessagec           B  s   e  Z d  Z d   Z RS(   u.   Data server has finished working on a package.c         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   u  s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRO   r  s   t   StartDownloadMessagec           B  s   e  Z d  Z d   Z RS(   u.   Data server has started downloading a package.c         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   |  s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRP   y  s   t   FinishDownloadMessagec           B  s   e  Z d  Z d   Z RS(   u/   Data server has finished downloading a package.c         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRQ     s   t   StartUnzipMessagec           B  s   e  Z d  Z d   Z RS(   u,   Data server has started unzipping a package.c         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRR     s   t   FinishUnzipMessagec           B  s   e  Z d  Z d   Z RS(   u-   Data server has finished unzipping a package.c         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRS     s   t   UpToDateMessagec           B  s   e  Z d  Z d   Z RS(   u/   The package download file is already up-to-datec         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRT     s   t   StaleMessagec           B  s   e  Z d  Z d   Z RS(   u3   The package download file is out-of-date or corruptc         C  s   | |  _  d  S(   N(   RN   (   R0   RN   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRU     s   t   ErrorMessagec           B  s   e  Z d  Z d   Z RS(   u    Data server encountered an errorc         C  s7   | |  _  t | t  r* t |  |  _ n	 | |  _ d  S(   N(   RN   R4   t	   Exceptiont   strt   message(   R0   RN   RY   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    	(   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRV     s   t   ProgressMessagec           B  s   e  Z d  Z d   Z RS(   u4   Indicates how much progress the data server has madec         C  s   | |  _  d  S(   N(   t   progress(   R0   R[   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRZ     s   t   SelectDownloadDirMessagec           B  s   e  Z d  Z d   Z RS(   u:   Indicates what download directory the data server is usingc         C  s   | |  _  d  S(   N(   t   download_dir(   R0   R]   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    (   R=   R>   R?   R3   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR\     s   t
   Downloaderc        	   B  s  e  Z d  Z d$ Z d Z d Z d Z d Z d Z d% d% d  Z
 d% e e e e e d  Z d	   Z d
   Z d   Z d   Z d   Z d% e d  Z d   Z d   Z d   Z d% d% e e d e e e j d  Z d% d  Z d% d  Z d% d  Z d% d  Z d   Z e d d  Z d% d  Z  d   Z! d   Z" d   Z# d   Z$ d   Z% e& e$ e%  Z' d    Z( d!   Z) d"   Z* e& e) e*  Z+ d#   Z, RS(&   uy   
    A class used to access the NLTK data server, which can be used to
    download corpora and other data packages.
    i<   uC   https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xmlu	   installedu   not installedu   out of dateu   partialc         C  sv   | p |  j  |  _ i  |  _ i  |  _ | |  _ d  |  _ d  |  _ i  |  _ d  |  _	 |  j d  k rr |  j
   |  _ n  d  S(   N(   t   DEFAULT_URLt   _urlt   _collectionst	   _packagest   _download_dirR@   t   _indext   _index_timestampt   _status_cachet   _errorst   default_download_dir(   R0   t   server_index_urlR]   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3     s    							c         C  s  d } | d  k r, |  j } t d |  n  | r t d d t |  j   t d |  j  t d d t |  j   | d 7} n  t } }	 g  }
 | r |
 j d  n  | r |
 j d  n  x|
 D]} t d	 | j    | d
 7} xet t	 |  |    d t
 D]E} |  j | |  } | |  j k r?| r?qn  | |  j k rWt } n  | |  j k rot }	 n  i d |  j 6d |  j 6d |  j 6d |  j 6| } t j d d | j p| j d d d d d } t d | | j j d d  | f  | t | j d   7} | r| d k rt d  } | j   d  k rHd  Sd } qqWt   q Wd } | ry| d 7} n  |	 r| d 7} n  t t j | d d d d d  d  S(!   Ni    u!   Using default data directory (%s)u   =i   u    Data server index for <%s>i   u   packagesu   collectionsu   %s:i   R8   u   *u   -u   Pu    i   iK   t   subsequent_indentu     [%s] %s %si   u   .u   
u   Hit Enter to continue: u   xu   qu   ([*] marks installed packagesu+   ; [-] marks out-of-date or corrupt packagesu+   ; [P] marks partially installed collectionsu   )t   widthiL   (   u   xu   q(   R@   Rc   t   printt   lenR`   t   Falset   appendt
   capitalizet   sortedt   getattrRX   t   statust	   INSTALLEDt   STALERA   t   PARTIALt   NOT_INSTALLEDt   textwrapt   fillR   R   t   ljustR)   R   t   lower(   R0   R]   t   show_packagest   show_collectionst   headert   more_promptt   skip_installedt   linest   stalet   partialt
   categoriest   categoryt   infoRs   t   prefixR   t
   user_inputt   msg(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   list  sb    		

%		



'&c         C  s   |  j    |  j j   S(   N(   t   _update_indexRb   t   values(   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRE   K  s    
c         C  s?   |  j    g  |  j j   D]! \ } } | j d k r | ^ q S(   Nu   corpora(   R   Rb   t   itemsR   (   R0   R   t   pkg(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   corporaO  s    
c         C  s?   |  j    g  |  j j   D]! \ } } | j d k r | ^ q S(   Nu   corpora(   R   Rb   R   R   (   R0   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   modelsS  s    
c         C  s   |  j    |  j j   S(   N(   R   Ra   R   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   collectionsW  s    
c         C  s$   t  | t  r |  j |  S| Sd  S(   N(   R4   R   R   (   R0   t
   info_or_id(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _info_or_id_  s    c         c  s"  | d  k r# |  j } t |  Vn  t | t t f  ra x" |  j | | |  D] } | VqN Wd  Sy |  j |  } Wn2 t t	 f k
 r } t
 d  d | | f  Vd  SXt | t  r t |  Vx% |  j | j | |  D] } | Vq Wt |  Vn% x" |  j | | |  D] } | VqWd  S(   Nu   Error loading %s: %s(   R@   Rc   R\   R4   R   t   tuplet   _download_listR   t   IOErrort
   ValueErrorRV   RC   RJ   t   incr_downloadRD   RL   t   _download_package(   R0   R   R]   t   forceR   R   t   e(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   n  s&    			c         C  s$   t  | t  r d St | j  Sd  S(   Ni   (   R4   R   Rm   RE   (   R0   t   item(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _num_packages  s    c         #  s4  xd t  t |   D]P } y   j | |  | | <Wq t t f k
 rb } t | | |  Vd  SXq Wt   f d   | D  } d } x t |  D] \ } } t | t	  r d | }	 n t | j
  | }	 xJ   j | | |  D]3 }
 t |
 t  rt | |
 j |	  Vq |
 Vq W| d |	 7} q Wd  S(   Nc         3  s   |  ] }   j  |  Vq d  S(   N(   R   (   t   .0R   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>  s    i    g      ?id   (   t   rangeRm   R   R   R   RV   t   sumt	   enumerateR4   R   RE   R   RZ   R[   (   R0   R   R]   R   t   iR   t   num_packagesR[   R   t   deltaR   (    (   R0   s.   lib/python2.7/site-packages/nltk/downloader.pyR     s"    		c         c  s  t  |  Vt d  V|  j | |  } | rc | |  j k rc t |  Vt d  Vt |  Vd  S|  j j | j d   t
 j j | | j  } t
 j j |  r | |  j k r t |  Vn  t
 j |  n  t
 j j |  s t
 j |  n  t
 j j t
 j j | | j   s8t
 j t
 j j | | j   n  t |  Vt d  Vy t | j  } t | d   } t d | j d  } xm t j   D]_ }	 | j d  }
 | j |
  |
 sPn  |	 d d k rt t d	 d d
 |	 |   VqqWWd  QX| j   Wn5 t  k
 r@} t! | d | j | j | f  Vd  SXt" |  Vt d	  V| j j# d  rt
 j j | | j  } | j$ st
 j j t
 j j | | j   rt% |  Vx+ t& | | d t' D] } | | _( | VqWt) |  Vqn  t |  Vd  S(   Ni    id   i   u   wbi   i   i   i   iP   iK   u$   Error downloading %r from <%s>:
  %su   .zipt   verbosei @  i @  (*   RM   RZ   Rs   Rt   RT   RO   Rf   t   popR   R@   R&   R'   R*   R+   t   existsRu   RU   t   removet   mkdirR   RP   R   R   t   opent   maxR   t	   itertoolst   countt   readt   writet   mint   closeR   RV   RQ   t   endswithR-   RR   t   _unzip_iterRn   RN   RS   (   R0   R   R]   R   Rs   t   filepatht   infilet   outfilet
   num_blockst   blockt   sR   t   zipdirR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s`    $"--		u   [nltk_data] c	      	     sl  t  j t d |  | d  k rG | d  k	 r9 | |  _ n  |  j   t Sd    f d  }	 x	|  j | | |  D]}
 t |
 t	  r.|	 |
 j
  | r t |
 j
   n  | r t St |  _ | s. d  t   j   } | d k r|  j |
 j j | | |   | |  s(t Sq+| d k r+t Sq.n  | sr t |
 t  rn|	 d	 |
 j j    d
 7      qdt |
 t  r      d    |  j r|	 d |
 j j  qa|	 d |
 j j  qdt |
 t  r|	 d |
 j j | f  qdt |
 t  r|	 d |
 j j d  qdt |
 t  rF|	 d |
 j j d  qdt |
 t  rd|
 j } qdqr qr Wt S(   Nt   fileu    c      	     s/    t  j |  d   | d   | d  d  S(   Nt   initial_indentRj   u    i   u       (   Rx   Ry   (   R   t   prefix2(   R   t   print_to(    s.   lib/python2.7/site-packages/nltk/downloader.pyt   show
  s
    
u(   Error installing package. Retry? [n/y/e]u   yu   Yu   eu   Eu   Downloading collection %ru      | iu$   Downloaded collection %r with errorsu   Done downloading collection %su   Downloading package %s to %s...u!   Package %s is already up-to-date!u     u   Unzipping %s.(   u   yu   Y(   u   eu   E(   t	   functoolsR   Rl   R@   Rc   t   _interactive_downloadRA   R   R4   RV   RY   R   Rn   Rg   R   t   stript   downloadRN   R   RJ   RK   RL   RM   RT   RR   R+   R\   R]   (   R0   R   R]   t   quietR   R   t   halt_on_errort   raise_on_errort   print_error_toR   R   t   choice(    (   R   R   s.   lib/python2.7/site-packages/nltk/downloader.pyR     sl    
		
		



	c         C  s   |  j  | |  |  j k S(   N(   Rs   Ru   (   R0   R   R]   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   is_staleR  s    c         C  s   |  j  | |  |  j k S(   N(   Rs   Rt   (   R0   R   R]   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   is_installedU  s    c         C  s3   | d  k r |  j j   n |  j j | d   d  S(   N(   R@   Rf   t   clearR   (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   clear_status_cacheX  s    c         C  sI  | d k r |  j } n  |  j |  } t | t  r g  | j D] } |  j | j  ^ q@ } |  j | k rt |  j S|  j	 | k r |  j	 S|  j
 | k r |  j | k r |  j	 S|  j | k r |  j S|  j
 Snv t j j | | j  } | |  j k r|  j | |  S| j |  j k r7|  j | |  |  j | j <n  |  j | j Sd S(   u   
        Return a constant describing the status of the given package
        or collection.  Status can be one of ``INSTALLED``,
        ``NOT_INSTALLED``, ``STALE``, or ``PARTIAL``.
        N(   R@   Rc   R   R4   RC   RE   Rs   R   Ru   Rv   Rt   Rw   R&   R'   R*   R+   t   _pkg_statusRf   (   R0   R   R]   R   R   t
   pkg_statusR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRs   ^  s(    (
c         C  s	  t  j j |  s |  j Sy t  j |  } Wn t k
 rC |  j SX| j t | j  k rc |  j	 St
 |  | j k r |  j	 S| j d  r| d  } t  j j |  s |  j St  j j |  s |  j	 St d   t  j |  D  } | | j k r|  j	 Sn  |  j S(   Nu   .zipic         s  sF   |  ]< \ } } } | D]& } t  j t  j j | |   j Vq q d  S(   N(   R&   t   statR'   R*   t   st_size(   R   t   dt   _t   filest   f(    (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>  s   (   R&   R'   R   Rw   R   t   OSErrorR   R   R   Ru   t   md5_hexdigestR    R   Rt   t   isdirR   t   walkR   (   R0   R   R   t   filestatt   unzipdirR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s,    

c         C  sY   |  j    xH |  j   D]: } |  j |  |  j k r |  j | d | d | q q Wd S(   uA   
        Re-download any packages whose status is STALE.
        R   R   N(   R   RE   Rs   Ru   R   (   R0   R   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR/     s    
c         C  sU  |  j  d k p4 | d k	 p4 t j   |  j |  j k s; d S| pG |  j |  _ t j j t	 j
 t |  j   j    |  _  t j   |  _ g  |  j  j d  D] } t j |  ^ q } t d   | D  |  _ g  |  j  j d  D] } t j |  ^ q } t d   | D  |  _ x |  j j   D] } x t | j  D]u \ } } | |  j k ro|  j | | j | <q=| |  j k r|  j | | j | <q=t d j |   | j | =q=Wq'Wx |  j j   D]v } i  } | g }	 xO |	 D]G }
 t |
 t  r|	 j |
 j  qt |
 t  r|
 | |
 j <qqW| j   | _ qW|  j j   d S(   u   A helper function that ensures that self._index is
        up-to-date.  If the index is older than self.INDEX_TIMEOUT,
        then download it again.Nu   packages/packagec         s  s   |  ] } | j  | f Vq d  S(   N(   R   (   R   t   p(    (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>  s    u   collections/collectionc         s  s   |  ] } | j  | f Vq d  S(   N(   R   (   R   t   c(    (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>  s    u.   removing collection member with no package: {}(   Rd   R@   t   timeRe   t   INDEX_TIMEOUTR`   t   nltkt	   internalst   ElementWrapperR   R5   R   t   getrootRF   R   R9   t   dictRb   RC   Ra   R   R   RD   Rl   t   formatR4   t   extendR   RE   Rf   R   (   R0   R   R   RE   R   R   RK   R   t   child_idt   queueRH   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     sB    	$..
	c         C  s   |  j    |  j S(   u   
        Return the XML index describing the packages available from
        the data server.  If necessary, this index will be downloaded
        from the data server.
        (   R   Rd   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   index  s    
c         C  sR   |  j    | |  j k r$ |  j | S| |  j k r> |  j | St d |   d S(   uN   Return the ``Package`` or ``Collection`` record for the
           given item.u   Package %r not found in indexN(   R   Rb   Ra   R   (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    
c         C  s   |  j    x3 |  j j d  D] } | j d  | k r | Sq Wx3 |  j j d  D] } | j d  | k rS | SqS Wt d |   d S(   u-   Return the XML info record for the given itemu   packages/packageu   idu   collections/collectionu   Package %r not found in indexN(   R   Rd   RF   RG   R   (   R0   R   RN   RK   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   xmlinfo  s    
c         C  s   |  j  S(   u)   The URL for the data server's index file.(   R`   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _get_url  s    c         C  s4   |  j  } y |  j |  Wn | |  _    n Xd S(   u   
        Set a new URL for the data server. If we're unable to contact
        the given url, then the original url is kept.
        N(   R`   R   (   R0   R   t   original_url(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _set_url  s    		c         C  s   d t  j k r d Sx< t j j D]. } t  j j |  r  t j j |  r  | Sq  Wt j	 d k r d t  j k r t  j d } n- t  j j
 d  } | d k r t d   n  t  j j | d  S(   u  
        Return the directory to which packages will be downloaded by
        default.  This value can be overridden using the constructor,
        or on a case-by-case basis using the ``download_dir`` argument when
        calling ``download()``.

        On Windows, the default download directory is
        ``PYTHONHOME/lib/nltk``, where *PYTHONHOME* is the
        directory containing Python, e.g. ``C:\Python25``.

        On all other platforms, the default directory is the first of
        the following which exists or which can be created with write
        permission: ``/usr/share/nltk_data``, ``/usr/local/share/nltk_data``,
        ``/usr/lib/nltk_data``, ``/usr/local/lib/nltk_data``, ``~/nltk_data``.
        u   APPENGINE_RUNTIMENu   win32u   APPDATAu   ~/u+   Could not find a default download directoryu	   nltk_data(   R&   t   environR   t   dataR'   R   R   t   is_writablet   syst   platformt
   expanduserR   R*   (   R0   t   nltkdirt   homedir(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRh   #  s    $c         C  s   |  j  S(   u  
        The default directory to which packages will be downloaded.
        This defaults to the value returned by ``default_download_dir()``.
        To override this default on a case-by-case basis, use the
        ``download_dir`` argument when calling ``download()``.
        (   Rc   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _get_download_dirJ  s    c         C  s   | |  _  |  j j   d  S(   N(   Rc   Rf   R   (   R0   R]   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _set_download_dirS  s    	c         C  sU   t  rA y t |   j   WqQ t k
 r= t |   j   qQ Xn t |   j   d  S(   N(   t   TKINTERt   DownloaderGUIt   mainloopR   t   DownloaderShellt   run(   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   ^  s    i  N(-   R=   R>   R?   R   R_   Rt   Rw   Ru   Rv   R@   R3   RA   Rn   R   RE   R   R   R   R   R   R   R   R   R   t   stderrR   R   R   R   Rs   R   R/   R   R   R   R   R   R   t   propertyR   Rh   R   R   R]   R   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR^     sb   	'5								GX"	$>			
				'			R   c           B  sP   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   c         C  s   | |  _  d  S(   N(   t   _ds(   R0   t
   dataserver(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   k  s    c         G  sc   t  d d  d t d   | D  t |  d d } t  d | j |   t  d d  d  S(   Nu   -iK   iD   c         s  s   |  ] } t  |  Vq d  S(   N(   Rm   (   R   t   o(    (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>p  s    i   u    u       (   Rl   R   Rm   R*   (   R0   t   optionst   spc(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _simple_interactive_menun  s    ,c         C  s  t  d  xt r|  j d d d d d d  t d  j   } | sT t    q n  | j   j   d	 } | j   d
 } y | d k r t    |  j j |  j j	 d t
 d t n | d k r |  j   nl | d k r |  j   nS | d k r d  S| d k r|  j |  n' | d k r,|  j   n t  d |  WnD t k
 r^} t  d |  n$ t k
 r} t  d | j  n Xt    q Wd  S(   Nu   NLTK Downloaderu   d) Downloadu   l) Listu
    u) Updateu	   c) Configu   h) Helpu   q) Quitu   Downloader> i    i   u   lR~   R   u   hu   cu   qu   xu   du   uu   Command %r unrecognizedu   Error reading from server: %su   Error connecting to server: %s(   u   qu   x(   Rl   RA   R  R   R   R{   R)   R   R   R]   Rn   t   _simple_interactive_helpt   _simple_interactive_configt   _simple_interactive_downloadt   _simple_interactive_updateR   R   t   reason(   R0   R   t   commandt   argsR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   w  sF    
	%c         C  s?  | rZ x2| D]F } y |  j  j | d d Wq t t f k
 rR } t |  q Xq Wn x t r:t   t d  t d  } | j   d k r |  j  j |  j  j	 d t
 d t d t q] q] | j   d k r d  S| r] xT | j   D]F } y |  j  j | d d Wq t t f k
 r.} t |  q Xq WPq] q] Wd  S(   NR   u       u*   Download which package (l=list; x=cancel)?u     Identifier> u   lR~   R   R   u   xu   qu    (   u   xu   qu    (   R   R   R   R   Rl   RA   R   R{   R   R]   Rn   R)   (   R0   R
  t   argR   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s4    	
	c   
      C  s  xt  rg  } t } } xc t t |  j d    d t D]@ } |  j j |  |  j j k r; | j | j	 | j
 f  q; q; Wt   | rt d  x\ | D]T \ } } t j d d | d d d d d } t d	 | j d
 d  | f  q Wt   t d  } | j   d k ruxT | D]L \ } } y |  j j | d d Wq!t t f k
 rl}	 t |	  q!Xq!WPq| j   d k rd  Sq t d  d  Sq Wd  S(   Nu   packagesR8   u/   Will update following packages (o=ok; x=cancel)u   -i   iK   Rj   u    u     [ ] %s %si   u   .u     Identifier> u   oR   u       u   xu   qu    u   Nothing to update.(   u   xu   qu    (   RA   Rn   Rq   Rr   R   RX   Rs   Ru   Ro   R   R   Rl   Rx   Ry   Rz   R   R{   R   R   R   (
   R0   t   stale_packagesR   R   R   t   pidt   pnameR   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s6    	
( 
$
c         C  s3   t    t  d  t  d  t  d  t  d  d  S(   Nu	   Commands:uH     d) Download a package or collection     u) Update out of date packagesu1     l) List packages & collections          h) Helpu1     c) View & Modify Configuration          q) Quit(   Rl   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    

c         C  s   t    t  d  t  d |  j j  t  d t |  j j     t  d t |  j j     t    t  d  t  d |  j j  d  S(   Nu   Data Server:u     - URL: <%s>u$     - %d Package Collections Availableu$     - %d Individual Packages Availableu   Local Machine:u     - Data directory: %s(   Rl   R   R   Rm   R   RE   R]   (   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _show_config  s    

c         C  sr  |  j    xat rmt   |  j d d d d  t d  j   j   } | d k ra |  j    q | d k r t d  j   } | d k r t d  qjt j j	 |  r | |  j
 _ qjt d |  q | d k rZt d  j   } | d k rt d  qj| j d  sd | } n  y | |  j
 _ Wqjt k
 rV} t d | | f  qjXq | d k r Pq q Wd  S(   Nu   s) Show Configu   u) Set Server URLu   d) Set Data Diru   m) Main Menuu   Config> u   su   du     New Directory> u    u   xu   qu   Xu   Qu     Cancelled!u)   Directory %r not found!  Create it first.u   uu     New URL> u   http://u   https://u   Error reading <%r>:
  %su   m(   u    u   xu   qu   Xu   Q(   u    u   xu   qu   Xu   Q(   u   http://u   https://(   R  RA   Rl   R  R   R   R{   R&   R'   R   R   R]   t
   startswithR   RW   (   R0   R   t
   new_dl_dirt   new_urlR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s6    
	(
   R=   R>   R3   R  R   R  R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   j  s   				)		 			
R   c           B  s  e  Z d  Z d d d d d d d d d	 d
 d d g Z i d d 6d d 6d d 6d d 6Z i d d 6d d 6d d 6d d 6d d 6d d 6Z d Z d d d d d g Z x  e D] Z e e k s t	  q Wx  e D] Z e e k s t	  q Wx  e D] Z e e k s t	  q WdN Z
 i dO e j 6dP e j 6dQ e j 6dR e j 6Z dS Z dT Z dU Z dV Z d# Z e d$  Z d%   Z d&   Z d'   Z d(   Z d)   Z d*   Z dW d+  Z d,   Z  d-   Z! d.   Z" d/   Z# d0   Z$ d1   Z% d2   Z& d3 Z' dW Z( d4   Z) d5   Z* d6   Z+ d Z, d7   Z- d8   Z. d9   Z/ d:   Z0 d;   Z1 d<   Z2 d=   Z3 d>   Z4 d?   Z5 d@   Z6 dA   Z7 e8 j9 dB  Z: dC   Z; dD   Z< d Z= dE   Z> dF   Z? dG   Z@ dH   ZA dI   ZB dJ eC jD f dK     YZE dL ZF dM   ZG RS(X   uU   
    Graphical interface for downloading packages from the NLTK data
    server.
    u    u
   Identifieru   Nameu   Sizeu   Statusu   Unzipped Sizeu	   Copyrightu   Contactu   Licenseu   Authoru   Subdiru   Checksumi    i   i   i   i-   i
   i   i   u   #000u   #cccu   #afau   #080u   #ffau   #880u   #faau   #800u   #fffu   #888u   #45cu   #aaau   #67au   #f00u   helvetica -16 boldc         C  s  | |  _  | |  _ t j   |  _ g  |  _ g  |  _ t |  _ i  |  _	 g  |  _
 d |  _ |  j d  t   } |  _ | j d  | j d  | j d |  j d  | j d |  j  | j d |  j  t |  _ i  |  _ |  j   |  j   y |  j   WnB t k
 r!} t d	 |  n# t k
 rC} t d
 | j  n X|  j   |  j   |  j  j! d  |  j  j d |  j"  d  S(   Ni    u   NLTK Downloader Started!u   +50+50u   NLTK Downloadert
   backgroundi   u   <Control-q>u   <Control-x>u   Error reading from serveru   Error connecting to serveru	   <Destroy>(#   R   t   _use_threadst	   threadingt   Lockt   _download_lockt   _download_msg_queuet   _download_abort_queueRn   t   _downloadingt   _afteridt   _log_messagest   _log_indentt   _logR   t   topt   geometryt   titlet	   configuret   _BACKDROP_COLORt   bindt   destroyt
   _destroyedt   _column_varst   _init_widgetst
   _init_menut   _fill_tableR   R   R   R  t
   _show_infot   _select_columnst   _tablet   selectt   _destroy(   R0   R   t   use_threadsR  R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   l  s<    										



c         C  s.   |  j  j d t j   d |  j | f  d  S(   Nu   %s %s%su    | (   R  Ro   R   t   ctimeR  (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    	c           s  t    j d d d d d d d d } | j d	 d
 d t d d  | j d d d | j d d d t  | d d j d d d d  t  |  } | j d d d d d d  t  |  } | j d d d d d d  t  |  } | j d d d d d d  t  | d d j d d d d  t  |  } | j d d d d d d  t  | d d j d d d d  t    j d d d d d   j d } | j d d d d  d   j d <d   j d <d d  d! d" g   _ i    _	 x t
   j  D]o \ } } t | d# | d$   j }	 |	 j d d% d | d d d&  |	 j d'   j  |	   j	 | j   <qWg    j D] }
   j j |
 d  ^ qr} t |   j d( | d) d d* d+ d,   j   _   j j d d-   j d xK t
   j  D]: \ } }
   j j |
   j  }   j j | d. | qW  j j d t d d    j j     j j d/   j    j j d0   j    j j d1   j    j j d2   j    j j d3   j    j j d4   j   | j d d d d5 d6   j! f d7 d8   j" f g } i    _# x t
 |  D] \ } \ } }	 } t | d# |	 j d d d | d d9  t$ | d$ d: d d; d< d= } | | f   j# | <| j d1   j%  | j d' |   f d>   | j d d d | d d?  q%W  j j d'   j%  t& | d# d@ dA   j d. d   _'   j' j d d%  t& | d# dB dA   j( d. d   _)   j) j d dC  t | d# dD d-   j d d   j d   _* t+ | d. dE d d+ d   j, d d dF d d   _-   j.     j- j d dC    j* j d d%  d  S(G   Nt   reliefu   raisedt   borderi   t   padxi   t   padyi    t   sidu   topt   expandRy   u   botht   weighti   t   heightt   columnt   rowt   stickyu   newsi   i   i   i   R  t   sideu   bottomu   xu   borderu   highlightthicknessu   Collectionsu   Corporau   Modelsu   All Packagest   textt   fontu   lefti
   u
   <Button-1>t   column_weightst   highlightthicknesst   listbox_heighti   t   reprfunct
   foregroundRk   u   <Double-Button-1>u   <space>u   <Return>u   <Left>u   <Right>u   <Control-a>u   urlu   Server Index:u   download_diru   Download Directory:u   eu   courieru   groovet   disabledforegroundu   blackc           s     j  |  S(   N(   t
   _info_edit(   R   R8   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   <lambda>  t    u   ewu   DownloadR	  u   Refreshu   rightu    i   u   sunken(/   R   R  t   packRA   t   grid_rowconfiguret   grid_columnconfiguret   gridR#  t
   _tab_namest   _tabsR   R   t	   _TAB_FONTR$  t   _select_tabR{   t   COLUMNSt   COLUMN_WEIGHTSRG   R   t   _table_reprfuncR-  t   columnconfigt   _MARK_COLORt   COLUMN_WIDTHSt   DEFAULT_COLUMN_WIDTHt   focust   bind_to_listboxest	   _downloadt   _table_markt	   _prev_tabt	   _next_tabt	   _mark_allR   R   t   _infoR   t
   _info_saveR	   t   _download_buttont   _refresht   _refresh_buttont   _progresslabelR
   t   _PROGRESS_COLORt   _progressbart   _init_progressbar(   R0   t   f1t   tabframet
   tableframet   buttonframet	   infoframet   progressframeR   t   tabt   labelR:  R@  Rk   R   R8   t   callbackt   entry(    (   R0   s.   lib/python2.7/site-packages/nltk/downloader.pyR(    s    '"""%	"+		"( !!
c      
     s%  t    j  } t  | d d } | j d d d d d   j d d  | j   | j d d	 d d
 d   f d    | j d d d d d   f d    | j   | j d d d d d   j  | j   | j d d d d d   j d d  | j d d d d d |  t  | d d } x   j j	 d D]{ } t
   j  } |   j k s[t  |   j | <|   j k r| j d  n  | j d | d d d | d   j  q1W| j d d d d d |  t  | d d } x>   j j	 d D], } | j d d | d |   f d   qW| j   x>   j j	 d D], } | j d d | d |   f d   q:W| j d d d d d |  t  | d d } | j d d d d d   j  | j d d d d d   j d d  | j d d  d d d |    j j d!   j    j j d |  d  S("   Nt   tearoffi    Ro  u   Downloadt	   underlineR	  t   acceleratoru   Returnu   Change Server Indexi   c             s     j  d  S(   Nu   url(   RF  (    (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyRG    RH  u   Change Download Directoryc             s     j  d  S(   Nu   download_dir(   RF  (    (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyRG  !  RH  u   Show Logi   u   Exiti   u   Ctrl-xu   Filet   menui   t   variableu   Viewu
   Sort by %sc           s     j  j |  d  S(   Nu	   ascending(   R-  t   sort_by(   R   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyRG  A  RH  u   Reverse sort by %sc           s     j  j |  d  S(   Nu
   descending(   R-  Rw  (   R   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyRG  H  RH  u   Sortu   Aboutu   Instructionsu   F1u   Helpu   <F1>(   R   R  t   add_commandRZ  t   add_separatort	   _show_logR%  t   add_cascadeR-  t   column_namesR   R'  t   AssertionErrort   INITIAL_COLUMNSt   sett   add_checkbuttonR,  t   aboutt   helpR$  t   config(   R0   t   menubart   filemenut   viewmenuR:  t   vart   sortmenut   helpmenu(    (   R0   s.   lib/python2.7/site-packages/nltk/downloader.pyR)    s^    	
		

		 	

	
	c         C  sS   xL |  j  j   D]; \ } } | j   r; |  j j |  q |  j j |  q Wd  S(   N(   R'  R   RG   R-  t   show_columnt   hide_column(   R0   R:  R  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR,  V  s    c         C  st   |  j  j   y |  j   WnB t k
 r= } t d |  n# t k
 r_ } t d | j  n X|  j j d  d  S(   Nu   Error reading from serveru   Error connecting to serveri    (	   R   R   R*  R   R   R   R  R-  R.  (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRb  ]  s    c         C  s?   |  j    |  j | \ } } d | d <d | d <| j   d  S(   Nu   normalu   stateu   sunkenu   relief(   R`  R_  RX  (   R0   t   info_keyRq  Rp  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRF  g  s
    


c         C  s   |  j  } x |  j j   D]y \ } } | d d k r; q n  | d  k	 rn | j | k rn | j d k rn | } q d | d <d | d <| | j    q W| j   d  S(   Nu   stateu   disabledu   Returnu   grooveu   relief(   R-  R_  R   R@   t   widgett   keysymRG   RX  (   R0   R   RX  Rq  Rp  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR`  n  s    	*	

c         C  s   |  j  j | j d  ro t | t  r0 d | S| d k  rH d | d S| d k  r` d	 | d Sd
 | d Sn  | d k r t |  Sd | Sd  S(   Nu   Sizeu     %si   i   u	     %.1f KBg      @i   i   u	     %.1f MBu	     %.1f GBi    u    i   g      @i   @g      0Ag      A(   i    u    (   R-  R|  R   R4   R   RX   (   R0   R;  t   colt   val(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRS  {  s    
c         C  sg   | |  j  j k r d  Sy | |  j  _ |  j   Wn& t k
 rX } t d t |   n X|  j   d  S(   Nu   Error Setting Server Index(   R   R   R*  R   R   RX   R+  (   R0   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    c         C  s   |  j  j | k r d  S| |  j  _ y |  j   WnB t k
 rR } t d |  n# t k
 rt } t d | j  n X|  j   d  S(   Nu   Error reading from serveru   Error connecting to server(   R   R]   R*  R   R   R   R  R+  (   R0   R]   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    c         C  s   t  d |  j j  x7 |  j j   D]& \ } } d | d <| j d d  q# W|  j d d j d |  j j  |  j d d j d |  j j  x' |  j j   D] \ } } d | d <q Wd  S(	   Nu   showing infou   normalu   statei    u   endu   urlu   download_diru   disabled(   Rl   R   R   R_  R   t   deletet   insertR]   (   R0   Rq  t   cb(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR+    s    
!!c         G  s   x t  |  j  D] \ } } | j   |  j k r | d k r |  j | d j   |  _ y |  j   SWq t k
 r } t d |  q t k
 r } t d | j  q Xq q Wd  S(   Ni    i   u   Error reading from serveru   Error connecting to server(	   R   RM  R{   t   _tabR*  R   R   R   R  (   R0   R   R   Rn  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR\    s    !c         G  s   x t  |  j  D] \ } } | j   |  j k r | t |  j  d k  r |  j | d j   |  _ y |  j   SWq t k
 r } t d |  q t	 k
 r } t d | j
  q Xq q Wd  S(   Ni   u   Error reading from serveru   Error connecting to server(   R   RM  R{   R  Rm   RN  R*  R   R   R   R  (   R0   R   R   Rn  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR]    s    .c         C  sm   | j  d j   |  _ y |  j   WnB t k
 rF } t d |  n# t k
 rh } t d | j  n Xd  S(   Nu   textu   Error reading from serveru   Error connecting to server(   R  R{   R  R*  R   R   R   R  (   R0   t   eventR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRP    s    u   collectionsc         C  s  |  j  j   } |  j  j   |  j d k r= |  j j   } n| |  j d k r^ |  j j   } n[ |  j d k r |  j j   } n: |  j d k r |  j j   } n d s t	 d |  j   g  | D] } |  j
 |  ^ q } |  j  j |  xw |  j j   D]f \ } } | |  j k r=| j d |  j d d |  j d	  q | j d |  j d d |  j d	  q W|  j  j d
 d d |  j   |  j  j |  |  j j d |  j  j j |  j  j j    |  j j d |  j  j j |  j  j j    d  S(   Nu   all packagesu   corporau   modelsu   collectionsi    u   bad tab value %rRD  R  i   u
   Identifiert   orderu	   ascendingi   i,  (   R-  t   selected_rowR   R  R   RE   R   R   R   R}  t   _package_to_columnsR   RN  R   R"  t   _FRONT_TAB_COLORt   _BACK_TAB_COLORRw  t   _color_tableR.  R  t   aftert
   _scrollbarR  t   _mlbt   yview(   R0   R  R   R   t   rowsRn  Ro  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR*    s4    "		
+c         C  s`   xO t  t |  j   D]8 } |  j j |  j | d f  } | |  j | d f <q W|  j   d  S(   Nu
   Identifieru   Status(   R   Rm   R-  R   Rs   R  (   R0   t   row_numRs   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _update_table_status  s    c         G  s   |  j  r |  j |   Sg  t t |  j   D]2 } |  j | d f d k r, |  j | d f ^ q, } |  j j   } | r | d  k	 r |  j | d f g } n  |  j j | |  j j	  } d |  _
 |  j | |  d  S(   Ni    u    u
   Identifier(   R  t   _download_threadedR   Rm   R-  R  R@   R   R   R]   R  t   _download_cb(   R0   R   R;  t   markedt	   selectiont   download_iter(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRZ     s    	2	c           sF  y t  |  } WnD t k
 rV   j     j j d   j d  } |   j d <d  SX  f d   } t | t  r   j | j	  nt | t
  r | | j  | j d  k	 r   j | j j  n    j d   d  St | t  r| d | j j    j d 7_ nt | t  r5| d | j j  n t | t  r[| d | j j  n t | t  r| d	 | j j  n t | t  r| d
 | j j  nm t | t  r  j d 8_ | d | j j    j | j j  n% t | t  r  j | j j  n    j j   j   j | |  } |   j d <d  S(   Ni
   i    u   _download_cbc           s   |    j  d <  j |   d  S(   Nu   text(   Rd  R  (   R   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    u   Downloading collection %si   u   Downloading package %su   Package %s is up-to-date!u   Finished downloading %r.u   Unzipping %su#   Finished downloading collection %r.(   t   nextt   StopIterationR  R  R  t   _show_progressR  R4   RZ   R[   RV   RY   RN   R@   t   _selectR   RJ   RK   R  RM   RT   RQ   RR   R+   RL   t   _clear_markRO   t	   _DL_DELAYR  (   R0   R  t   idsR   t   afteridR   (    (   R0   s.   lib/python2.7/site-packages/nltk/downloader.pyR    sF    
!c         C  sQ   xJ t  t |  j   D]3 } |  j | d f | k r |  j j |  d  Sq Wd  S(   Nu
   Identifier(   R   Rm   R-  R.  (   R0   R   R;  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  A  s    c         C  s   x t  t |  j   D] } |  j |  j | d f \ } } d
 \ } } |  j j | d | d | d | d | |  j j | d d |  j d d |  j d	 q Wd  S(   Nu   Statusu   blacku   whiteRD  t   selectforegroundR  t   selectbackgroundi    i   (   u   blacku   white(   R   Rm   R-  t
   _ROW_COLORt	   rowconfigt   itemconfigureRU  (   R0   R;  t   bgt   sbgt   fgt   sfg(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  G  s     		c         C  sS   xL t  t |  j   D]5 } |  j | d f | k r d |  j | d f <q q Wd  S(   Nu
   Identifieru    i    (   R   Rm   R-  (   R0   R   R;  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  X  s    c         G  s7   x0 t  t |  j   D] } d |  j | d f <q Wd  S(   Nu   Xi    (   R   Rm   R-  (   R0   R   R;  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR^  ]  s    c         G  su   |  j  j   } | d k r^ |  j  | d d k rH d |  j  | d f <q^ d |  j  | d f <n  |  j  j d d  d  S(   Ni    u    u   XR   i   (   R-  R  R.  (   R0   R   R  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR[  a  s    c         C  s)   d j  |  j  } t |  j d |  d  S(   Nu   
u   NLTK Downloader Log(   R*   R  R   R  (   R0   R>  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRz  j  s    c         C  s   g  } x t  |  j  D] \ } } | d k r> | j d  q | d k r] | j | j  q | d k r | j |  j j |   q | j   j d d  } | j t | | d   q W| S(   u   
        Given a package, return a list of values describing that
        package, one for each column in ``self.COLUMNS``.
        i    u    u
   Identifieru   Statusu    u   _u   n/a(	   R   RQ  Ro   R   R   Rs   R{   t   replaceRr   (   R0   R   R;  t   column_indext   column_namet   attr(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  n  s    c         G  s'   |  j  r d  S|  j j   t |  _  d  S(   N(   R&  R  R%  RA   (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR%    s    	c         G  sl   |  j  d  k	 r< x* |  j j   D] } |  j  j |  q Wn  |  j r[ |  j r[ |  j   n  |  j j	   d  S(   N(
   R  R@   R  R   t   after_cancelR  R  t   _abort_downloadR'  R   (   R0   R   R  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR/    s    c         O  s   |  j  j | |   d  S(   N(   R  R   (   R0   R
  t   kwargs(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    un      This tool can be used to download a variety of corpora and models
    that can be used with NLTK.  Each corpus or model is distributed
    in a single zip file, known as a "package file."  You can
    download packages individually, or you can download pre-defined
    collections of packages.

    When you download a package, it will be saved to the "download
    directory."  A default download directory is chosen when you run

    the downloader; but you may also select a different download
    directory.  On Windows, the default download directory is


    "package."

    The NLTK downloader can be used to download a variety of corpora,
    models, and other data packages.

    Keyboard shortcuts::
      [return]	 Download
      [up]	 Select previous package
      [down]	 Select next package
      [left]	 Select previous tab
      [right]	 Select next tab
    c         G  s\   y, t  |  j d |  j j   d d d d Wn) t  |  j d |  j j   d d n Xd  S(   Nu   Help: NLTK DowloaderRk   iK   R?  u   fixedu   Help: NLTK Downloader(   R   R  t   HELPR   (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    c         G  sh   d d } d } y- d d l  m } | d | d |  j   Wn$ t k
 rc t |  j | |  n Xd  S(   Nu   NLTK Downloader
u   Written by Edward Loperu   About: NLTK Downloaderi(   t   MessageRY   R!  (   t   six.moves.tkinter_messageboxR  R   t   ImportErrorR   R  (   R0   R   t   ABOUTt   TITLER  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    
c         C  s	  |  j  } t | d  t | d  } } x t d t | d  d |  j  D]c } | j | |  j d d | |  j | d | d d |  j d d	 d
 t | d d  d qO W| j d  | j d d d | j d | j	 d d d d d |  j
 d  d  S(   Nu   widthu   heighti    i   i   iRk   Ry   u	   #%02x0000iP   i   i   i   u   gradientt   stateu   hiddenu   redbox(   Rf  R   R   t   _gradient_widtht   create_linet   abst
   addtag_allt
   itemconfigt   addtag_withtagt   create_rectangleRe  (   R0   R   Rk   R9  R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyRg    s    	!+
	%c         C  s   |  j  } | d  k rD | j d d d d d  | j d d d nV t | d  t | d  } } | t |  d d	 } | j d d d | | d	  d  S(
   Nu   redboxi    u   gradientR  u   hiddenu   widthu   heightid   i   (   Rf  R@   t   coordsR  R   (   R0   t   percentR   Rk   R9  t   x(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    	!c         C  s   |  j  } |  j s( | j d d d n | j d d d | j d  \ } } } } | d k r | j d |  j d d d  n | j d d	 d  |  j j d
 |  j  } | |  j	 d <d  S(   Nu   gradientR  u   hiddenu   normalii   i   i    ii   u   _progress_alive(
   Rf  R  R  t   bboxt   moveR  R  R  t   _progress_aliveR  (   R0   R   t   x1t   y1t   x2t   y2R  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    		!c         G  sD  |  j  r |  j   d  Sd |  j d <g  t t |  j   D]2 } |  j | d f d k r: |  j | d f ^ q: } |  j j   } | r | d  k	 r |  j | d f g } n  t |  j	 j
 |  j	 j  } |  j g  k s t  |  j g  k s t  |  j | | |  j |  j |  j  j   d |  _ t |  _  |  j   |  j   d  S(   Nu   Cancelu   texti    u    u
   Identifier(   R  R  Ra  R   Rm   R-  R  R@   R^   R   R   R]   R  R}  R  t   _DownloadThreadR  t   startR  RA   t   _monitor_message_queueR  (   R0   R   R;  R  R  t   ds(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  	  s.    	
2		
c         C  s:   |  j  r6 |  j j   |  j j d  |  j j   n  d  S(   Nu   abort(   R  R  t   acquireR  Ro   t   release(   R0   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  5  s    	R  c           B  s   e  Z d    Z d   Z RS(   c         C  sA   | |  _  | |  _ | |  _ | |  _ | |  _ t j j |   d  S(   N(   t   data_serverR   t   lockt   message_queuet   abortR  t   ThreadR3   (   R0   R  R   R  R  R  (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR3   <  s    					c         C  s   xq |  j  j |  j  D]Z } |  j j   |  j j |  |  j rc |  j j d  |  j j   d  S|  j j   q W|  j j   |  j j d  |  j j   d  S(   Nu   abortedu   finished(	   R  R   R   R  R  R  Ro   R  R  (   R0   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   D  s    	(   R=   R>   R3   R   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  ;  s   	id   c           s1    f d   }   j  j   s" d  Sx  j D]} | d k sJ | d k r   j   t   _ d   j d <  j 2  j 2  j  j   | d k r | d    j	 d   n(   j j d   j	 d   } |   j d <d  St | t  r   j	 | j  q, t | t  rT| | j  | j d  k	 r:  j | j j  n    j	 d   t   _ d  St | t  r| d	 | j j    j d
 7_ q, t | t  r  j j | j j  | d | j j  q, t | t  r| d | j j  q, t | t  r| d | j j  q, t | t  r7| d | j j  q, t | t   r]| d | j j  q, t | t!  r  j d
 8_ | d | j j    j" | j j  q, t | t#  r,   j     j" | j j  q, q, W  j rd   j$ d <n    j 2  j  j     j j   j%   j&  } |   j d <d  S(   Nc           s   |    j  d <  j |   d  S(   Nu   text(   Rd  R  (   R   (   R0   (    s.   lib/python2.7/site-packages/nltk/downloader.pyR   U  s    u   finishedu   abortedu   Downloadu   textu   Download aborted!id   u   _monitor_message_queueu   Downloading collection %ri   u   Downloading package %ru   Package %s is up-to-date!u   Finished downloading %r.u   Unzipping %su   Finished installing %su#   Finished downloading collection %r.u   Aborting download...('   R  R  R  R  Rn   R  Ra  R  R  R  R@   R  R  R  R4   RZ   R[   RV   RY   RN   R  R   RJ   RK   R  RM   R   R   RT   RQ   RR   R+   RS   RL   R  RO   Rd  t   _MONITOR_QUEUE_DELAYR  (   R0   R   R   R  (    (   R0   s.   lib/python2.7/site-packages/nltk/downloader.pyR  T  sj    
	
	
	(   u   #000u   #ccc(   u   #afau   #080(   u   #ffau   #880(   u   #faau   #800(   u   #fffu   #888(   u   #000u   #ccc(   u   #fffu   #45c(   u   #aaau   #67a(   u   #f00u   #aaaN(H   R=   R>   R?   RQ  RR  RV  RW  R~  R   R}  R#  R^   Rt   Rv   Ru   Rw   R  RU  R  R  Re  RO  RA   R3   R  R(  R)  R,  Rb  RF  R@   R`  RS  R   R   R+  R\  R]  RP  R  t   _rowsR*  R  RZ  R  R  R  R  R  R^  R[  Rz  R  R%  R/  R   Rx   t   dedentR  R  R  R  Rg  R  R  R  R  R  R  R  R  R  (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s   	"



1			k	E		
			
		
					)			,																
		,	c         C  s>   t  |  t  r4 t |  d   } t |  SWd QXn  t |   S(   uz   
    Calculate and return the MD5 checksum for a given file.
    ``file`` may either be a filename or an open stream.
    u   rbN(   R4   R   R   t   _md5_hexdigest(   R   R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    c         C  sF   t    } x0 t r; |  j d  } | s+ Pn  | j |  q W| j   S(   Ni   i   i @  (   R   RA   R   R/   t	   hexdigest(   t   fpt
   md5_digestR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR    s    		c         C  s?   x8 t  |  | |  D]$ } t | t  r t |   q q Wd S(   u\   
    Extract the contents of the zip file ``filename`` into the
    directory ``root``.
    N(   R   R4   RV   RW   (   R+   t   rootR   RY   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR-     s    c         c  s   | r: t  j j d t j j |   d  t  j j   n  y t j |   } WnF t j	 k
 rt } t
 |  d  Vd  St k
 r } t
 |  |  Vd  SX| j |  | r t   n  d  S(   Nu   Unzipping %si   u   Error with downloaded zip file(   R   t   stdoutR   R&   R'   R)   t   flusht   zipfilet   ZipFilet   errorRV   RW   t
   extractallRl   (   R+   R  R   t   zfR   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR     s    $c         C  s#  g  } xt  t j j |  d   D] \ } } } t j | j  } d | | t j j | j  d f } t d   | j   D  } | j	 d d |  | j	 d d | j
  | j	 d d t | j   | j	 d	 |  | j d
  s | j	 d
 |  n  | j |  q" Wt t t j j |  d    }	 t	   }
 xY | |	 D]M } | j d  |
 k r|t d | j d    n  |
 j | j d   qEWt j d  } | j t j d   x | D] } | d j |  qW| j t j d   x |	 D] } | d j |  qWt |  | S(   u}  
    Create a new data.xml index file, by combining the xml description
    files for various packages and collections.  ``root`` should be the
    path to a directory containing the package xml and zip files; and
    the collection xml files.  The ``root`` directory is expected to
    have the following subdirectories::

      root/
        packages/ .................. subdirectory for packages
          corpora/ ................. zip & xml files for corpora
          grammars/ ................ zip & xml files for grammars
          taggers/ ................. zip & xml files for taggers
          tokenizers/ .............. zip & xml files for tokenizers
          etc.
        collections/ ............... xml files for collections

    For each package, there should be two files: ``package.zip``
    (where *package* is the package name)
    which contains the package itself as a compressed zip file; and
    ``package.xml``, which is an xml description of the package.  The
    zipfile ``package.zip`` should expand to a single subdirectory
    named ``package/``.  The base filename ``package`` must match
    the identifier given in the package's xml file.

    For each collection, there should be a single file ``collection.zip``
    describing the collection, where *collection* is the name of the collection.

    All identifiers (for both packages and collections) must be unique.
    u   packagesu   %s/%s/%si   c         s  s   |  ] } | j  Vq d  S(   N(   t	   file_size(   R   t   zf_info(    (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>	  s    u   unzipped_sizeu   %su   sizeu   checksumu   subdiru   urlu   collectionsu   idu   Duplicate UID: %su	   nltk_datai    (   t   _find_packagesR&   R'   R*   R   R+   R)   R   t   infolistR  R   R   RG   Ro   R   t   _find_collectionsR   t   addR   t   Elementt   _indent_xml(   R  t   base_urlRE   t   pkg_xmlR  R   t   zipstatR   R   R   t   uidsR   t   top_eltRN   RK   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   build_index  s6    +&!	
u    c         C  s   t  |   d k r |  j p d j   d | d |  _ x |  D] } t | | d  q= Wx6 |  d  D]* } | j pu d j   d | d | _ qc W|  d j p d j   d | |  d _ n  d S(   u   
    Helper for ``build_index()``: Given an XML ``ElementTree``, modify it
    (and its descendents) ``text`` and ``tail`` attributes to generate
    an indented tree, where each nested element is indented by 2
    spaces with respect to its parent.
    i    u    u   
u     iN(   Rm   R>  R   R  t   tail(   R7   R   RH   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  +	  s    $(c           s   t  j j t  j j |  d  d   |  j d    k r] t d |  j d    f   n  t   f d   | j   D  r t d     f   n  d S(   ur   
    Helper for ``build_index()``: Perform some checks to make sure that
    the given package is consistent.
    i   i    u   idu&   package identifier mismatch (%s vs %s)c         3  s/   |  ]% } |   k o& | j    d   Vq d S(   u   /N(   R  (   R   R   (   t   uid(    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>H	  s    u;   Zipfile %s.zip does not expand to a single subdirectory %s/N(   R&   R'   R(   R)   RG   R   R   t   namelist(   R  t   zipfilenameR  (    (   R  s.   lib/python2.7/site-packages/nltk/downloader.pyt   _check_package;	  s    &"c         C  s   t  j d d d |  g d t  j d t  j } | j   \ } } | j d k s[ | s[ | r t d t j j |   d t	 j
 |  f   n  | j   d	 S(
   u   
    Helper for ``build_index()``: Calculate the subversion revision
    number for a given file (by using ``subprocess`` to run ``svn``).
    u   svnu   statusu   -vR  R   i    u)   Error determining svn_revision for %s: %si   i   (   t
   subprocesst   Popent   PIPEt   communicatet
   returncodeR   R&   R'   R)   Rx   Ry   (   R+   R   R  R   (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   _svn_revisionP	  s    	,c         c  sy   g  } xl t  j |   D][ \ } } } xI | D]A } | j d  r, t  j j | |  } t j |  j   Vq, q, Wq Wd S(   u   
    Helper for ``build_index()``: Yield a list of ElementTree.Element
    objects, each holding the xml for a single package collection.
    u   .xmlN(   R&   R   R   R'   R*   R   R5   R   (   R  RE   t   dirnamet   subdirsR   R+   t   xmlfile(    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR  c	  s    c         #  s  d d l  m } g  } xt j |   D]\ } } } d j | |  |   } xa| D]Y} | j d  rT t j j | |  } | d  d }	 y t j |	  }
 Wn) t	 k
 r } t
 d |	 | f   n Xy t j |  j   } Wn) t	 k
 r} t
 d | | f   n Xt j j | d   d   | j d	    k rat
 d
 | j d	    f   n  t   f d   |
 j   D  rt
 d     f   n  | |
 | f VqT qT Wy | j d  Wq& t
 k
 rq& Xq& Wd S(   u  
    Helper for ``build_index()``: Yield a list of tuples
    ``(pkg_xml, zf, subdir)``, where:
      - ``pkg_xml`` is an ``ElementTree.Element`` holding the xml for a
        package
      - ``zf`` is a ``zipfile.ZipFile`` for the package's contents.
      - ``subdir`` is the subdirectory (relative to ``root``) where
        the package was found (e.g. 'corpora' or 'grammars').
    i(   t
   _path_fromu   /u   .xmliu   .zipu   Error reading file %r!
%si   u   idu&   package identifier mismatch (%s vs %s)c         3  s/   |  ]% } |   k o& | j    d   Vq d S(   u   /N(   R  (   R   R   (   R  (    s.   lib/python2.7/site-packages/nltk/downloader.pys	   <genexpr>	  s   u;   Zipfile %s.zip does not expand to a single subdirectory %s/u   .svnN(   t   nltk.corpus.reader.utilR  R&   R   R*   R   R'   R  R  RW   R   R   R5   R   R)   RG   R   R  R   (   R  R  RE   R  R  R   t   relpathR+   t   xmlfilenameR  R  R   R  (    (   R  s.   lib/python2.7/site-packages/nltk/downloader.pyR  p	  s@    
c           C  s   t  t  j   d  S(   N(   R   t   _downloaderR   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   download_shell	  s    c           C  s   t  t  j   d  S(   N(   R   R  R   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   download_gui	  s    c           C  s   t  j   d  S(   N(   R  R/   (    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyR/   	  s    u   __main__(   t   OptionParseru   -du   --dirt   destu   dirR  u!   download package to directory DIRt   metavaru   DIRu   -qu   --quietu   quiett   actionu
   store_truet   defaultu   work quietlyu   -fu   --forceu   forceu"   download even if already installedu   -eu   --exit-on-erroru   halt_on_erroru   exit if an error occursu   -uu   --urlu   server_index_urlu   NLTK_DOWNLOAD_URLu   download server index urlRi   R   R]   R   R   R   (j   R?   t
   __future__R    R   R   R   R&   R  R   Rx   R  R   t   shutilR   R  t   hashlibR   t	   xml.etreeR   RA   R   t   six.moves.tkinterR   R   R   R   R	   R
   R   R   R   R  R   t   nltk.draw.tableR   t   nltk.draw.utilR   R  Rn   R   t   sixR   R   t	   six.movesR   t   six.moves.urllib.requestR   t   six.moves.urllib.errorR   R   R   t   nltk.compatR   t   objectR   RC   RI   RJ   RL   RM   RO   RP   RQ   RR   RS   RT   RU   RV   RZ   R\   R^   R   R   R   R  R-   R   R  R  R  R
  R  R  R  R   R  R  R/   R=   t   optparseR  t   parsert
   add_optionR   RG   t
   parse_argsR  R
  Ri   t
   downloadert   pkg_idt   dirR   R   R   t   rv(    (    (    s.   lib/python2.7/site-packages/nltk/downloader.pyt   <module>D   s   \l@

].     		
	H				?														