
    gj                       d 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ZddlmZ ddlmZ 	 d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  ddl#m$Z$m%Z% ddl&m'Z' ddl(Z( G d d      Z) G d d      Z* G d d      Z+ G d de+      Z, G d de+      Z- G d de+      Z. G d de+      Z/ G d de+      Z0 G d de+      Z1 G d d e+      Z2 G d! d"e+      Z3 G d# d$e+      Z4 G d% d&e+      Z5 G d' d(e+      Z6 G d) d*e+      Z7 G d+ d,e+      Z8 G d- d.      Z9 G d/ d0      Z: G d1 d2      Z;d3 Z<d4 Z=d_d5Z>d_d6Z?d7 Z@d`d8ZAd9 ZBd: ZCd; ZDd< ZE e9       ZFeFj                  ZGd= ZHd> ZId? ZJeKd@k(  rWddAlLmMZM  eM       ZNeNj                  dBdCdDdEdFG       eNj                  dHdIdJdKd
dLM       eNj                  dNdOdPdKd
dQM       eNj                  dRdSdTdKd
dUM       eNj                  dVdWdXej                  j                  dY      dZ[       eNj                         \  ZSZT e9eSj                  \      ZVeTrZeTD ]T  ZWeVj                  eWeSj                  eSj                  eSj                  eSj                  ]      Z\e\d
k(  sGeSj                  sT y yeVj                  eSj                  eSj                  eSj                  eSj                  ^       yy# e!$ r d
Ze"ZY w xY w)aaH	  
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
    N)md5)ElementTreeT)	ButtonCanvasEntryFrameIntVarLabelMenuTclErrorTk)	showerror)Table)ShowTextF)	HTTPErrorURLError)urlopenc                   J    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 ddZed        Zd Zd Zy)Packagea4  
    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.
    Nc                    || _         	 |xs || _        	 || _        	 || _        	 t	        |      | _        	 t	        |      | _        	 || _        	 || _        	 |	| _	        	 |
| _
        	 || _        	 || _        	 t        j                  j                  |j!                  d      d         d   }t        j                  j#                  |||z         | _        	 t'        t	        |            | _        	 | j*                  j-                  |       y )N/   )idnamesubdirurlintsizeunzipped_sizechecksumsvn_revision	copyrightcontactlicenseauthorospathsplitextsplitjoinfilenameboolunzip__dict__update)selfr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r.   kwexts                   D/var/www/openai/venv/lib/python3.12/site-packages/nltk/downloader.py__init__zPackage.__init__   s   " 3JB	-	4 EI	: /	 !4(<"0	, 3%ggsyy~b1215VR#X6	3 #e*%
	 	R     c                     t        | t              rt        j                  |       } | j                  D ]'  }t        | j                  |         | j                  |<   ) t        di | j                  S )N )
isinstancestrr   parseattribr   )xmlkeys     r4   fromxmlzPackage.fromxml  sV    c3##C(C::C!#**S/2CJJsO $$$r6   c                 4    | j                   |j                   k  S Nr   r1   others     r4   __lt__zPackage.__lt__      ww!!r6   c                      d| j                   z  S )Nz<Package %s>rB   r1   s    r4   __repr__zPackage.__repr__   s    ''r6   )N NNNNUnknownrK   rK   rK   T	__name__
__module____qualname____doc__r5   staticmethodr?   rE   rI   r8   r6   r4   r   r      sO     C!J % %"(r6   r   c                   4    e Zd ZdZddZed        Zd Zd Zy)
Collectionz
    A directory entry for a collection of downloadable packages.
    These entries are extracted from the XML index file that is
    downloaded by ``Downloader``.
    Nc                     || _         	 |xs || _        	 || _        	 d | _        	 | j                  j                  |       y rA   )r   r   childrenpackagesr/   r0   )r1   r   rU   r   r2   s        r4   r5   zCollection.__init__+  sH    6JB	0 	, 	3 	R r6   c                 J   t        | t              rt        j                  |       } | j                  D ]'  }t        | j                  |         | j                  |<   ) | j                  d      D cg c]  }|j                  d       }}t        dd|i| j                  S c c}w )NitemrefrU   r8   )r9   r:   r   r;   r<   findallgetrS   )r=   r>   childrU   s       r4   r?   zCollection.fromxml=  s    c3##C(C::C!#**S/2CJJsO 25++f2EF2EEIIe$2EF:8:szz:: Gs   /B c                 4    | j                   |j                   k  S rA   rB   rC   s     r4   rE   zCollection.__lt__F  rF   r6   c                      d| j                   z  S )Nz<Collection %s>rB   rH   s    r4   rI   zCollection.__repr__I  s     477**r6   rA   rL   r8   r6   r4   rS   rS   $  s*    !$ ; ;"+r6   rS   c                       e Zd ZdZy)DownloaderMessagezSA status message object, used by ``incr_download`` to
    communicate its progress.N)rM   rN   rO   rP   r8   r6   r4   r`   r`   R  s    !r6   r`   c                       e Zd ZdZd Zy)StartCollectionMessagez<Data server has started working on a collection of packages.c                     || _         y rA   
collectionr1   re   s     r4   r5   zStartCollectionMessage.__init__Z  	    $r6   NrM   rN   rO   rP   r5   r8   r6   r4   rb   rb   W  s
    F%r6   rb   c                       e Zd ZdZd Zy)FinishCollectionMessagez=Data server has finished working on a collection of packages.c                     || _         y rA   rd   rf   s     r4   r5   z FinishCollectionMessage.__init__a  rg   r6   Nrh   r8   r6   r4   rj   rj   ^  s
    G%r6   rj   c                       e Zd ZdZd Zy)StartPackageMessagez-Data server has started working on a package.c                     || _         y rA   packager1   rp   s     r4   r5   zStartPackageMessage.__init__h  	    r6   Nrh   r8   r6   r4   rm   rm   e  
    7r6   rm   c                       e Zd ZdZd Zy)FinishPackageMessagez.Data server has finished working on a package.c                     || _         y rA   ro   rq   s     r4   r5   zFinishPackageMessage.__init__o  rr   r6   Nrh   r8   r6   r4   ru   ru   l  
    8r6   ru   c                       e Zd ZdZd Zy)StartDownloadMessagez.Data server has started downloading a package.c                     || _         y rA   ro   rq   s     r4   r5   zStartDownloadMessage.__init__v  rr   r6   Nrh   r8   r6   r4   ry   ry   s  rw   r6   ry   c                       e Zd ZdZd Zy)FinishDownloadMessagez/Data server has finished downloading a package.c                     || _         y rA   ro   rq   s     r4   r5   zFinishDownloadMessage.__init__}  rr   r6   Nrh   r8   r6   r4   r|   r|   z  
    9r6   r|   c                       e Zd ZdZd Zy)StartUnzipMessagez,Data server has started unzipping a package.c                     || _         y rA   ro   rq   s     r4   r5   zStartUnzipMessage.__init__  rr   r6   Nrh   r8   r6   r4   r   r     s
    6r6   r   c                       e Zd ZdZd Zy)FinishUnzipMessagez-Data server has finished unzipping a package.c                     || _         y rA   ro   rq   s     r4   r5   zFinishUnzipMessage.__init__  rr   r6   Nrh   r8   r6   r4   r   r     rs   r6   r   c                       e Zd ZdZd Zy)UpToDateMessagez/The package download file is already up-to-datec                     || _         y rA   ro   rq   s     r4   r5   zUpToDateMessage.__init__  rr   r6   Nrh   r8   r6   r4   r   r     r~   r6   r   c                       e Zd ZdZd Zy)StaleMessagez3The package download file is out-of-date or corruptc                     || _         y rA   ro   rq   s     r4   r5   zStaleMessage.__init__  rr   r6   Nrh   r8   r6   r4   r   r     s
    =r6   r   c                       e Zd ZdZd Zy)ErrorMessagez Data server encountered an errorc                 b    || _         t        |t              rt        |      | _        y || _        y rA   )rp   r9   	Exceptionr:   message)r1   rp   r   s      r4   r5   zErrorMessage.__init__  s%    gy)w<DL"DLr6   Nrh   r8   r6   r4   r   r     s
    *#r6   r   c                       e Zd ZdZd Zy)ProgressMessagez4Indicates how much progress the data server has madec                     || _         y rA   )progress)r1   r   s     r4   r5   zProgressMessage.__init__  s	     r6   Nrh   r8   r6   r4   r   r     s
    >!r6   r   c                       e Zd ZdZd Zy)SelectDownloadDirMessagez:Indicates what download directory the data server is usingc                     || _         y rA   )download_dirr1   r   s     r4   r5   z!SelectDownloadDirMessage.__init__  s
    (r6   Nrh   r8   r6   r4   r   r     s
    D)r6   r   c                   D   e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ		 d(d	Z
	 	 	 	 	 	 d)dZd Zd Zd Zd Zd Zd*dZd Zd Zd Zdddddd
dej,                  fdZd+dZd+dZd+dZd+dZd Z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*y)-
Downloaderzy
    A class used to access the NLTK data server, which can be used to
    download corpora and other data packages.
    i  zChttps://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml	installedznot installedzout of datepartialNc                     |xs | j                   | _        	 i | _        	 i | _        	 || _        	 d | _        	 d | _        	 i | _        	 d | _        	 | j                  | j                         | _        y y rA   )
DEFAULT_URL_url_collections	_packages_download_dir_index_index_timestamp_status_cache_errorsdefault_download_dir)r1   server_index_urlr   s      r4   r5   zDownloader.__init__  s    $8(8(8	7E?)I@ $	L  	
 R %!%!:!:!<D &r6   TFc                    d}|| j                   }t        d|z         |ret        ddt        | j                        z   z         t        d| j                  z         t        ddt        | j                        z   z         |dz  }dx}}	g }
|r|
j	                  d       |r|
j	                  d	       |
D ]  }t        d
|j                         z         |dz  }t         t        | |             t              D ]4  }| j                  ||      }|| j                  k(  r|r(|| j                  k(  rd}|| j                  k(  rd}	| j                  d| j                  d| j                  d| j                  di|   }t        j                  d|j                   xs |j"                  z   dd      dd  }t        dj%                  ||j"                  j'                  dd      |             |t        |j)                  d            z  }|s|dkD  st+        d      }|j-                         dv r  y d}7 t                 d}|r|dz  }|	r|dz  }t        t        j                  |d z   dd!"             y )#Nr   z!Using default data directory (%s)=   z Data server index for <%s>   FrV   collectionsz%s:r   r>   T*-P ---------------------------K                              subsequent_indent   z  [{}] {} {}   .
zHit Enter to continue: )xqz([*] marks installed packagesz+; [-] marks out-of-date or corrupt packagesz+; [P] marks partially installed collections)L   )r   width)r   printlenr   append
capitalizesortedgetattrr:   status	INSTALLEDSTALEPARTIALNOT_INSTALLEDtextwrapfillr   r   formatljustr*   inputlower)r1   r   show_packagesshow_collectionsheadermore_promptskip_installedlinesstaler   
categoriescategoryinfor   prefixr   
user_inputmsgs                     r4   listzDownloader.list	  sS    --L5DE#c$))n,-./$));<#c$))n,-.QJE
j)m,"H%(--//0QJE6wtX68cBBT<8T^^+TZZ' ET\\)"GNNCJJLL#&&	
   }}		 4TWW5rX# n++FDGGMM"c4JDQRTZZ-..52:!&'@!AJ!'')Z7E/ C0 G7 #8 .@@C@@ChmmC#IBGHr6   c                 V    | j                          | j                  j                         S rA   )_update_indexr   valuesrH   s    r4   rV   zDownloader.packagesE  s!    ~~$$&&r6   c                     | j                          | j                  j                         D cg c]  \  }}|j                  dk(  s| c}}S c c}}w Ncorporar   r   itemsr   r1   r   pkgs      r4   r   zDownloader.corporaI  D    %)^^%9%9%;W%;	SszzY?V%;WWW   AAc                     | j                          | j                  j                         D cg c]  \  }}|j                  dk7  s| c}}S c c}}w r   r   r   s      r4   modelszDownloader.modelsM  r   r   c                 V    | j                          | j                  j                         S rA   )r   r   r   rH   s    r4   r   zDownloader.collectionsQ  s#      ''))r6   c                 H    t        |t              r| j                  |      S |S rA   )r9   r:   r   )r1   
info_or_ids     r4   _info_or_idzDownloader._info_or_idY  s!    j#&99Z((r6   c              #     K   || j                   }t        |       t        |t        t        f      r| j                  |||      E d {    y 	 | j                  |      }t        |t              r@t        |       | j                  |j                  ||      E d {    t        |       y | j                  |||      E d {    y 7 # t        t        f$ r}t        d d| d|        Y d }~y d }~ww xY w7 `7 9w)NzError loading : )r   r   r9   r   tuple_download_listr   OSError
ValueErrorr   rS   rb   incr_downloadrU   rj   _download_package)r1   r   r   forcer   es         r4   r   zDownloader.incr_downloadh  s    --L*<88 j4-0**:|UKKK	##J/D dJ'(..))$--uMMM)$// --dL%HHH% L $ 	t~j\A3%GHH	 N
 IsZ   AD
CDC "=DD  (DD	DC=C83D8C==DDc                 N    t        |t              ryt        |j                        S )Nr   )r9   r   r   rV   )r1   rX   s     r4   _num_packageszDownloader._num_packages  s    dG$t}}%%r6   c              #      K   t        t        |            D ]  }	  j                  ||         ||<    t         fd|D              }d}t        |      D ]  \  }}t        |t              rd|z  }	nt        |j                        |z  }	 j                  |||      D ]4  }
t        |
t              rt        ||
j                  |	z  z          1|
 6 |d|	z  z  } y # t        t        f$ r}t        ||   |       Y d }~ y d }~ww xY ww)Nc              3   @   K   | ]  }j                  |        y wrA   )r   ).0rX   r1   s     r4   	<genexpr>z,Downloader._download_list.<locals>.<genexpr>  s     F4--d3s   r   g      ?d   )ranger   r   r   r   r   sum	enumerater9   r   rV   r   r   r   )r1   r   r   r   ir   num_packagesr   rX   deltar   s   `          r4   r   zDownloader._download_list  s    s5z"A++E!H5a # FFF 'GAt$(l*DMM*\9))$eDc?3)(S\\E5I*IJJI	 E e#H ( Z( "58Q//s.   DCB,DD
.D?DD

Dc              #     K   t        |       t        d       | j                  ||      }|s7|| j                  k(  r(t	        |       t        d       t        |       y | j                  j                  |j                  d        t        j                  j                  ||j                        }t        j                  j                  |      r1|| j                  k(  rt        |       t        j                   |       t        j"                  |d       t        j"                  t        j                  j                  ||j$                        d       t'        |       t        d       	 t)        |j*                        }t-        |d      5 }t/        d|j0                  dz        }t3        j4                         D ]Q  }	|j7                  d      }
|j9                  |
       |
s n+|	d	z  dk(  s2t        t;        d
dd|	|z  z  z                S d d d        |j=                          tC        |       t        d
       |j                  jE                  d      rt        j                  j                  ||j$                        }|jF                  sGt        j                  j                  t        j                  j                  ||j                              r8tI        |       tK        ||d      D ]  }||_&        |  tO        |       t        |       y # 1 sw Y   xY w# t>        $ r5}tA        |d|j                  d|j*                  d|       Y d }~y d }~ww xY ww)Nr   r  T)exist_ok   wbr    @     P   r   zError downloading z from <>:
  .zipF)verbose)(rm   r   r   r   r   ru   r   popr   r'   r(   r+   r,   existsr   r   removemakedirsr   ry   r   r   openmaxr   	itertoolscountreadwritemincloser   r   r|   endswithr.   r   _unzip_iterrp   r   )r1   r   r   r   r   filepathinfileoutfile
num_blocksblocksr   zipdirr   s                 r4   r   zDownloader._download_package  s    !$''a   T<04>>1!$''!#&&&t,, 	tww- 77<<dmm<77>>(##"4((IIh 	L40
BGGLLt{{;dK #4((a  	TXX&Fh% DII$;<
&__.EI.AMM!$qyA~-c"a"
@R:S6S.TUU / & LLN $D))b!! ==!!&)WW\\,<F zzRWW^^BGGLL,IJ'--&xGC"&CKI H ).."4((A &%  	>BggtxxQRS  	sP   E6M:9!L9 AL,:"L,L9 4C8M:,L61L9 9	M7+M2-M:2M77M:[nltk_data] c	           
         t        j                  t        |      |||| _        | j	                          ydfd	}	| j                  |||      D ]  }
t        |
t              r |	|
j                         |rt        |
j                        |r yd| _
        |sW d       t               j                         }|dv r-| j                  |
j                  j                  |||||      s y|dv r y|rt        |
t               r- |	d|
j"                  j                  z         d	z          t        |
t$              r[        d d
 | j                  r! |	d|
j"                  j                  z         + |	d|
j"                  j                  z         Lt        |
t&              r% |	d|
j                  j                  d|d       t        |
t(              r" |	d|
j                  j                  z  d       t        |
t*              r" |	d|
j                  j,                  z  d       t        |
t.              s|
j0                  } y)N)fileTc                 T     t        j                  | |z   |z   dz                y )N    )initial_indentr   )r   r   )r&  prefix2r   print_tos     r4   showz!Downloader.download.<locals>.show  s/    MM'-'7*07*:W*Dr6   Fz(Error installing package. Retry? [n/y/e])yY)r   EDownloading collection %rz   | z$Downloaded collection %r with errorszDone downloading collection %szDownloading package z to z...z!Package %s is already up-to-date!  zUnzipping %s.rJ   )	functoolsr   r   r   _interactive_downloadr   r9   r   r   r   r   r   stripdownloadrp   r   rb   re   rj   rm   r   r   r,   r   r   )r1   r   r   quietr   r   halt_on_errorraise_on_errorprint_error_tor0  r   choicer/  s        `      @r4   r;  zDownloader.download  s    $$U@ '%1"&&( ))*lEJc<0%%(55$$#'DL  !KL!&!Z/#'== # , % % & - .$ (-#z1#( !#'=>83>>;L;LLM') (#C)@A (!'<<  F"%.."3"3!4
 !!ACNNDUDU!UV $C)<="{{~~|= $C9@3;;>>QSWX $C):;_s{{/C/CCTJ $C)AB'*'7'7y Kz r6   c                 @    | j                  ||      | j                  k(  S rA   )r   r   r1   r   r   s      r4   is_stalezDownloader.is_staleE  s    {{:|4

BBr6   c                 @    | j                  ||      | j                  k(  S rA   )r   r   rB  s      r4   is_installedzDownloader.is_installedH  s    {{:|4FFr6   c                 v    || j                   j                          y | j                   j                  |d        y rA   )r   clearr  r1   r   s     r4   clear_status_cachezDownloader.clear_status_cacheK  s/    :$$&""2t,r6   c                    || j                   }| j                  |      }t        |t              r|j                  D cg c]  }| j                  |j                         }}| j                  |v r| j                  S | j                  |v r| j                  S | j                  |v r| j                  |v r| j                  S | j                  |v r| j                  S | j                  S t        j                  j                  ||j                        }|| j                   k7  r| j                  ||      S |j                  | j                   vr)| j                  ||      | j                   |j                  <   | j                   |j                     S c c}w )z
        Return a constant describing the status of the given package
        or collection.  Status can be one of ``INSTALLED``,
        ``NOT_INSTALLED``, ``STALE``, or ``PARTIAL``.
        )r   r   r9   rS   rV   r   r   r   r   r   r   r'   r(   r+   r,   _pkg_statusr   )r1   r   r   r   r   
pkg_statusr!  s          r4   r   zDownloader.statusQ  sR    --L
+ dJ'9=G#$++cff-JGzzZ'zz!+||#:-$2D2D
2R||###z1)))~~% ww||L$--@Ht111''h7777$"4"44262B2B42RD&&tww/))$''22) Hs   "F	c                    t         j                  j                  |      s| j                  S 	 t        j                  |      }|j                  t        |j                        k7  r| j                  S t        |      |j                  k7  r| j                  S |j                  d      r|d d }t         j                  j                  |      s| j                  S t         j                  j                  |      s| j                  S t        d t        j                   |      D              }||j"                  k7  r| j                  S | j                  S # t
        $ r | j                  cY S w xY w)Nr  r5  c              3      K   | ]L  \  }}}|D ]A  }t        j                  t         j                  j                  ||            j                   C N y wrA   )r'   statr(   r+   st_size)r   d_filesfs        r4   r  z)Downloader._pkg_status.<locals>.<genexpr>  sI       #4KAq%A Q*+33 4#4s   AA)r'   r(   r  r   rO  r   rP  r   r   r   md5_hexdigestr!   r  r   isdirr  walkr    )r1   r   r!  filestatunzipdirr    s         r4   rK  zDownloader._pkg_statuss  s"   ww~~h'%%%	&wwx(H s499~-:: "dmm3:: V$}H77>>(+~~%77==*zz!  #%778#4  M
  2 22zz! ~~7  	&%%%	&s   E E$#E$c                     | j                          | j                         D ]5  }| j                  |      | j                  k(  s"| j	                  |||       7 y)zA
        Re-download any packages whose status is STALE.
        )r<  r   N)rI  rV   r   r   r;  )r1   r<  r   r   s       r4   r0   zDownloader.update  sG     	!==?C{{34::-cv> #r6   c                    | j                   1|/t        j                         | j                  z
  | j                  kD  sy|xs | j                  | _        t
        j                  j                  t        j                  t        | j                              j                               | _         t        j                         | _        | j                   j                  d      D cg c]  }t        j                  |       }}|D ci c]  }|j                  | c}| _        | j                   j                  d      D cg c]  }t"        j                  |       }}|D ci c]  }|j                  | c}| _        | j$                  j'                         D ]  }t)        |j*                        D ]  \  }}|| j                   v r| j                   |   |j*                  |<   1|| j$                  v r| j$                  |   |j*                  |<   \t-        dj/                  |             |j*                  |=   | j$                  j'                         D ]o  }i }|g}	|	D ]N  }
t1        |
t"              r|	j3                  |
j*                         /t1        |
t              r|
||
j                  <   OP |j'                         |_        q | j6                  j9                          yc c}w c c}w c c}w c c}w )zA helper function that ensures that self._index is
        up-to-date.  If the index is older than self.INDEX_TIMEOUT,
        then download it again.Npackages/packagecollections/collectionz.removing collection member with no package: {})r   timer   INDEX_TIMEOUTr   nltk	internalsElementWrapperr   r;   r   getrootrZ   r   r?   r   r   rS   r   r   r  rU   r   r   r9   extendrV   r   rG  )r1   r   prV   cr   re   r  child_idqueuer\   s              r4   r   zDownloader._update_index  s    KKyy{T222T5G5GG $499	 nn33gdii0199;
 !%		 150C0CDV0WX0W1GOOA&0WX+348a!$$'84 ,0;;+>+>?W+X
+XaJq!+X 	 
 /::kQTT1Wk: ++224J()<)<=8t~~--1^^H-EJ''*!2!22-1->->x-HJ''*HOO$
 #++A.  > 5 ++224JHLEeZ0LL0w/).HUXX&  #+//"3J 5 	  "M Y4
 ;s   !KK<K$K)c                 :    | j                          | j                  S )z
        Return the XML index describing the packages available from
        the data server.  If necessary, this index will be downloaded
        from the data server.
        )r   r   rH   s    r4   indexzDownloader.index  s     	{{r6   c                     | j                          || j                  v r| j                  |   S || j                  v r| j                  |   S t        d|z        )zKReturn the ``Package`` or ``Collection`` record for the
        given item.Package %r not found in index)r   r   r   r   rH  s     r4   r   zDownloader.info  s[     	>>"%%"""$$R((82=>>r6   c                    | j                          | j                  j                  d      D ]  }|j                  d      |k(  s|c S  | j                  j                  d      D ]  }|j                  d      |k(  s|c S  t	        d|z        )z-Return the XML info record for the given itemr\  r   r]  rl  )r   r   rZ   r[   r   )r1   r   rp   re   s       r4   xmlinfozDownloader.xmlinfo  s    {{**+=>G{{4 B& ? ++--.FGJ~~d#r)!! H 82=>>r6   c                     | j                   S )z)The URL for the data server's index file.)r   rH   s    r4   _get_urlzDownloader._get_url  s    yyr6   c                 Z    | j                   }	 | j                  |       y#  || _          xY w)z
        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   )r1   r   original_urls      r4   _set_urlzDownloader._set_url  s1    
 yy	s#	$DIs     
*c                    dt         j                  v ryt        j                  j                  D ]E  }t         j                  j                  |      s#t        j                  j                  |      sC|c S  t        j                  dk(  r&dt         j                  v rt         j                  d   }n/t         j                  j                  d      }|dk(  rt        d      t         j                  j                  |d      S )a  
        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``.
        APPENGINE_RUNTIMENwin32APPDATAz~/z+Could not find a default download directory	nltk_data)r'   environr`  datar(   r  ra  is_writablesysplatform
expanduserr   r+   )r1   nltkdirhomedirs      r4   r   zDownloader.default_download_dir  s    " "**, yy~~Gww~~g&4>>+E+Eg+N &
 <<7"yBJJ'>jj+G gg((.G$ !NOO ww||G[11r6   c                     | j                   S )a  
        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()``.
        )r   rH   s    r4   _get_download_dirzDownloader._get_download_dir=  s     !!!r6   c                 F    || _         | j                  j                          y rA   )r   r   rG  r   s     r4   _set_download_dirzDownloader._set_download_dirF  s    )  "r6   c                     t         r	 t        |       j                          y t	        |       j                          y # t        $ r t	        |       j                          Y y w xY wrA   )TKINTERDownloaderGUImainloopr   DownloaderShellrunrH   s    r4   r9  z Downloader._interactive_downloadQ  sR     ,d#,,. D!%%'  ,%))+,s   < "A! A!)NN)NTTTFF)NFrA   )Fr(  )+rM   rN   rO   rP   r_  r   r   r   r   r   r5   r   rV   r   r   r   r   r   r   r   r   r|  stderrr;  rC  rE  rI  r   rK  r0   r   rj  r   rn  rp  rs  propertyr   r   r  r  r   r9  r8   r6   r4   r   r     s7    M XK! I$#ME"GE=N :Ix'XX*I8&$2@)H zz^@CG- 3D"H?<#|?	?
 8X
&C%2N"#
 -/@AL	(r6   r   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
r  c                     || _         y rA   )_ds)r1   
dataservers     r4   r5   zDownloaderShell.__init__^  s	    r6   c                     t        d       dt        d |D              z
  t        |      dz
  z  dz  }t        d|j                  |      z          t        d       y )NzK---------------------------------------------------------------------------D   c              3   2   K   | ]  }t        |        y wrA   )r   )r   os     r4   r  z;DownloaderShell._simple_interactive_menu.<locals>.<genexpr>c  s     01As   r   r   r,  )r   r  r   r+   )r1   optionsspcs      r4   _simple_interactive_menuz(DownloaderShell._simple_interactive_menua  sN    hC0000c'lQ6FG#Mfsxx(()hr6   c                 
   t        d       	 | j                  dddddd       t        d	      j                         }|st                =|j	                         j                         d
   }|j                         dd  }	 |dk(  r=t                | j                  j                  | j                  j                  dd       nl|dk(  r| j                          nV|dk(  r| j                          n@|dv ry |dk(  r| j                  |       n$|dk(  r| j                          nt        d|z         t                +# t        $ r}t        d|z         Y d }~(d }~wt        $ r"}t        d|j                  z         Y d }~Qd }~ww xY w)NNLTK DownloaderTzd) Downloadzl) Listz
 u) Updatez	c) Configzh) Helpzq) QuitzDownloader> r   r   lF)r   r   hrf  )r   r   rQ  uzCommand %r unrecognizedzError reading from server: %szError connecting to server: %s)r   r  r   r:  r   r*   r  r   r   _simple_interactive_help_simple_interactive_config_simple_interactive_download_simple_interactive_updater   r   reason)r1   r   commandargsr   s        r4   r  zDownloaderShell.rung  si    )) ~.446J &&(..03G##%ab)DCc>GHHMM$(("7"7SWMX^113^335
*^55d;^3353j@A GK >  ;59:: C6ABBCs+   >A2D8 1;D8 8	FEF E==Fc                 R   |r&|D ]   }	 | j                   j                  |d       " y 	 t	                t	        d       t        d      }|j                         dk(  r4| j                   j                  | j                   j                  ddd       h|j                         d	v ry |r4|j                         D ]   }	 | j                   j                  |d       " y # t        t        f$ r}t	        |       Y d }~d }~ww xY w# t        t        f$ r}t	        |       Y d }~kd }~ww xY w)
Nr,  r   Tz*Download which package (l=list; x=cancel)?  Identifier> r  F)r   r   r   r   r   rJ   )
r  r;  r   r   r   r   r   r   r   r*   )r1   r  argr   r   r   s         r4   r  z,DownloaderShell._simple_interactive_download  s   HH%%c&%9  BC"#34
##%,HHMM--$$('+	 "  %%'>9(..0% HH--b-@ 1
 )   , !HH* !(4 %!!HH%s/   C:DC?*C::C?D&D!!D&c           	      (   	 g }dx}}t         t        | j                  d             t              D ]\  }| j                  j	                  |      | j                  j
                  k(  s6|j                  |j                  |j                  f       ^ t                |rt        d       |D ]N  \  }}t        j                  d|z   dd      d	d  }t        d
j                  |j                  dd      |             P t                t        d      }|j                         dk(  r)|D ]#  \  }}	 | j                  j!                  |d       % y |j                         dv ry t        d       y k# t"        t$        f$ r}	t        |	       Y d }	~	gd }	~	ww xY w)NFrV   r   z/Will update following packages (o=ok; x=cancel)r   r   r   r   r   z  [ ] {} {}r   r   r  r  r,  r  r  zNothing to update.)r   r   r  r:   r   r   r   r   r   r   r   r   r   r   r   r   r;  r   r   )
r1   stale_packagesr   r   r   pidpnamer   r   r   s
             r4   r  z*DownloaderShell._simple_interactive_update  sm   N##EG<wtxx<>CH88??4(DHHNN:"))477DII*>? I GGH"0JC#== E*B(cD -..syyS/A4HI	 #1
 "#34
##%,&4
U% HH--c&-A '5
 %%'>9*+; , !(4 %!!HH%s   ,E--F<FFc                 p    t                t        d       t        d       t        d       t        d       y )Nz	Commands:zH  d) Download a package or collection     u) Update out of date packagesz1  l) List packages & collections          h) Helpz1  c) View & Modify Configuration          q) Quit)r   rH   s    r4   r  z(DownloaderShell._simple_interactive_help  s.    kV	
 	ABABr6   c                    t                t        d       t        d| j                  j                  z         t        dt        | j                  j	                               z         t        dt        | j                  j                               z         t                t        d       t        d| j                  j                  z         y )NzData Server:z  - URL: <%s>z$  - %d Package Collections Availablez$  - %d Individual Packages AvailablezLocal Machine:z  - Data directory: %s)r   r  r   r   r   rV   r   rH   s    r4   _show_configzDownloaderShell._show_config  s    no,-4s488;O;O;Q7RRS4s488;L;L;N7OOP&)>)>>?r6   c                    | j                          	 t                | j                  dddd       t        d      j	                         j                         }|dk(  r| j                          n|dk(  rit        d      j	                         }|d	v rt        d
       nt        j                  j                  |      r|| j                  _
        nlt        d|z         n]|dk(  rRt        d      j	                         }|d	v rt        d
       n/|j                  d      sd|z   }	 || j                  _        n|dk(  ry (# t        $ r}t        d|d|        Y d }~!d }~ww xY w)Nzs) Show Configzu) Set Server URLzd) Set Data Dirzm) Main MenuzConfig> r&  rQ  z  New Directory> )rJ   r   r   XQz  Cancelled!z)Directory %r not found!  Create it first.r  z  New URL> )zhttp://https://r  zError reading <r  m)r  r   r  r   r:  r   r'   r(   rV  r  r   
startswithr   r   )r1   r   
new_dl_dirnew_urlr   s        r4   r  z*DownloaderShell._simple_interactive_config  sL   G)) "57H. z*00288:JS !!#s""#67==?
!99.)WW]]:.,6DHH)E
RSs".44666.)"--.EF",w"6F'. s"9 2 % F{&DEEFs    D: :	EEEN)rM   rN   rO   r5   r  r  r  r  r  r  r  r8   r6   r4   r  r  ]  s.    'R<@C@r6   r  c                   \   e Zd ZdZg dZ	 dddddZ	 dddd	d	d
dZ	 dZ	 g dZ	 eD ]  Z	e	ev rJ  eD ]  Z	e	ev rJ  eD ]  Z	e	ev rJ  dZ
ej                  dej                  dej                  dej                  diZdZdZdZdZdZdBdZd Zd Zd Zd Zd Zd ZdCdZd  Zd! Zd" Z d# Z!d$ Z"d% Z#d& Z$d'Z%dZ&d( Z'd) Z(d* Z)d	Z*d+ Z+d, Z,d- Z-d. Z.d/ Z/d0 Z0d1 Z1d2 Z2d3 Z3d4 Z4d5 Z5 e6jn                  d6      Z8d7 Z9d8 Z:dZ;d9 Z<d: Z=d; Z>d< Z?d= Z@ G d> d?eAj                        ZCd@ZDdA ZEy)Dr  zU
    Graphical interface for downloading packages from the NLTK data
    server.
    )rJ   
IdentifierNameSizeStatusUnzipped Size	CopyrightContactLicenseAuthorSubdirChecksumr   r  )rJ   r  r  r  r   r   -   
      )rJ   r  r  r  r  r     )rJ   r  r  r  r  )z#000z#ccc)z#afaz#080)z#ffaz#880)z#faaz#800)#fffz#888)r  z#45c)#aaaz#67a)z#f00r  zhelvetica -16 boldc                    || _         || _        t        j                         | _        g | _        g | _        d| _        i | _        g | _	        d| _
        | j                  d       t               x}| _        |j                  d       |j                  d       |j!                  | j"                  d          |j%                  d| j&                         |j%                  d	| j&                         d| _        i | _        | j-                          | j/                          	 | j1                          | j;                          | j=                          | j>                  jA                  d       | j>                  j%                  d| jB                         y # t2        $ r}t5        d
|       Y d }~|d }~wt6        $ r }t5        d|j8                         Y d }~d }~ww xY w)NFr   zNLTK Downloader Started!z+50+50r  r   )
backgroundz<Control-q>z<Control-x>Error reading from serverError connecting to serverz	<Destroy>)"r  _use_threads	threadingLock_download_lock_download_msg_queue_download_abort_queue_downloading_afterid_log_messages_log_indent_logr   topgeometrytitle	configure_BACKDROP_COLORbinddestroy
_destroyed_column_vars_init_widgets
_init_menu_fill_tabler   r   r   r  
_show_info_select_columns_tableselect_destroy)r1   r  use_threadsr  r   s        r4   r5   zDownloaderGUI.__init__\  s   ' (nn.#% %'"!   		,- dhX		#$!5!5a!89 	-- 		> 	1 	dmm4  	61155 	>2AHH==	>s$   F 	GF((G4GGc                     | j                   j                  dj                  t        j                         d| j
                  z  |             y )Nz{} {}{}z | )r  r   r   r^  ctimer  r1   r   s     r4   r  zDownloaderGUI._log  s9    !!TZZ\543C3C+CSI	
r6   c                 \    t         j                  dddd      }|j                  ddd	       |j                  dd
       |j	                  dd
       t        |d      j                  dd       t        |      }|j                  dd
d       t        |      }|j                  ddd       t        |      }|j                  ddd       t        |d      j                  dd       t        |      }|j                  ddd       t        |d      j                  dd       t         j                  dd j                  d
         }|j                  dd       d j                  d<   d j                  d<   g d _        i  _        t         j                        D ]r  \  }}t        || j                        }	|	j                  d|d
z   dz  dz         |	j                  d j                         |	 j                  |j                         <   t  j                  D 
cg c]  }
 j                   j#                  |
d
        }}
t%        | j                  |dd  j&                  !       _         j(                  j+                  d j,                  d   "       t         j                        D ]H  \  }}
 j.                  j#                  |
 j0                        } j(                  j+                  ||#       J  j(                  j                  dd$        j(                  j3                           j(                  j5                  d% j6                          j(                  j                  d& j8                          j(                  j                  d' j6                          j(                  j                  d( j:                          j(                  j                  d) j<                          j(                  j                  d* j>                         |j	                  d
d
       d+d, j@                  fd-d. jB                  fg}i  _"        t        |      D ]  \  }\  }}	}t        ||	/      j                  d|d0       tG        |d1d2d3d34      }||f jD                  |<   |j                  d' jH                         |j                  d|f fd5	       |j                  d
|d6         j                  j                  d jH                         tK        |d7 j6                  d8       _&         jL                  j                  d9       tK        |d: jN                  d8       _(         jP                  j                  d;9       t        |d< j                  d    j                  d
   =       _)        tU        |d>d  jV                  d
   d?d
@       _,         j[                           jX                  j                  d;9        jR                  j                  d9       y c c}
w )ANraisedr     r   )reliefborderpadxpadyr  Tboth)sidexpandr   r   )weight)height)columnrownews)r  r  stickyr      r     )r  r  r  bottomr   )sider   r  highlightthickness)CollectionsCorporaModelszAll Packages)textfontleftr  )r  r  z
<Button-1>   )column_weightsr  listbox_heightreprfunc)
foregroundr   )r  r   z<Double-Button-1>z<space>z<Return>z<Left>z<Right>z<Control-a>r   zServer Index:r   zDownload Directory:)r  r   couriergroovez#007aff)r  r  disabledforegroundr  c                 &    j                  |      S rA   
_info_edit)r   r>   r1   s     r4   <lambda>z-DownloaderGUI._init_widgets.<locals>.<lambda>  s    8Lr6   ewDownload)r  r  r   )r  RefreshrightrJ   )r  r  r     sunken)r   r  r  r  r  ).r   r  packgrid_rowconfiguregrid_columnconfiguregridr  
_tab_names_tabsr  r
   	_TAB_FONTr  _select_tabr   COLUMNSCOLUMN_WEIGHTSr[   r   _table_reprfuncr  columnconfig_MARK_COLORCOLUMN_WIDTHSDEFAULT_COLUMN_WIDTHfocusbind_to_listboxes	_download_table_mark	_prev_tab	_next_tab	_mark_allrs  r  _infor   
_info_saver   _download_button_refresh_refresh_button_progresslabelr   _PROGRESS_COLOR_progressbar_init_progressbar)r1   f1tabframe
tableframebuttonframe	infoframeprogressframer  tablabelr  r
  r   r   r>   callbackentrys   `                r4   r  zDownloaderGUI._init_widgets  sb   488HQQQG
E$V4
Qq)
!,b  q 19QAf52Y
qa7Biq8b  q 1"I	aQv6b  q 1HH111E1Ea1H
 	s3)*%& O
0FAs(4>>BEJJF1q5A+);J<JJ|T%5%56&+DJJsyy{#	 1 LP<<X<$--11&!<<XLL) ))
 	  t/?/?/B C"4<<0IAv&&**643L3LMEKK$$Qe$4 1 	62%%&94>>JD$4$45T^^44>>2DNN37 	&&q&3 OT]]32D4J4JK
 
)24%A%UH)%(--QAc-J#,$E  %h/DJJsOJJz4??3JJ|3%LMJJaQtJ4 *9  	lDOO4 !'j$..!
 	"""/%ia 
 	!!w!/ $++A.++A.	
 #++A.
 	 G,  f -W Ys   +#X)c                     t         j                        }t        |d      }|j                  dd j                  d       |j	                          |j                  dd fd	       |j                  d
d fd	       |j	                          |j                  dd j
                  	       |j	                          |j                  dd j                  d       |j                  dd|       t        |d      } j                  j                  dd  D ]t  }t         j                        }| j                  vsJ | j                  |<   | j                  v r|j                  d       |j                  |d| j                         v |j                  dd|       t        |d      } j                  j                  dd  D ]  }|j                  d|z  |f fd	        |j	                           j                  j                  dd  D ]  }|j                  d|z  |f fd	        |j                  dd|       t        |d      }|j                  dd j                   	       |j                  dd j"                  d       |j                  dd|        j                  j%                  d  j"                          j                  j'                  |!       y )"Nr   )tearoffr  Return)rB  	underliner  acceleratorzChange Server Index   c                  &     j                  d      S )Nr   r  rH   s   r4   r  z*DownloaderGUI._init_menu.<locals>.<lambda>  s    DOOE2r6   )rB  rH  r  zChange Download Directoryc                  &     j                  d      S )Nr   r  rH   s   r4   r  z*DownloaderGUI._init_menu.<locals>.<lambda>  s    DOON;r6   zShow Logr  Exitr   zCtrl-xFile)rB  rH  menur  )rB  rH  variabler  Viewz
Sort by %sc                 <    j                   j                  | d      S )N	ascendingr  sort_byrf  r1   s    r4   r  z*DownloaderGUI._init_menu.<locals>.<lambda>5  s    $++*=*=a*Mr6   )rB  r  zReverse sort by %sc                 <    j                   j                  | d      S )N
descendingrT  rV  s    r4   r  z*DownloaderGUI._init_menu.<locals>.<lambda><  s    $++*=*=a*Nr6   SortAboutInstructionsF1Helpz<F1>)rO  )r   r  add_commandr-  add_separator	_show_logr  add_cascader  column_namesr	   r  INITIAL_COLUMNSsetadd_checkbuttonr  abouthelpr  config)r1   menubarfilemenuviewmenur  varsortmenuhelpmenus   `       r4   r  zDownloaderGUI._init_menu  s   txx.+4>>x 	 	
 	 '2 	 	

 	-; 	 	

 	 :DNNS At|| 	 	
 	&AHE
 +kk..qr2F"C!2!2222(+Df%---
$$CAUAU %  3 	&AHE
 +kk..qr2F  "V+"(M !  3
 	 kk..qr2F  *V3"(N !  3
 	&AHE+7aL Atyyd 	 	
 	&AHEfdii(W%r6   c                     | j                   j                         D ]L  \  }}|j                         r| j                  j	                  |       2| j                  j                  |       N y rA   )r  r   r[   r  show_columnhide_column)r1   r  rl  s      r4   r  zDownloaderGUI._select_columnsJ  sL    ,,224KFCwwy''/''/	 5r6   c                 "   | j                   j                          	 | j                          | j                  j                  d       y # t        $ r}t	        d|       Y d }~6d }~wt
        $ r }t	        d|j                         Y d }~]d }~ww xY w)Nr  r  r   )	r  rI  r  r   r   r   r  r  r  r1   r   s     r4   r5  zDownloaderGUI._refreshQ  sr    ##%	>
 	1	  	61155 	>2AHH==	>s#   A 	BA""B.B		Bc                 |    | j                          | j                  |   \  }}d|d<   d|d<   |j                          y )Nnormalstater  r  )r3  r2  r+  )r1   info_keyrD  rC  s       r4   r  zDownloaderGUI._info_edit[  s:     JJx0!g"hr6   Nc                    | j                   }| j                  j                         D ]P  \  }}|d   dk(  r| |j                  |u r|j                  dk7  r|}1d|d<   d|d<    ||j                                R |j                          y )Nrv  disabledrG  r  r  )r  r2  r   widgetkeysymr[   r+  )r1   r   r+  rD  rC  s        r4   r3  zDownloaderGUI._info_saveb  s    #zz002OE8W~+}U!2qxx87K!+g"*h%  3 	r6   c                     | j                   j                  |   j                  d      r7t        |t              rd|z  S |dk  rd|dz  z  S |dk  rd|dz  z  S d	|d
z  z  S |dv rt	        |      S d|z  S )Nr  z  %si   z	  %.1f KBg      @i   @z	  %.1f MBg      0Az	  %.1f GBg      A)r   rJ   )r  rb  r  r9   r:   )r1   r  colvals       r4   r&  zDownloaderGUI._table_reprfunco  s    ;;##C(11&9#s#|#w"cIo66w"cIo66"cIo66'>s8OC<r6   c                     || j                   j                  k(  ry 	 || j                   _        | j                          | j                          y # t        $ r}t	        dt        |             Y d }~4d }~ww xY w)NzError Setting Server Index)r  r   r  r   r   r:   r  )r1   r   r   s      r4   rs  zDownloaderGUI._set_url  sa    $((,,	<DHHL 	  	<2CF;;	<s   !A 	A6A11A6c                 .   | j                   j                  |k(  ry || j                   _        	 | j                          | j                          y # t        $ r}t	        d|       Y d }~+d }~wt
        $ r }t	        d|j                         Y d }~Rd }~ww xY w)Nr  r  )r  r   r  r   r   r   r  r  )r1   r   r   s      r4   r  zDownloaderGUI._set_download_dir  s}    88  L0 !-	>
 		  	61155 	>2AHH==	>s#   A 	BA((B4BBc                    t        d| j                  j                         | j                  j	                         D ]  \  }}d|d<   |j                  dd        | j                  d   d   j                  d| j                  j                         | j                  d   d   j                  d| j                  j                         | j                  j	                         D ]
  \  }}d|d<    y )	Nzshowing inforu  rv  r   endr   r   ry  )r   r  r   r2  r   deleteinsertr   )r1   rD  cbs      r4   r  zDownloaderGUI._show_info  s    ndhhll+**,IE2%E'NLLE" - 	

5!##Atxx||4

>"1%,,Q0E0EF**,IE2'E'N -r6   c                    t        | j                        D ]`  \  }}|j                         | j                  k(  s$|dkD  s*| j                  |dz
     j                         | _        	 | j	                         c S  y # t
        $ r}t        d|       Y d }~~d }~wt        $ r }t        d|j                         Y d }~d }~ww xY w)Nr   r   r  r  )	r  r   r   _tabr  r   r   r   r  r1   r   r  rA  s       r4   r/  zDownloaderGUI._prev_tab  s    0FAsyy{dii'AE OOAE288:	F++--	 1
 ! >91== F:AHHEEFs$   &A::	C BC  B;;C c                    t        | j                        D ]v  \  }}|j                         | j                  k(  s$|t	        | j
                        dz
  k  s@| j                  |dz      j                         | _        	 | j                         c S  y # t        $ r}t        d|       Y d }~d }~wt        $ r }t        d|j                         Y d }~d }~ww xY w)Nr   r  r  )r  r   r   r  r   r!  r  r   r   r   r  r  s       r4   r0  zDownloaderGUI._next_tab  s    0FAsyy{dii'ATZZ11D,E OOAE288:	F++--	 1
 ! >91== F:AHHEEFs$   <B	CB**C6CCc                     |j                   d   j                         | _        	 | j                          y # t        $ r}t        d|       Y d }~y d }~wt        $ r }t        d|j                         Y d }~y d }~ww xY w)Nr  r  r  )rz  r   r  r  r   r   r   r  )r1   eventr   s      r4   r#  zDownloaderGUI._select_tab  se    LL(..0		> 	61155 	>2AHH==	>s    5 	A;AA;A66A;r   c                    | j                   j                         }| j                   j                          | j                  dk(  r| j                  j                         }n| j                  dk(  r| j                  j                         }nh| j                  dk(  r| j                  j                         }n>| j                  dk(  r| j                  j                         }nJ d| j                  z         |D cg c]  }| j                  |       }}| j                   j                  |       | j                  j                         D ]o  \  }}|| j                  k(  r.|j                  | j                  d   | j                  d          C|j                  | j                  d   | j                  d          q | j                   j!                  d	d
       | j#                          | j                   j%                  |        | j&                  j(                  d| j                   j*                  j,                  g| j                   j.                  j1                            | j&                  j(                  d| j                   j*                  j,                  g| j                   j.                  j1                           y c c}w )Nzall packagesr   r   r   r   zbad tab value %rr   r  r  r  rS  )order   i,  )r  selected_rowrG  r  r  rV   r   r   r   _package_to_columnsrd  r!  r   r  _FRONT_TAB_COLOR_BACK_TAB_COLORrU  _color_tabler  r  after
_scrollbarrd  _mlbyview)r1   r  r   rX   rowsrA  rB  s          r4   r  zDownloaderGUI._fill_table  s   {{//199&HH%%'EYY)#HH$$&EYY("HHOO%EYY-'HH((*E4(499441;@A54((.5A4  ****,JCdii#44Q7#44Q7   
 #33A6#33A6    - 	L<<( 	sDKK2266R9I9I9O9O9QRsDKK2266R9I9I9O9O9QR5 Bs   5J;c                     t        t        | j                              D ]=  }| j                  j	                  | j                  |df         }|| j                  |df<   ? | j                          y )Nr  r  )r  r   r  r  r   r  )r1   row_numr   s      r4   _update_table_statusz"DownloaderGUI._update_table_status  s[    S-.GXX__T[[,1F%GHF-3DKK)* / 	r6   c                    | j                   r | j                  | S t        t        | j                              D cg c]'  }| j                  |df   dk7  r| j                  |df   ) }}| j                  j                         }|s|| j                  |df   g}| j                  j                  || j                  j                        }d| _	        | j                  ||       y c c}w )Nr   rJ   r  )r  _download_threadedr  r   r  r  r  r   r   r  _download_cb)r1   r   r  marked	selectiondownload_iters         r4   r-  zDownloaderGUI._download  s     *4**A.. S-.
.{{36"b( KK\)*. 	 

 KK,,.	)/kk)\"9:;F..vtxx7L7LM-0
s   ,C$c                     	 t        |      } fd}t        |t              r j                  |j                         nt        |t              rU ||j                         |j                  % j                  |j                  j                          j                  d        y t        |t              r6 |d|j                   j                  z          xj"                  dz  c_        n`t        |t$              r! |d|j                  j                  z         n/t        |t&              r  |d|j                  j                  z         nt        |t(              r  |d	|j                  j                  z         nt        |t*              r  |d
|j                  j,                  z         nt        |t.              rZ xj"                  dz  c_         |d|j                   j                  z          j1                  |j                   j                         n5t        |t2              r% j1                  |j                  j                          j                  j	                   j4                   j6                  ||      }| j                  d<   y # t        $ rI  j                           j                  j	                  d j
                  d      }| j                  d<   Y y w xY w)Nr  r   r  c                 F    | j                   d<   j                  |        y Nr  r7  r  r&  r1   s    r4   r0  z(DownloaderGUI._download_cb.<locals>.show      *+D'IIaLr6   zDownloading collection %sr   zDownloading package %sPackage %s is up-to-date!Finished downloading %r.Unzipping %s#Finished downloading collection %r.)nextStopIterationr  r  r  _show_progressr  r9   r   r   r   r   rp   _selectr   rb   re   r  rm   r   r|   r   r,   rj   _clear_markru   	_DL_DELAYr  )r1   r  idsr   afteridr0  s   `     r4   r  zDownloaderGUI._download_cb	  s   	}%C	 c?+-\*{{&S[[^^,%34,s~~/@/@@A!01)CKKNN:;_-,s{{~~=> 23+ckknn<=./#++"6"66745!69J9JJKS^^../12S[[^^,((..1B1BMSVW(/n%O  	%%'hhnnR)<)<a@G,3DMM.)	s   J AKKc                     t        t        | j                              D ]3  }| j                  |df   |k(  s| j                  j                  |        y  y )Nr  )r  r   r  r  r1   r   r  s      r4   r  zDownloaderGUI._select5  sE    T[[)*C{{3,-3""3' +r6   c                 H   t        t        | j                              D ]  }| j                  | j                  |df      \  }}d\  }}| j                  j	                  |||||       | j                  j                  |d| j                  d   | j                  d           y )Nr  )blackwhite)r  selectforegroundr  selectbackgroundr   r   r  )r  r   r  
_ROW_COLOR	rowconfigitemconfigurer(  )r1   r  bgsbgfgsfgs         r4   r  zDownloaderGUI._color_table;  s    T[[)*Coodkk#x-&@AGB(GBKK!!!$!$ "  KK%%Q4#3#3A#64CSCSTUCV &  +r6   c                     t        t        | j                              D ](  }| j                  |df   |k(  sd| j                  |df<   * y )Nr  rJ   r   r  r   r  r  s      r4   r  zDownloaderGUI._clear_markL  sB    T[[)*C{{3,-3&(CF# +r6   c                 l    t        t        | j                              D ]  }d| j                  |df<    y )Nr  r   r  )r1   r   r  s      r4   r1  zDownloaderGUI._mark_allQ  s,    T[[)*C"%DKKQ +r6   c                     | j                   j                         }|dk\  r8| j                   |   d   dk7  rd| j                   |df<   nd| j                   |df<   | j                   j                  d       y )Nr   rJ   r  r   )r  )r  r  r  )r1   r   r  s      r4   r.  zDownloaderGUI._table_markU  sj    KK,,.	>{{9%a(B.,.IqL),/IqL)#r6   c                 h    dj                  | j                        }t        | j                  d|       y )Nr   zNLTK Downloader Log)r+   r  r   r  )r1   r  s     r4   r`  zDownloaderGUI._show_log^  s'    yy++,0$7r6   c                    g }t        | j                        D ]  \  }}|dk(  r|j                  d       |dk(  r|j                  |j                         >|dk(  r+|j                  | j                  j                  |             n|j                         j                  dd      }|j                  t        ||d              |S )z
        Given a package, return a list of values describing that
        package, one for each column in ``self.COLUMNS``.
        r   rJ   r  r  r   rR  zn/a)	r  r$  r   r   r  r   r   replacer   )r1   r   r  column_indexcolumn_nameattrs         r4   r  z!DownloaderGUI._package_to_columnsb  s    
 )24<<)@%L+q 

2,

366"(

488??3/0"((*223<

73e45 *A 
r6   c                 `    | j                   ry | j                  j                          d| _         y )NT)r  r  r  rs  s     r4   r  zDownloaderGUI.destroyx  s#    ??r6   c                    | j                   :| j                  j                         D ]  }| j                   j                  |        | j                  r| j
                  r| j                          | j                  j                          y rA   )	r  r  r   after_cancelr  r  _abort_downloadr  rG  )r1   r   r  s      r4   r  zDownloaderGUI._destroy~  sh    88==//1%%g. 2 !2!2  "
 	!r6   c                 <     | j                   j                  |i | y rA   )r  r  )r1   r  kwargss      r4   r  zDownloaderGUI.mainloop  s    4*6*r6   an      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                     	 t        | j                  d| j                  j                         dd       y #  t        | j                  d| j                  j                         d       Y y xY w)NzHelp: NLTK Downloaderr   fixed)r   r  r  )r   r  HELPr:  rs  s     r4   rg  zDownloaderGUI.help  sU    		U'		!	UTXX6		8IQSTs	   25 3A*c                     d}d}	 ddl m}  |||      j                          y # t        $ r t	        | j
                  ||       Y y w xY w)Nz'NLTK Downloader
Written by Edward LoperzAbout: NLTK Downloaderr   )Message)r   r  )tkinter.messageboxr  r0  ImportErrorr   r  )r1   r   ABOUTTITLEr  s        r4   rf  zDownloaderGUI.about  sF    ?(	-2E/446 	-TXXue,	-s   %  AAc                    | j                   }t        |d         t        |d         }}t        dt        |d         dz  | j                  z        D ]a  }|j	                  || j                  z  dz   d|| j                  z  |z
  dz
  |dz   | j                  ddt        |d	z  d
z
        dz  z   z         c |j                  d       |j                  dd       |j                  d|j                  dddd| j                  d                y )Nr   r  r   r  r   iz	#%02x0000r  r  r   r  )r   r   gradienthiddenrv  redbox)r   )r9  r   r  _gradient_widthcreate_lineabs
addtag_all
itemconfigaddtag_withtagcreate_rectangler8  )r1   rf  r   r  r  s        r4   r:  zDownloaderGUI._init_progressbar  s   AgJQx[)9vq3qz?Q.43G3GGHAMMD(((2-D(((61B6** BQUQY")<$<=   I 	
Z 	Zx0 	
a((Aq!$:N:Nq:Q(R	
r6   c                    | j                   }|)|j                  ddddd       |j                  dd       y t        |d         t        |d         }}|t        |      z  dz  d	z   }|j                  ddd||d	z          y )
Nr  r   r  r  r  r   r  r  r   )r9  coordsr  r   )r1   percentrf  r   r  r   s         r4   r  zDownloaderGUI._show_progress  s    ?HHXq!Q*LL8L4'
OS8-=6E#e*$+a/AHHXq!Q
3r6   c                    | j                   }| j                  s|j                  dd       y |j                  dd       |j                  d      \  }}}}|dk  r$|j	                  d| j
                  dz  dz
  d       n|j	                  dd	d       | j                  j                  d
| j                        }|| j                  d<   y )Nr  r  r  ru  ir  r  r   r5  r  _progress_alive)
r9  r  r  bboxmover  r  r  r  r  )r1   rf  x1y1x2y2r  s          r4   r  zDownloaderGUI._progress_alive  s      LL8L4LL8L4VVJ/NBBTzzD$8$81$<#A1Ez2q)hhnnS$*>*>?G/6DMM+,r6   c                    | j                   r| j                          y d| j                  d<   t        t	        | j
                              D cg c]'  }| j
                  |df   dk7  r| j
                  |df   ) }}| j
                  j                         }|s|| j
                  |df   g}t        | j                  j                  | j                  j                        }| j                  g k(  sJ | j                  g k(  sJ | j                  ||| j                  | j                  | j                        j                          d| _        d| _         | j#                          | j%                          y c c}w )NCancelr  r   rJ   r  T)r  r  r4  r  r   r  r  r   r  r   r   r  r  _DownloadThreadr  startr  _monitor_message_queuer  )r1   r   r  r  r  dss         r4   r  z DownloaderGUI._download_threaded  sg      " )1f% S-.
.{{36"b( KK\)*. 	 

 KK,,.	)/kk)\"9:;F
 dhh&;&;< ''2---))R///$$&&	
 %'  ##% 	A
s   ,E1c                     | j                   rP| j                  j                          | j                  j	                  d       | j                  j                          y y )Nabort)r  r  acquirer  r   releaserH   s    r4   r  zDownloaderGUI._abort_download)  sH    '')&&--g6'') r6   c                       e Zd Zd Zd Zy)DownloaderGUI._DownloadThreadc                     || _         || _        || _        || _        || _        t
        j                  j                  |        y rA   )data_serverr   lockmessage_queuer  r  Threadr5   )r1   r   r   r  r  r  s         r4   r5   z&DownloaderGUI._DownloadThread.__init__0  s;    *DDJDI!.DDJ%%d+r6   c                    | j                   j                  | j                        D ]  }| j                  j	                          | j
                  j                  |       | j                  r7| j
                  j                  d       | j                  j                           y | j                  j                           | j                  j	                          | j
                  j                  d       | j                  j                          y )Nabortedfinished)	r   r   r   r  r  r  r   r  r  r  s     r4   r  z!DownloaderGUI._DownloadThread.run8  s    ''55djjA		!!#""))#.::&&--i8II%%'		!!# B II%%j1IIr6   N)rM   rN   rO   r5   r  r8   r6   r4   r  r  /  s    	,	 r6   r  r  c                 \     fd} j                   j                         sy  j                  D ]x  }|dk(  s|dk(  r j                          d _        d j
                  d<    j                  d d =  j                  d d =  j                   j                          |dk(  r |d        j                  d         y  j                  j                  d j                  d       }| j                  d	<    y t        |t              r j                  |j                         t        |t              r] ||j                          |j"                  % j%                  |j"                  j&                          j                  d        d _         y t        |t(              r6 |d
|j*                  j&                  z          xj,                  dz  c_        t        |t.              rP j0                  j3                  |j"                  j&                          |d|j"                  j&                  z         t        |t4              r! |d|j"                  j&                  z         4t        |t6              r! |d|j"                  j&                  z         et        |t8              r! |d|j"                  j:                  z         t        |t<              r! |d|j"                  j&                  z         t        |t>              r[ xj,                  dz  c_         |d|j*                  j&                  z          jA                  |j*                  j&                         2t        |tB              sD j                           jA                  |j"                  j&                         {  j                  rd jD                  d<    j                  d d =  j                   j                           j                  j                   jF                   jH                        }| j                  d	<   y )Nc                 F    | j                   d<   j                  |        y r  r  r  s    r4   r0  z2DownloaderGUI._monitor_message_queue.<locals>.showI  r  r6   r  r  Fr  r  zDownload aborted!r  r  r4  r   zDownloading package %rr  r  r  zFinished installing %sr  zAborting download...)%r  r  r  r  r  r4  r  r  r  r  r  r  r9   r   r   r   r   rp   r  r   rb   re   r  rm   r  rI  r   r|   r   r,   r   rj   r  ru   r7  _MONITOR_QUEUE_DELAYr  )r1   r0  r   r  s   `   r4   r  z$DownloaderGUI._monitor_message_queueH  s-   	
 ""**,++Cj C9$4))+$)!0:%%f-,,Q/..q1##++-)#,-''-  #hhnnS$2E2EtLG>EDMM":; C1##CLL1C.S[[!;;*LL0##D)$)!C!7803>>3D3DDE  A% C!45++CKKNN;->?C103;;>>AB C!67/#++..@AC!23^ckk&:&::;C!34->?C!89  A% :S^^=N=NNO  !2!23C!56))+  0g ,p %%*@D' $$Q'##% ((..!:!:D<W<WX29./r6   TrA   )FrM   rN   rO   rP   r$  r%  r)  r*  rc  rf  r  r   r   r   r   r   r  r(  r  r  r8  r"  r5   r  r  r  r  r5  r  r3  r&  rs  r  r  r/  r0  r#  r  _rowsr  r  r-  r  r  r  r  r  r1  r.  r`  r  r  r  r  r   dedentr  rg  rf  r  r:  r  r  r  r  r  r  r  r	  r  r8   r6   r4   r  r    s   GD QQ?NC M<   COA G|| G|| G||  'O 	.,*  "2	J #K (&O&O$I/5b
m.^C&J0  (	F	F> DE'SR1& I*0X")
&$8,"+ 8??	D:U- O
(47$*X* )**  . I:r6   r  c                     t        | t              r!t        | d      5 }t        |      cddd       S t        |       S # 1 sw Y   t        |       S xY w)zz
    Calculate and return the MD5 checksum for a given file.
    ``file`` may either be a filename or an open stream.
    rbN)r9   r:   r  _md5_hexdigest)r*  r"  s     r4   rU  rU    sF    
 $$!&) $ $s	   =Ac                     t               }	 | j                  d      }|s	 |j                         S |j                  |       6)Nr  )r   r  r0   	hexdigest)fp
md5_digestr%  s      r4   r  r    sD    J
	"!! 	% 	 r6   c                 ^    t        | ||      D ]  }t        |t              st        |       y)z\
    Extract the contents of the zip file ``filename`` into the
    directory ``root``.
    N)r   r9   r   r   )r,   rootr  r   s       r4   r.   r.     s,    
 xw7g|,G$$ 8r6   c              #     K   |r`t         j                  j                  dt        j                  j                  |       d   z         t         j                  j                          	 t        j                  |       }|j                  |       |rt                y y # t        j                  $ r t        | d       Y y t        $ r}t        | |       Y d }~y d }~ww xY ww)Nr  r   zError with downloaded zip file)r|  stdoutr  r'   r(   r*   flushzipfileZipFile
BadZipFiler   r   
extractallr   )r,   r  r  zfr   s        r4   r   r     s     

"''--*A!*DDE

__X& MM$   8%EFF 8Q''s<   A#C &B ;C !C;C =CCC CC c                    g }t        t        j                  j                  | d            D ]  \  }}}t        j                  |j
                        }| d| dt        j                  j                  |j
                        d    }t        d |j                         D              }|j                  dd|z         |j                  dd|j                  z         |j                  ddt        |j
                        z         |j                  d	|       |j                  d
      s|j                  d
|       |j                  |        t        t        t        j                  j                  | d                  }	t               }
||	z   D ]R  }|j                  d      |
v rt!        d|j                  d      z        |
j#                  |j                  d             T t%        j&                  d      }|j                  t%        j&                  d             |d   j)                  t+        |d              |j                  t%        j&                  d             |d   j)                  t+        |	d              t-        |       |S )a}  
    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.
    rV   r   r   c              3   4   K   | ]  }|j                     y wrA   )	file_size)r   zf_infos     r4   r  zbuild_index.<locals>.<genexpr>  s     K]'G--]s   r    z%sr   r!   r   r   r   r   zDuplicate UID: %srx  r   c                 $    | j                  d      S Nr   r[   ro   s    r4   r  zbuild_index.<locals>.<lambda>	  s    7;;t;Lr6   r   c                 $    | j                  d      S r#  r$  rd   s    r4   r  zbuild_index.<locals>.<lambda>	  s    PTAUr6   )_find_packagesr'   r(   r+   rO  r,   r*   r  infolistrd  rP  rU  r[   r   r   _find_collectionsr   addr   Elementrd  r   _indent_xml)r  base_urlrV   pkg_xmlr  r   zipstatr   r    r   uidsrX   top_elts                r4   build_indexr1    s   > H-bggll4.LMV''"++&
!F81RWW]]2;;%?%B$CDKR[[]KK 	OTM%9:FD7??23J}R[['A ABHf%{{5!KKs# 	   N$ (dM)JKLK 5D;&88D>T!0488D>ABB$  ' !!+.GNN;&&z23AJfX+LMNNN;&&}56AJf[.UVWNr6   c                 p   t        |       dkD  r| j                  xs dj                         dz   |z   dz   | _        | D ]  }t        ||dz           | dd D ].  }|j                  xs dj                         dz   |z   dz   |_        0 | d   j                  xs dj                         dz   |z   | d   _        yy)z
    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.
    r   rJ   r   r6  Nr   )r   r  r:  r+  tail)r=   r   r\   s      r4   r+  r+  	  s     3x!|HHN))+d2V;dBEv}- "XE***113d:VCdJEJ B*113d:VCB r6   c                 n   t         j                  j                  t         j                  j                  |      d         d   | j	                  d      k7  r*t        dj                  | j	                  d                  t        fd|j                         D              rt        ddd      y	)
zr
    Helper for ``build_index()``: Perform some checks to make sure that
    the given package is consistent.
    r   r   r   z&package identifier mismatch ({} vs {})c              3   V   K   | ]   }|k7  xr |j                  d z           " ywr   Nr  r   r   uids     r4   r  z!_check_package.<locals>.<genexpr>9	  s.     
VDCK:c	 :::   &)Zipfile ..zip does not expand to a single subdirectory r   N)	r'   r(   r)   r*   r[   r   r   r  namelist)r-  zipfilenamer  r9  s      @r4   _check_packager?  ,	  s     ''

277==5a8
9!
<C{{4C4;;GKK<MsS
 	

 
V
VV"%s,
 	
 Wr6   c                 l   t        j                  ddd| gt         j                  t         j                        }|j                         \  }}|j                  dk7  s|s|sDt        dt        j                  j                  |       d   dt        j                  |            |j                         d	   S )
z
    Helper for ``build_index()``: Calculate the subversion revision
    number for a given file (by using ``subprocess`` to run ``svn``).
    svnr   z-v)r  r  r   z#Error determining svn_revision for r   r   r  )
subprocessPopenPIPEcommunicate
returncoder   r'   r(   r*   r   r   )r,   re  r  r  s       r4   _svn_revisionrG  A	  s    
 		$)	A
 }}VV||qF&ww}}X&q)8==+@B
 	
 <<>!r6   c              #     K   t        j                  |       D ]d  \  }}}|D ]Y  }|j                  d      st         j                  j	                  ||      }t        j                  |      j                          [ f yw)z
    Helper for ``build_index()``: Yield a list of ElementTree.Element
    objects, each holding the xml for a single package collection.
    .xmlN)r'   rW  r  r(   r+   r   r;   rc  )r  dirname_subdirsrS  r,   xmlfiles         r4   r(  r(  T	  sg     
 %'GGDM 5H  ('',,w9!''088::  %2s   3B A
B c           
   #     K   ddl m} g }t        j                  |       D ]  \  }}}dj	                   || |            }|D ]  }|j                  d      rt        j                  j	                  ||      }|dd dz   }		 t        j                  |	      }
	 t        j                  |      j                         }t        j                  j                  |dd       d
   |j                  d      k7  r!t        d|j                  d      dd      t!        fd|
j#                         D              rt        ddd      ||
|f |j                  d      s!t        j                  j%                  |      d   }t        j                  j	                  ||dz         }t        j                  j'                  |      rt)        j*                  | d|dz    d| dd        	 |j-                  d        y# t        $ r}t        d|	d	|       |d}~ww xY w# t        $ r}t        d|d	|       |d}~ww xY w# t        $ r Y 7w xY ww)a  
    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').
    r   )
_path_fromr   rI  Nr5  r  zError reading file z!
r   r   zpackage identifier mismatch (z vs r   c              3   V   K   | ]   }|k7  xr |j                  d z           " ywr6  r7  r8  s     r4   r  z!_find_packages.<locals>.<genexpr>	  s5       - S[Cs)C%CC -r:  r;  r<  z exists, but z' cannot be found! This could mean that z can not be downloaded.r  )
stacklevelz.svn)nltk.corpus.reader.utilrN  r'   rW  r+   r  r(   r  r  r   r   r   r;   rc  r*   r[   r  r=  r)   r  warningswarnr  )r  rN  rV   rJ  subdirsrS  relpathr,   xmlfilenamer>  r  r   r-  resourcenamer9  s                 @r4   r&  r&  `	  sQ     3 H#%774=%((:dG45H  ( ggll7H=)#2.7Y 5BY)//<DDFG
 ggmmK$45a8;;t$+$$+KK$5s<    "  %58#? 
 r7**""6*!ww//9!< ggll7L64IJww~~k2MM#*M,2G1H I00<~=TV#$O \	NN6"c $1 ! Y$':;/QC%PQWXXY ! Y$':;/QC%PQWXXYL  		sz   A=IH#H):B(I$A$I
&I1II	H&H!!H&&I)	I	2II		I	IIIIc                  >    t        t              j                          y rA   )r  _downloaderr  r8   r6   r4   download_shellrZ  	  s    K $$&r6   c                  >    t        t              j                          y rA   )r  rY  r  r8   r6   r4   download_guir\  	  s    +'')r6   c                  ,    t         j                          y rA   )rY  r0   r8   r6   r4   r0   r0   	  s    r6   __main__)OptionParserz-dz--dirdirz!download package to directory DIRDIR)destrg  metavarz-qz--quietr<  
store_truezwork quietly)rb  actiondefaultrg  z-fz--forcer   z"download even if already installedz-ez--exit-on-errorr=  zexit if an error occursz-uz--urlr   NLTK_DOWNLOAD_URLzdownload server index url)rb  rf  rg  )r   )r   r   r<  r   r=  )r   r<  r   r=  r
  r7  )]rP   r8  r  r'   shutilrB  r|  r   r  r^  rR  r  hashlibr   	xml.etreer   r  tkinterr   r   r   r   r	   r
   r   r   r   r  r   nltk.draw.tabler   nltk.draw.utilr   r  r   urllib.errorr   r   urllib.requestr   r`  r   rS   r`   rb   rj   rm   ru   ry   r|   r   r   r   r   r   r   r   r   r  r  rU  r  r.   r   r1  r+  r?  rG  r(  r&  rY  r;  rZ  r\  r0   rM   optparser_  parser
add_optionry  r[   
parse_argsr  r  r   
downloaderpkg_idr`  r<  r   r=  rvr8   r6   r4   <module>rw     s\  <~Yt   	   
       !	GWWW,%'
 - " Z( Z(z&+ &+\! !
%. %%/ %+ , , - ) * ' $ #$ #!' !)0 )_
( _
(Db bJO: O:p "%4CLD 
*&	;AV l'* z%^F
0      1   &   

23(   '')OWdW-E-EFJF$$!$[[mmmm%33 % B U{w44  	 ----!//	 	 	
w KH  GHs   *K 	K,+K,