
    /hj             	          S r  SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKJr  SSKJr   SrSSKJrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SS	KJ r   SSK#J$r$J%r%  SSK&J'r'  SSK(r( " S S5      r) " S S5      r* " S S5      r+ " S S\+5      r, " S S\+5      r- " S S\+5      r. " S S\+5      r/ " S S\+5      r0 " S S\+5      r1 " S S \+5      r2 " S! S"\+5      r3 " S# S$\+5      r4 " S% S&\+5      r5 " S' S(\+5      r6 " S) S*\+5      r7 " S+ S,\+5      r8 " S- S.5      r9 " S/ S05      r: " S1 S25      r;S3 r<S4 r=S_S5 jr>S_S6 jr?S7 r@S`S8 jrAS9 rBS: rCS; rDS< rE\9" 5       rF\FR                  rGS= rHS> rIS? rJ\KS@:X  GaM  SSAKLJMrM  \M" 5       rN\NR                  SBSCSDSESFSG9  \NR                  SHSISJSKS
SLSM9  \NR                  SNSOSPSKS
SQSM9  \NR                  SRSSSTSKS
SUSM9  \NR                  SVSWSX\R                  R                  SY5      SZS[9  \NR                  5       u  rSrT\9" \SR                  S\9rV\T(       a`  \T HY  rW\VR                  \W\SR                  \SR                  \SR                  \SR                  S]9r\\\S
:X  d  MF  \SR                  (       d  MY    g   g\VR                  \SR                  \SR                  \SR                  \SR                  S^9  gg! \! a    S
r\"r GNf = f)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                   T    \ rS rSrSr           S	S jr\S 5       rS rS r	Sr
g)
Package   a  
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l          U=(       d    UU l         X@l         X l         [	        U5      U l         [	        U5      U l         Xpl         Xl         Xl	         Xl
         Xl         Xl         [        R                  R                  UR!                  S5      S   5      S   n[        R                  R#                  XAU-   5      U l         ['        [	        U5      5      U l         U R*                  R-                  U5        g )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                   G/var/www/auris/envauris/lib/python3.13/site-packages/nltk/downloader.py__init__Package.__init__   s    " 3JB	-	4 EI	: /	 !4(<"0	, 3%ggsyy~b1215V#X6	3 #e*%
	 	R     c                     [        U [        5      (       a  [        R                  " U 5      n U R                   H(  n[        U R                  U   5      U R                  U'   M*     [        S0 U R                  D6$ )N )
isinstancestrr   parseattribr   )xmlkeys     r5   fromxmlPackage.fromxml  sY    c3##C(C::C!#**S/2CJJsO $$$r8   c                 4    U R                   UR                   :  $ Nr   r2   others     r5   __lt__Package.__lt__      ww!!r8   c                      SU R                   -  $ )Nz<Package %s>rE   r2   s    r5   __repr__Package.__repr__   s    ''r8   )r'   r"   r%   r$   r-   r   r&   r   r    r   r#   r/   r!   r   )N NNNNUnknownrP   rP   rP   T__name__
__module____qualname____firstlineno____doc__r6   staticmethodrA   rH   rM   __static_attributes__r:   r8   r5   r   r      sO     C!J % %"(r8   r   c                   >    \ rS rSrSrS	S jr\S 5       rS rS r	Sr
g)

Collectioni$  z
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l          U=(       d    UU l         X l         S U l         U R                  R                  U5        g rD   )r   r   childrenpackagesr0   r1   )r2   r   r\   r   r3   s        r5   r6   Collection.__init__+  sD    6JB	0 	, 	3 	R r8   c                 ^   [        U [        5      (       a  [        R                  " U 5      n U R                   H(  n[        U R                  U   5      U R                  U'   M*     U R                  S5       Vs/ s H  o"R                  S5      PM     nn[        SSU0U R                  D6$ s  snf )Nitemrefr\   r:   )r;   r<   r   r=   r>   findallgetrZ   )r?   r@   childr\   s       r5   rA   Collection.fromxml=  s    c3##C(C::C!#**S/2CJJsO 25++f2EF2EIIe$2EF:8:szz:: Gs   7B*c                 4    U R                   UR                   :  $ rD   rE   rF   s     r5   rH   Collection.__lt__F  rJ   r8   c                      SU R                   -  $ )Nz<Collection %s>rE   rL   s    r5   rM   Collection.__repr__I  s     477**r8   )r\   r   r   r]   rD   rQ   r:   r8   r5   rZ   rZ   $  s*    !$ ; ;"+r8   rZ   c                       \ rS rSrSrSrg)DownloaderMessageiR  zOA status message object, used by ``incr_download`` to
communicate its progress.r:   N)rR   rS   rT   rU   rV   rX   r:   r8   r5   rk   rk   R  s    !r8   rk   c                       \ rS rSrSrS rSrg)StartCollectionMessageiW  z<Data server has started working on a collection of packages.c                     Xl         g rD   
collectionr2   rp   s     r5   r6   StartCollectionMessage.__init__Z      $r8   ro   NrR   rS   rT   rU   rV   r6   rX   r:   r8   r5   rm   rm   W  s
    F%r8   rm   c                       \ rS rSrSrS rSrg)FinishCollectionMessagei^  z=Data server has finished working on a collection of packages.c                     Xl         g rD   ro   rq   s     r5   r6    FinishCollectionMessage.__init__a  rs   r8   ro   Nrt   r:   r8   r5   rv   rv   ^  s
    G%r8   rv   c                       \ rS rSrSrS rSrg)StartPackageMessageie  z-Data server has started working on a package.c                     Xl         g rD   packager2   r}   s     r5   r6   StartPackageMessage.__init__h      r8   r|   Nrt   r:   r8   r5   rz   rz   e  
    7r8   rz   c                       \ rS rSrSrS rSrg)FinishPackageMessageil  z.Data server has finished working on a package.c                     Xl         g rD   r|   r~   s     r5   r6   FinishPackageMessage.__init__o  r   r8   r|   Nrt   r:   r8   r5   r   r   l  
    8r8   r   c                       \ rS rSrSrS rSrg)StartDownloadMessageis  z.Data server has started downloading a package.c                     Xl         g rD   r|   r~   s     r5   r6   StartDownloadMessage.__init__v  r   r8   r|   Nrt   r:   r8   r5   r   r   s  r   r8   r   c                       \ rS rSrSrS rSrg)FinishDownloadMessageiz  z/Data server has finished downloading a package.c                     Xl         g rD   r|   r~   s     r5   r6   FinishDownloadMessage.__init__}  r   r8   r|   Nrt   r:   r8   r5   r   r   z  
    9r8   r   c                       \ rS rSrSrS rSrg)StartUnzipMessagei  z,Data server has started unzipping a package.c                     Xl         g rD   r|   r~   s     r5   r6   StartUnzipMessage.__init__  r   r8   r|   Nrt   r:   r8   r5   r   r     s
    6r8   r   c                       \ rS rSrSrS rSrg)FinishUnzipMessagei  z-Data server has finished unzipping a package.c                     Xl         g rD   r|   r~   s     r5   r6   FinishUnzipMessage.__init__  r   r8   r|   Nrt   r:   r8   r5   r   r     r   r8   r   c                       \ rS rSrSrS rSrg)UpToDateMessagei  z/The package download file is already up-to-datec                     Xl         g rD   r|   r~   s     r5   r6   UpToDateMessage.__init__  r   r8   r|   Nrt   r:   r8   r5   r   r     r   r8   r   c                       \ rS rSrSrS rSrg)StaleMessagei  z3The package download file is out-of-date or corruptc                     Xl         g rD   r|   r~   s     r5   r6   StaleMessage.__init__  r   r8   r|   Nrt   r:   r8   r5   r   r     s
    =r8   r   c                       \ rS rSrSrS rSrg)ErrorMessagei  z Data server encountered an errorc                 h    Xl         [        U[        5      (       a  [        U5      U l        g X l        g rD   )r}   r;   	Exceptionr<   message)r2   r}   r   s      r5   r6   ErrorMessage.__init__  s$    gy))w<DL"Lr8   )r   r}   Nrt   r:   r8   r5   r   r     s
    *#r8   r   c                       \ rS rSrSrS rSrg)ProgressMessagei  z4Indicates how much progress the data server has madec                     Xl         g rD   progress)r2   r   s     r5   r6   ProgressMessage.__init__  s     r8   r   Nrt   r:   r8   r5   r   r     s
    >!r8   r   c                       \ rS rSrSrS rSrg)SelectDownloadDirMessagei  z:Indicates what download directory the data server is usingc                     Xl         g rD   download_dirr2   r   s     r5   r6   !SelectDownloadDirMessage.__init__  s    (r8   r   Nrt   r:   r8   r5   r   r     s
    D)r8   r   c                   `   \ rS rSrSrSr Sr Sr Sr Sr	 Sr
 S*S
 jr      S+S jrS rS rS rS rS rS,S jrS rS rS rS	S	SSSSS\R.                  4S jrS-S jrS-S jrS-S jrS-S jrS rS.S jrS-S jrS  r S! r!S" r"S# r#S$ r$\%" \#\$5      r&S% r'S& r(S' r)\%" \(\)5      r*S( r+S)r,g	)/
Downloaderi  zm
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                     U=(       d    U R                   U l         0 U l         0 U l         X l         S U l         S U l         0 U l         S U l         U R                  c  U R                  5       U l        g g rD   )
DEFAULT_URL_url_collections	_packages_download_dir_index_index_timestamp_status_cache_errorsdefault_download_dir)r2   server_index_urlr   s      r5   r6   Downloader.__init__  s    $8(8(8	7E?)I@ $	L  	
 R %!%!:!:!<D &r8   TFc                 6   SnUc  U R                   n[        SU-  5        U(       ae  [        SS[        U R                  5      -   -  5        [        SU R                  -  5        [        SS[        U R                  5      -   -  5        US-  nS=p/ n
U(       a  U
R	                  S5        U(       a  U
R	                  S	5        U
 GH  n[        S
UR                  5       -  5        US-  n[        [        X5      " 5       [        S9 GHF  nU R                  X5      nXR                  :X  a	  U(       a  M-  XR                  :X  a  SnXR                  :X  a  Sn	U R                  SU R                  SU R                  SU R                  S0U   n[        R                  " SUR                   =(       d    UR"                  -   SSS9SS  n[        SR%                  XR"                  R'                  SS5      U5      5        U[        UR)                  S5      5      -  nU(       d  GM  US:  d  GM"  [+        S5      nUR-                  5       S;   a      g SnGMI     [        5         GM     SnU(       a  US-  nU	(       a  US-  n[        [        R                  " US -   SS!S"95        g )#Nr   z!Using default data directory (%s)=   z Data server index for <%s>   Fr]   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)r2   r   show_packagesshow_collectionsheadermore_promptskip_installedlinesstaler   
categoriescategoryinfor   prefixr   
user_inputmsgs                     r5   listDownloader.list	  sA    --L5DE#c$))n,-./$));<#c$))n,-.QJE
j)m,"H%(--//0QJEwt68cBT8^^+ZZ' E\\)"GNNCJJLL#&&	
   }}		 4TWW5rX# n++FGGMM"c4JDQRTZZ-..;52:!&'@!AJ!'')Z7E/ C0 G7 #8 .@@C@@ChmmC#IBGHr8   c                 V    U R                  5         U R                  R                  5       $ rD   )_update_indexr   valuesrL   s    r5   r]   Downloader.packagesE  s!    ~~$$&&r8   c                     U R                  5         U R                  R                  5        VVs/ s H  u  pUR                  S:X  d  M  UPM     snn$ s  snnf Ncorporar   r   itemsr   r2   r   pkgs      r5   r  Downloader.corporaI  B    %)^^%9%9%;W%;	szzY?V%;WWW   AAc                     U R                  5         U R                  R                  5        VVs/ s H  u  pUR                  S:w  d  M  UPM     snn$ s  snnf r  r  r  s      r5   modelsDownloader.modelsM  r  r	  c                 V    U R                  5         U R                  R                  5       $ rD   )r   r   r   rL   s    r5   r   Downloader.collectionsQ  s#      ''))r8   c                 R    [        U[        5      (       a  U R                  U5      $ U$ rD   )r;   r<   r   )r2   
info_or_ids     r5   _info_or_idDownloader._info_or_idY  s$    j#&&99Z((r8   c              #     #    Uc  U R                   n[        U5      v   [        U[        [        45      (       a  U R                  XU5       S h  vN   g  U R                  U5      n[        U[        5      (       a?  [        U5      v   U R                  UR                  X#5       S h  vN   [        U5      v   g U R                  XBU5       S h  vN   g  N! [        [        4 a  n[        S SU SU 35      v    S nAg S nAff = f N` N:7f)NzError loading : )r   r   r;   r   tuple_download_listr  OSError
ValueErrorr   rZ   rm   incr_downloadr\   rv   _download_package)r2   r  r   forcer   es         r5   r  Downloader.incr_downloadh  s     --L*<88 j4-00**:UKKK	##J/D dJ''(..))$--MMM)$// --d%HHH% L $ 	t~j\A3%GHH	 N
 Is[   ADCDC 'AD(D	)'DDDD(D<DDDDc                 X    [        U[        5      (       a  g[        UR                  5      $ )Nr   )r;   r   r   r]   )r2   r`   s     r5   _num_packagesDownloader._num_packages  s!    dG$$t}}%%r8   c              #   8  ^ #    [        [        U5      5       H  n T R                  X   5      X'   M     [        U 4S jU 5       5      nSn[        U5       H  u  pH[        U[        5      (       a  SU-  n	O[        UR                  5      U-  n	T R                  XU5       H:  n
[        U
[        5      (       a  [        XzR                  U	-  -   5      v   M6  U
v   M<     USU	-  -  nM     g ! [        [        4 a  n[        X   U5      v    S nA  g S nAff = f7f)Nc              3   F   >#    U  H  nTR                  U5      v   M     g 7frD   )r  ).0r`   r2   s     r5   	<genexpr>,Downloader._download_list.<locals>.<genexpr>  s     F4--d33s   !r   g      ?d   )ranger   r  r  r  r   sum	enumerater;   r   r]   r  r   r   )r2   r  r   r  ir  num_packagesr   r`   deltar   s   `          r5   r  Downloader._download_list  s     s5z"A++EH5 # FFF 'GA$((l*DMM*\9))$eDc?33)(\\E5I*IJJI	 E e#H ( Z( "58Q//s.   DC,B;D,D<DDDDc              #   8  #    [        U5      v   [        S5      v   U R                  X5      nU(       d7  X@R                  :X  a(  [	        U5      v   [        S5      v   [        U5      v   g U R                  R                  UR                  S 5        [        R                  R                  X!R                  5      n[        R                  R                  U5      (       a2  X@R                  :X  a  [        U5      v   [        R                   " U5        [        R"                  " USS9  [        R"                  " [        R                  R                  X!R$                  5      SS9  ['        U5      v   [        S5      v    [)        UR*                  5      n[-        US5       n[/        SUR0                  S-  5      n[2        R4                  " 5        HX  n	UR7                  S5      n
UR9                  U
5        U
(       d    O.U	S	-  S:X  d  M9  [        [;        S
SSX-  -  -   5      5      v   MZ     S S S 5        UR=                  5         [C        U5      v   [        S
5      v   UR                  RE                  S5      (       a  [        R                  R                  X!R$                  5      nURF                  (       dK  [        R                  R                  [        R                  R                  XR                  5      5      (       a5  [I        U5      v   [K        X\SS9 H  nXl&        Uv   M     [O        U5      v   [        U5      v   g ! , (       d  f       GN!= f! [>         a8  n[A        USUR                  < SUR*                  < SU< 35      v    S nAg S nAff = f7f)Nr   r&  T)exist_ok   wbr    @     P   r   zError downloading z from <>:
  .zipF)verbose)(rz   r   r   r   r   r   r   popr   r(   r)   r,   r-   existsr   r   removemakedirsr   r   r   r   openmaxr    	itertoolscountreadwritemincloser  r   r   endswithr/   r   _unzip_iterr}   r   )r2   r   r   r  r   filepathinfileoutfile
num_blocksblocksr  zipdirr   s                 r5   r  Downloader._download_package  s    !$''a   T0>>1!$''!#&&&t,, 	tww- 77<<mm<77>>(###"4((IIh 	L40
BGGLL{{;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J'--&xGC"&KI H ).."4((A &%  	>BggtxxQRS  	sP   E:N=!M A$M#M)M DN
MM 
N.NNNN[nltk_data] c	           
      \  ^^ [         R                  " [        US9mUc  Ub  X l        U R	                  5         gSUU4S jjn	U R                  XU5       GHT  n
[        U
[        5      (       a  U	" U
R                  5        U(       a  [        U
R                  5      eU(       a    gSU l
        U(       da  T" S5        [        5       R                  5       nUS;   a3  U R                  U
R                  R                  UUUTUU5      (       d    gOUS;   a    gU(       a  M  [        U
[         5      (       a/  U	" SU
R"                  R                  -  5        TS	-  mT" T5        GM  [        U
[$        5      (       ab  T" T5        TS S
 mU R                  (       a"  U	" SU
R"                  R                  -  5        GMa  U	" SU
R"                  R                  -  5        GM  [        U
[&        5      (       a(  U	" SU
R                  R                  < SU< S35        GM  [        U
[(        5      (       a#  U	" SU
R                  R                  -  S5        GM  [        U
[*        5      (       a#  U	" SU
R                  R,                  -  S5        GM0  [        U
[.        5      (       d  GMH  U
R0                  nGMW     g)N)fileTc                 P   > T" [         R                  " U TU-   TU-   S-   S95        g )N    )initial_indentr   )r   r   )rK  prefix2r   print_tos     r5   show!Downloader.download.<locals>.show  s/    MM'-'7*07*:W*Dr8   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.rO   )	functoolsr   r   r   _interactive_downloadr  r;   r   r   r  r   r   stripdownloadr}   r   rm   rp   rv   rz   r   r   r-   r   r   )r2   r  r   quietr  r   halt_on_errorraise_on_errorprint_error_torV  r   choicerU  s        `      @r5   rb  Downloader.download  s7    $$U@ '%1"&&(  ))*EJc<00%%(55$$#'DL  !KL!&!Z/#'== # , % % & - .$ $ (-$ $z1#( u!#'=>>83>>;L;LLM') (#C)@AA (!'<<  F"%.."3"3!4
 !!ACNNDUDU!UV $C)<=="{{~~|= $C99@3;;>>QSWX $C):;;_s{{/C/CCTJ $C)ABB'*'7'7y Kz r8   c                 >    U R                  X5      U R                  :H  $ rD   )r   r   r2   r  r   s      r5   is_staleDownloader.is_staleE  s    {{:4

BBr8   c                 >    U R                  X5      U R                  :H  $ rD   )r   r   rj  s      r5   is_installedDownloader.is_installedH  s    {{:4FFr8   c                 x    Uc  U R                   R                  5         g U R                   R                  US 5        g rD   )r   clearr8  r2   r   s     r5   clear_status_cacheDownloader.clear_status_cacheK  s/    :$$&""2t,r8   c                 >   Uc  U R                   nU R                  U5      n[        U[        5      (       a  UR                   Vs/ s H  o@R                  UR                  5      PM     nnU R                  U;   a  U R                  $ U R                  U;   a  U R                  $ U R                  U;   a  U R                  U;   a  U R                  $ U R                  U;   a  U R                  $ U R                  $ [        R                  R                  X#R                  5      nX R                   :w  a  U R                  X65      $ UR                  U R                   ;  a(  U R                  X65      U R                   UR                  '   U R                   UR                     $ s  snf )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  r;   rZ   r]   r   r   r   r   r   r   r(   r)   r,   r-   _pkg_statusr   )r2   r  r   r   r  
pkg_statusrF  s          r5   r   Downloader.statusQ  sK    --L
+ dJ''9=G#++cff-JGzzZ'zz!+||#:-$2D2D
2R||###z1)))~~% ww||L--@H111''7777$"4"44262B2B42RD&&tww/))$''22) Hs   $Fc                     [         R                  R                  U5      (       d  U R                  $  [         R                  " U5      nUR                  [        UR                  5      :w  a  U R                  $ [        U5      UR                  :w  a  U R                  $ UR                  S5      (       a  US S n[         R                  R                  U5      (       d  U R                  $ [         R                  R                  U5      (       d  U R                  $ [        S [         R                   " U5       5       5      nXQR"                  :w  a  U R                  $ U R                  $ ! [
         a    U R                  s $ f = f)Nr6  r\  c              3      #    U  HO  u  pnU  HB  n[         R                  " [         R                  R                  X5      5      R                  v   MD     MQ     g 7frD   )r(   statr)   r,   st_size)r#  d_filesfs        r5   r$  )Downloader._pkg_status.<locals>.<genexpr>  sD       #4KA%A Q*+33 4#4s   AA)r(   r)   r9  r   r{  r  r|  r   r    r   md5_hexdigestr"   rD  r   isdirr(  walkr!   )r2   r   rF  filestatunzipdirr!   s         r5   rv  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                     U R                  5         U R                  5        H4  nU R                  U5      U R                  :X  d  M$  U R	                  X1US9  M6     g)z1
Re-download any packages whose status is STALE.
)rc  r   N)rs  r]   r   r   rb  )r2   rc  r   r  s       r5   r1   Downloader.update  sE     	!==?C{{34::-cv> #r8   c                 2   U R                   b4  Uc1  [        R                  " 5       U R                  -
  U R                  :  d  gU=(       d    U R                  U l        [
        R                  R                  [        R                  " [        U R                  5      5      R                  5       5      U l         [        R                  " 5       U l        U R                   R                  S5       Vs/ s H  n[        R                  U5      PM     nnU Vs0 s H  o"R                  U_M     snU l        U R                   R                  S5       Vs/ s H  n["        R                  U5      PM     nnU Vs0 s H  oDR                  U_M     snU l        U R$                  R'                  5        H  n[)        UR*                  5       H  u  pxXR                   ;   a  U R                   U   UR*                  U'   M2  XR$                  ;   a  U R$                  U   UR*                  U'   M_  [-        SR/                  U5      5        UR*                  U	 M     M     U R$                  R'                  5        H}  n0 nU/n	U	 HZ  n
[1        U
["        5      (       a  U	R3                  U
R*                  5        M5  [1        U
[        5      (       a  XU
R                  '   MZ  M\     UR'                  5       Ul        M     U R6                  R9                  5         gs  snf s  snf s  snf s  snf )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   getrootrb   r   rA   r   r   rZ   r   r   r)  r\   r   r   r;   extendr]   r   rq  )r2   r   pr]   cr   rp   r*  child_idqueuerd   s              r5   r   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TT1Wk: ++224J()<)<=~~--1^^H-EJ''*!2!22-1->->x-HJ''*HOO$
 #++A.  > 5 ++224JHLEeZ00LL0w//).UXX&  #+//"3J 5 	  "M Y4
 ;s   ,LL
L1Lc                 :    U R                  5         U R                  $ )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   rL   s    r5   indexDownloader.index  s     	{{r8   c                     U R                  5         XR                  ;   a  U R                  U   $ XR                  ;   a  U R                  U   $ [        SU-  5      e)zCReturn the ``Package`` or ``Collection`` record for the
given item.Package %r not found in index)r   r   r   r  rr  s     r5   r   Downloader.info  sW     	>>"%%"""$$R((82=>>r8   c                 *   U R                  5         U R                  R                  S5       H  nUR                  S5      U:X  d  M  Us  $    U R                  R                  S5       H  nUR                  S5      U:X  d  M  Us  $    [	        SU-  5      e)z-Return the XML info record for the given itemr  r   r  r  )r   r   rb   rc   r  )r2   r   r}   rp   s       r5   xmlinfoDownloader.xmlinfo  s    {{**+=>G{{4 B& ? ++--.FGJ~~d#r)!! H 82=>>r8   c                     U R                   $ )z)The URL for the data server's index file.)r   rL   s    r5   _get_urlDownloader._get_url  s    yyr8   c                 X    U R                   n U R                  U5        g!   X l         e = f)zm
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   )r2   r   original_urls      r5   _set_urlDownloader._set_url  s/    
 yy	s#	$Is     	)c                 "   S[         R                  ;   a  g[        R                  R                   HQ  n[         R                  R                  U5      (       d  M)  [        R                  R                  U5      (       d  MO  Us  $    [        R                  S:X  a(  S[         R                  ;   a  [         R                  S   nO0[         R                  R                  S5      nUS:X  a  [        S5      e[         R                  R                  US5      $ )aw  
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)   r9  r  is_writablesysplatform
expanduserr  r,   )r2   nltkdirhomedirs      r5   r   Downloader.default_download_dir  s    " "**, yy~~Gww~~g&&4>>+E+Eg+N+N &
 <<7"yBJJ'>jj+G gg((.G$ !NOO ww||G[11r8   c                     U R                   $ )z
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   rL   s    r5   _get_download_dirDownloader._get_download_dir=  s     !!!r8   c                 D    Xl         U R                  R                  5         g rD   )r   r   rq  r   s     r5   _set_download_dirDownloader._set_download_dirF  s    )  "r8   c                     [         (       a   [        U 5      R                  5         g [	        U 5      R                  5         g ! [         a    [	        U 5      R                  5          g f = frD   )TKINTERDownloaderGUImainloopr   DownloaderShellrunrL   s    r5   r`   Downloader._interactive_downloadQ  sT     7,d#,,. D!%%'  ,%))+,s   A #A'&A')r   r   r   r   r   r   r   r   )NN)NTTTFF)NFrD   )FrN  )-rR   rS   rT   rU   rV   r  r   r   r   r   r   r6   r   r]   r  r  r   r  r  r  r  r  r  stderrrb  rk  rn  rs  r   rv  r1   r   r  r   r  r  r  propertyr   r   r  r  r   r`  rX   r:   r8   r5   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	(r8   r   c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)r  i]  c                     Xl         g rD   _ds)r2   
dataservers     r5   r6   DownloaderShell.__init__^  s    r8   c                     [        S5        S[        S U 5       5      -
  [        U5      S-
  -  S-  n[        SUR                  U5      -   5        [        S5        g )NzK---------------------------------------------------------------------------D   c              3   8   #    U  H  n[        U5      v   M     g 7frD   )r   )r#  os     r5   r$  ;DownloaderShell._simple_interactive_menu.<locals>.<genexpr>c  s     01A   r   r   rR  )r   r(  r   r,   )r2   optionsspcs      r5   _simple_interactive_menu(DownloaderShell._simple_interactive_menua  sN    hC0000c'lQ6FG#Mfsxx(()hr8   c                 &   [        S5         U R                  SSSSSS5        [        S	5      R                  5       nU(       d  [        5         MC  UR	                  5       R                  5       S
   nUR                  5       SS  n US:X  a:  [        5         U R                  R                  U R                  R                  SSS9  OsUS:X  a  U R                  5         O\US:X  a  U R                  5         OEUS;   a  g US:X  a  U R                  U5        O&US:X  a  U R                  5         O[        SU-  5         [        5         GM7  ! [         a  n[        SU-  5         S nAN*S nAf[         a"  n[        SUR                  -  5         S nANTS nAff = f)NNLTK DownloaderTzd) Downloadzl) Listz
 u) Updatez	c) Configzh) Helpzq) QuitzDownloader> r   r   lF)r   r   hr  )r   r   r}  uzCommand %r unrecognizedzError reading from server: %szError connecting to server: %s)r   r  r   ra  r   r+   r  r   r   _simple_interactive_help_simple_interactive_config_simple_interactive_download_simple_interactive_updater   r   reason)r2   r   commandargsr  s        r5   r  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sH   ?E E E 2E 9E E (E 
FE!!F.FFc                 n   U(       a%  U H  n U R                   R                  USS9  M      g  [	        5         [	        S5        [        S5      nUR                  5       S:X  a2  U R                   R                  U R                   R                  SSSS9  Mg  UR                  5       S	;   a  g U(       a3  UR                  5        H  n U R                   R                  USS9  M      g M  ! [        [        4 a  n[	        U5         S nAM  S nAff = f! [        [        4 a  n[	        U5         S nAMo  S nAff = f)
NrR  r   Tz*Download which package (l=list; x=cancel)?  Identifier> r  F)r   r   r   r   r   rO   )
r  rb  r  r  r   r   r   r   r   r+   )r2   r  argr  r   r   s         r5   r  ,DownloaderShell._simple_interactive_download  s   HH%%c&%9  BC"#34
##%,HHMM--$$('+	 "  %%'>9(..0% HH--b-@ 1
 )   , !HH* !(4 %!!HH%s/   C%D%D5DDD4D//D4c           	      :    / nS=p#[        [        U R                  S5      " 5       [        S9 H_  nU R                  R	                  U5      U R                  R
                  :X  d  M8  UR                  UR                  UR                  45        Ma     [        5         U(       a  [        S5        U HL  u  pV[        R                  " SU-   SSS9S	S  n[        S
R                  UR                  SS5      U5      5        MN     [        5         [        S5      nUR                  5       S:X  a'  U H   u  pV U R                  R!                  USS9  M"     g UR                  5       S;   a  g O[        S5        g GMr  ! ["        [$        4 a  n	[        U	5         S n	A	Mk  S n	A	ff = f)NFr]   r   z/Will update following packages (o=ok; x=cancel)r   r   r   r   r   z  [ ] {} {}r   r   r  r  rR  r  r  zNothing to update.)r   r   r  r<   r   r   r   r   r   r   r   r   r   r   r   r   rb  r  r  )
r2   stale_packagesr   r   r   pidpnamer   r   r  s
             r5   r  *DownloaderShell._simple_interactive_update  sk   N##E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
% HH--c&-A '5
 %%'>9 : *+; , !(4 %!!HH%s   0E44FFFc                 p    [        5         [        S5        [        S5        [        S5        [        S5        g )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   rL   s    r5   r  (DownloaderShell._simple_interactive_help  s.    kV	
 	ABABr8   c                    [        5         [        S5        [        SU R                  R                  -  5        [        S[        U R                  R	                  5       5      -  5        [        S[        U R                  R                  5       5      -  5        [        5         [        S5        [        SU R                  R                  -  5        g )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   r]   r   rL   s    r5   _show_configDownloaderShell._show_config  s    no,-4s488;O;O;Q7RRS4s488;L;L;N7OOP&)>)>>?r8   c                    U R                  5          [        5         U R                  SSSS5        [        S5      R	                  5       R                  5       nUS:X  a  U R                  5         OUS:X  ao  [        S5      R	                  5       nUS	;   a  [        S
5        O[        R                  R                  U5      (       a  X R                  l
        Ot[        SU-  5        OeUS:X  aX  [        S5      R	                  5       nUS	;   a  [        S
5        O4UR                  S5      (       d  SU-   n X0R                  l        OUS:X  a  g GM9  ! [         a  n[        SU< SU 35         S nAN$S nAff = f)Nzs) Show Configzu) Set Server URLzd) Set Data Dirzm) Main MenuzConfig> rK  r}  z  New Directory> )rO   r   r   XQz  Cancelled!z)Directory %r not found!  Create it first.r  z  New URL> )zhttp://https://r  zError reading <r5  m)r  r   r  r   ra  r   r(   r)   r  r  r   
startswithr   r   )r2   r   
new_dl_dirnew_urlr  s        r5   r  *DownloaderShell._simple_interactive_config  sN   G)) "57H. z*00288:JS !!#s""#67==?
!99.)WW]]:..,6HH)E
RSs".44666.)"--.EFF",w"6F'. s"9 2 % F{&DEEFs   0E 
E1E,,E1r  N)rR   rS   rT   rU   r6   r  r  r  r  r  r  r  rX   r:   r8   r5   r  r  ]  s.    'R<@C@r8   r  c                      \ rS rSrSr/ SQr SSSSS.r SSS	S
S
SS.r Sr / SQr	 \ H  r
\
\;   a  M   e   \ H  r
\
\;   a  M   e   \	 H  r
\
\;   a  M   e   Sr\R                  S\R                  S\R                  S\R                   S0rSrSrSrSrSrSDS jrS rS rS rS rS rS rSES  jrS! rS" r S# r!S$ r"S% r#S& r$S' r%S(r&Sr'S) r(S* r)S+ r*S
r+S, r,S- r-S. r.S/ r/S0 r0S1 r1S2 r2S3 r3S4 r4S5 r5S6 r6\7Rp                  " S75      r9S8 r:S9 r;Sr<S: r=S; r>S< r?S= r@S> rA " S? S@\BR                  5      rDSArESB rFSCrGg)Fr  i  zI
Graphical interface for downloading packages from the NLTK data
server.
)rO   
IdentifierNameSizeStatusUnzipped Size	CopyrightContactLicenseAuthorSubdirChecksumr   r0  )rO   r  r  r   r   r   -   
      )rO   r  r  r  r  r      )rO   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                    Xl         X l        [        R                  " 5       U l        / U l        / U l        SU l        0 U l        / U l	        SU l
        U R                  S5        [        5       =o0l        UR                  S5        UR                  S5        UR!                  U R"                  S   S9  UR%                  SU R&                  5        UR%                  S	U R&                  5        SU l        0 U l        U R-                  5         U R/                  5          U R1                  5         U R;                  5         U R=                  5         U R>                  RA                  S5        U R>                  R%                  SU RB                  5        g ! [2         a  n[5        S
U5         S nAN}S nAf[6         a   n[5        SUR8                  5         S nANS nAff = f)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)r2   r  use_threadsr  r  s        r5   r6   DownloaderGUI.__init__\  s{   ' (nn.#% %'"!   		,- hX		#$!5!5a!89 	-- 		> 	1 	dmm4  	61155 	>2AHH==	>s$   F	 	
GF$$G1GGc                     U R                   R                  SR                  [        R                  " 5       SU R
                  -  U5      5        g )Nz{} {}{}z | )r  r   r   r  ctimer  r2   r   s     r5   r  DownloaderGUI._log  s9    !!TZZ\543C3C+CSI	
r8   c           	        ^  [        T R                  SSSSS9nUR                  SSSS	9  UR                  SS
S9  UR	                  SS
S9  [        USS9R                  SSS9  [        U5      nUR                  SS
SS9  [        U5      nUR                  SSSS9  [        U5      nUR                  SSSS9  [        USS9R                  SSS9  [        U5      nUR                  SSSS9  [        USS9R                  SSS9  [        T R                  SST R                  S
   S9nUR                  SSS9  ST R                  S'   ST R                  S'   / SQT l        0 T l        [        T R                  5       Hk  u  px[        X(T R                  S9n	U	R                  SUS
-   S-  S-  S9  U	R                  ST R                  5        U	T R                  UR                  5       '   Mm     T R                   V
s/ s H  n
T R                   R#                  U
S
5      PM!     nn
[%        UT R                  USS T R&                  S!9T l        T R(                  R+                  ST R,                  S   S"9  [        T R                  5       HD  u  pzT R.                  R#                  U
T R0                  5      nT R(                  R+                  X|S#9  MF     T R(                  R                  SSS$9  T R(                  R3                  5         T R(                  R5                  S%T R6                  5        T R(                  R                  S&T R8                  5        T R(                  R                  S'T R6                  5        T R(                  R                  S(T R:                  5        T R(                  R                  S)T R<                  5        T R(                  R                  S*T R>                  5        UR	                  S
S
S9  S+S,T R@                  4S-S.T RB                  4/n0 T l"        [        U5       H  u  nu  pn[        XYS/9R                  SUS0S9  [G        US1S2S3S3S49nUU4T RD                  U'   UR                  S'T RH                  5        UR                  SU4U 4S5 jj5        UR                  S
US6S9  M     T R                  R                  ST RH                  5        [K        US7T R6                  SS89T l&        T RL                  R                  SS99  [K        US:T RN                  SS89T l(        T RP                  R                  S;S99  [        US<T R                  S   T R                  S
   S=9T l)        [U        US>S T RV                  S
   S?S
S@9T l,        T R[                  5         T RX                  R                  S;S99  T RR                  R                  SS99  g s  sn
f )ANraisedr3     r   )reliefborderpadxpadyr  Tboth)sidexpandr   r   )weight)height)columnrownews)r@  rA  stickyr      r0     )r9  r:  r  bottomr   )sider   r8  highlightthickness)CollectionsCorporaModelszAll Packages)textfontleftr	  )rG  r9  z
<Button-1>   )column_weightsrH  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:)rL  r  couriergroovez#007aff)rM  r7  disabledforegroundrS  c                 &   > TR                  U5      $ rD   
_info_edit)r  r@   r2   s     r5   <lambda>-DownloaderGUI._init_widgets.<locals>.<lambda>  s    8Lr8   ewDownload)rL  r  r   )rG  RefreshrightrO   )rL  rS  r     sunken)r   r?  r  r7  r8  ).r   r  packgrid_rowconfiguregrid_columnconfiguregridr!  
_tab_names_tabsr)  r
   	_TAB_FONTr"  _select_tabr   COLUMNSCOLUMN_WEIGHTSrc   r   _table_reprfuncr+  columnconfig_MARK_COLORCOLUMN_WIDTHSDEFAULT_COLUMN_WIDTHfocusbind_to_listboxes	_download_table_mark	_prev_tab	_next_tab	_mark_allr  r  _infor   
_info_saver   _download_button_refresh_refresh_button_progresslabelr   _PROGRESS_COLOR_progressbar_init_progressbar)r2   f1tabframe
tableframebuttonframe	infoframeprogressframer*  tablabelr@  rP  r   r   r@   callbackentrys   `                r5   r&  DownloaderGUI._init_widgets  sV   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
0FA(4>>BEJJF1q5A+);J<JJ|T%5%56&+DJJsyy{#	 1 LP<<X<$--11&!<<XLL) ))
 	  t/?/?/B C"4<<0IA&&**643L3LMEKK$$Q$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%H)(--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   5&Wc                 |  ^  [        T R                  5      n[        USS9nUR                  SST R                  SS9  UR	                  5         UR                  SSU 4S jS	9  UR                  S
SU 4S jS	9  UR	                  5         UR                  SST R
                  S	9  UR	                  5         UR                  SST R                  SS9  UR                  SSUS9  [        USS9nT R                  R                  SS   Hv  n[        T R                  5      nUT R                  ;  d   eUT R                  U'   UT R                  ;   a  UR                  S5        UR                  USUT R                  S9  Mx     UR                  SSUS9  [        USS9nT R                  R                  SS   H  nUR                  SU-  U4U 4S jjS9  M     UR	                  5         T R                  R                  SS   H  nUR                  SU-  U4U 4S jjS9  M     UR                  SSUS9  [        USS9nUR                  SST R                   S	9  UR                  SST R"                  SS9  UR                  SSUS9  T R                  R%                  S T R"                  5        T R                  R'                  US!9  g )"Nr   )tearoffr^  Return)r  	underliner  acceleratorzChange Server Index   c                  &   > T R                  S5      $ )Nr   rY  rL   s   r5   r[  *DownloaderGUI._init_menu.<locals>.<lambda>  s    DOOE2r8   )r  r  r  zChange Download Directoryc                  &   > T R                  S5      $ )Nr   rY  rL   s   r5   r[  r    s    DOON;r8   zShow Logr0  Exitr   zCtrl-xFile)r  r  menur3  )r  r  variabler  Viewz
Sort by %sc                 <   > TR                   R                  U S5      $ )N	ascendingr+  sort_byr  r2   s    r5   r[  r  5  s    $++*=*=a*Mr8   )r  r  zReverse sort by %sc                 <   > TR                   R                  U S5      $ )N
descendingr  r  s    r5   r[  r  <  s    $++*=*=a*Nr8   SortAboutInstructionsF1Helpz<F1>)r  )r   r  add_commandrt  add_separator	_show_logr#  add_cascader+  column_namesr	   r%  INITIAL_COLUMNSsetadd_checkbuttonr*  abouthelpr"  config)r2   menubarfilemenuviewmenur@  varsortmenuhelpmenus   `       r5   r'  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%r8   c                     U R                   R                  5        HR  u  pUR                  5       (       a  U R                  R	                  U5        M7  U R                  R                  U5        MT     g rD   )r%  r  rc   r+  show_columnhide_column)r2   r@  r  s      r5   r*  DownloaderGUI._select_columnsJ  sL    ,,224KFwwyy''/''/	 5r8   c                 &   U R                   R                  5          U R                  5         U R                  R                  S5        g ! [         a  n[	        SU5         S nAN7S nAf[
         a   n[	        SUR                  5         S nAN_S nAff = f)Nr  r  r   )	r  rs  r(  r   r   r   r  r+  r,  r2   r  s     r5   r|  DownloaderGUI._refreshQ  sr    ##%	>
 	1	  	61155 	>2AHH==	>s#   A 
BA##B0BBc                 z    U R                  5         U R                  U   u  p#SUS'   SUS'   UR                  5         g )Nnormalstaterb  r7  )rz  ry  rr  )r2   info_keyr  r  s       r5   rZ  DownloaderGUI._info_edit[  s8     JJx0!g"hr8   Nc                 $   U R                   nU R                  R                  5        HV  u  p4US   S:X  a  M  Ub#  UR                  UL a  UR                  S:w  a  UnM6  SUS'   SUS'   U" UR                  5       5        MX     UR                  5         g )Nr  disabledr  rV  r7  )r+  ry  r   widgetkeysymrc   rr  )r2   r  rr  r  r  s        r5   rz  DownloaderGUI._info_saveb  s~    #zz002OEW~+}U!2qxx87K!+g"*h%  3 	r8   c                    U R                   R                  U   R                  S5      (       a>  [        U[        5      (       a  SU-  $ US:  a  SUS-  -  $ US:  a  SUS-  -  $ S	US
-  -  $ US;   a  [	        U5      $ SU-  $ )Nr  z  %si   z	  %.1f KBg      @i   @z	  %.1f MBg      0Az	  %.1f GBg      A)r   rO   )r+  r  rD  r;   r<   )r2   rA  colvals       r5   rm  DownloaderGUI._table_reprfunco  s    ;;##C(11&99#s##|#w"cIo66w"cIo66"cIo66'>s8OC<r8   c                     XR                   R                  :X  a  g  XR                   l        U R                  5         U R                  5         g ! [         a  n[	        S[        U5      5         S nAN5S nAff = f)NzError Setting Server Index)r  r   r(  r  r   r<   r)  )r2   r   r  s      r5   r  DownloaderGUI._set_url  s]    ((,,	<HHL 	  	<2CF;;	<s    A 
A6A11A6c                 2   U R                   R                  U:X  a  g XR                   l         U R                  5         U R                  5         g ! [         a  n[	        SU5         S nAN,S nAf[
         a   n[	        SUR                  5         S nANTS nAff = f)Nr  r  )r  r   r(  r   r   r   r  r)  )r2   r   r  s      r5   r  DownloaderGUI._set_download_dir  s{    88  L0 !-	>
 		  	61155 	>2AHH==	>s#   A 
BA))B6BBc                    [        SU R                  R                  5        U R                  R	                  5        H  u  pSUS'   UR                  SS5        M     U R                  S   S   R                  SU R                  R                  5        U R                  S   S   R                  SU R                  R                  5        U R                  R	                  5        H
  u  pSUS'   M     g )	Nzshowing infor  r  r   endr   r   r  )r   r  r   ry  r   deleteinsertr   )r2   r  cbs      r5   r)  DownloaderGUI._show_info  s    ndhhll+**,IE%E'NLLE" - 	

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

>"1%,,Q0E0EF**,IE'E'N -r8   c                    [        U R                  5       Hc  u  p#UR                  5       U R                  :X  d  M%  US:  d  M-  U R                  US-
     R                  5       U l         U R	                  5       s  $    g ! [
         a  n[        SU5         S nAM  S nAf[         a!  n[        SUR                  5         S nAM  S nAff = f)Nr   r   r  r  )	r)  rg  r   _tabr(  r   r   r   r  r2   r  r*  r  s       r5   rv  DownloaderGUI._prev_tab  s    0FAyy{dii'AE OOAE288:	F++--	 1
 ! >91== F:AHHEEFs$   )A>>
CBC'CCc                    [        U R                  5       Hy  u  p#UR                  5       U R                  :X  d  M%  U[	        U R
                  5      S-
  :  d  MC  U R                  US-      R                  5       U l         U R                  5       s  $    g ! [         a  n[        SU5         S nAM  S nAf[         a!  n[        SUR                  5         S nAM  S nAff = f)Nr   r  r  )r)  rg  r   r  r   rh  r(  r   r   r   r  r  s       r5   rw  DownloaderGUI._next_tab  s    0FAyy{dii'ATZZ11D,E OOAE288:	F++--	 1
 ! >91== F:AHHEEFs$   ?B
CB00C=CCc                     UR                   S   R                  5       U l         U R                  5         g ! [         a  n[        SU5         S nAg S nAf[         a   n[        SUR                  5         S nAg S nAff = f)NrL  r  r  )r  r   r  r(  r   r   r   r  )r2   eventr  s      r5   rj  DownloaderGUI._select_tab  se    LL(..0		> 	61155 	>2AHH==	>s    5 
A=AA=A88A=r   c                 ~   U R                   R                  5       nU R                   R                  5         U R                  S:X  a  U R                  R                  5       nOU R                  S:X  a  U R                  R                  5       nOjU R                  S:X  a  U R                  R                  5       nO?U R                  S:X  a  U R                  R                  5       nO SU R                  -  5       eU Vs/ s H  o0R                  U5      PM     nnU R                   R                  U5        U R                  R                  5        Hj  u  pVXPR                  :X  a,  UR                  U R                  S   U R                  S   S9  M@  UR                  U R                  S   U R                  S   S9  Ml     U R                   R!                  S	S
S9  U R#                  5         U R                   R%                  U5        U R&                  R(                  " SU R                   R*                  R,                  /U R                   R.                  R1                  5       Q76   U R&                  R(                  " SU R                   R*                  R,                  /U R                   R.                  R1                  5       Q76   g s  snf )Nzall packagesr  r  r   r   zbad tab value %rr   rS  r  r  r  )order   i,  )r+  selected_rowrq  r  r  r]   r  r  r   _package_to_columnsr  rh  r  r   _FRONT_TAB_COLOR_BACK_TAB_COLORr  _color_tabler,  r  after
_scrollbarr  _mlbyview)r2   r  r  r`   rowsr  r  s          r5   r(  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ii#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   9J:c                     [        [        U R                  5      5       H=  nU R                  R	                  U R                  US4   5      nX R                  US4'   M?     U R                  5         g )Nr  r   )r'  r   r+  r  r   r  )r2   row_numr   s      r5   _update_table_status"DownloaderGUI._update_table_status  sY    S-.GXX__T[[,1F%GHF-3KK)* / 	r8   c                    U R                   (       a  U R                  " U6 $ [        [        U R                  5      5       Vs/ s H+  nU R                  US4   S:w  d  M  U R                  US4   PM-     nnU R                  R                  5       nU(       d  Ub  U R                  US4   /nU R                  R                  X0R                  R                  5      nSU l	        U R                  XS5        g s  snf )Nr   rO   r  )r  _download_threadedr'  r   r+  r  r  r  r   r  _download_cb)r2   r  rA  marked	selectiondownload_iters         r5   rt  DownloaderGUI._download  s     **A.. S-.
.{{36"b( +DKK\)*. 	 

 KK,,.	)/kk)\"9:;F..vxx7L7LM-0
s   C3C3c                 $  ^   [        U5      nU 4S jn[        U[        5      (       a  T R                  UR                  5        GO5[        U[        5      (       aV  U" UR                  5        UR                  b%  T R                  UR                  R                  5        T R                  S 5        g [        U[        5      (       a6  U" SUR                   R                  -  5        T =R"                  S-  sl        GO[        U[$        5      (       a!  U" SUR                  R                  -  5        GOI[        U[&        5      (       a!  U" SUR                  R                  -  5        GO[        U[(        5      (       a   U" S	UR                  R                  -  5        O[        U[*        5      (       a   U" S
UR                  R,                  -  5        O[        U[.        5      (       aZ  T =R"                  S-  sl        U" SUR                   R                  -  5        T R1                  UR                   R                  5        O:[        U[2        5      (       a%  T R1                  UR                  R                  5        T R                  R	                  T R4                  T R6                  X5      nUT R                  S'   g ! [         aI    T R                  5         T R                  R	                  ST R
                  S5      nUT R                  S'    g f = f)Nr	  r   r  c                 F   > U TR                   S'   TR                  U 5        g NrL  r~  r  rK  r2   s    r5   rV  (DownloaderGUI._download_cb.<locals>.show      *+D'IIaLr8   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  r;   r   r   r   r   r}   _selectr   rm   rp   r  rz   r   r   r   r-   rv   _clear_markr   	_DL_DELAYr  )r2   r  idsr   afteridrV  s   `     r5   r  DownloaderGUI._download_cb	  s5   	}%C	 c?++-\**{{&S[[^^,%344,s~~/@/@@A!011)CKKNN:;_--,s{{~~=> 233+ckknn<=.//#++"6"667455!69J9JJKS^^../122S[[^^,((..1B1BMW(/n%O  	%%'hhnnR)<)<a@G,3DMM.)	s   J< <ALLc                     [        [        U R                  5      5       H5  nU R                  US4   U:X  d  M  U R                  R                  U5          g    g )Nr  )r'  r   r+  r,  r2   r   rA  s      r5   r	  DownloaderGUI._select5  sE    T[[)*C{{3,-3""3' +r8   c           	      <   [        [        U R                  5      5       Hz  nU R                  U R                  US4      u  p#Su  pEU R                  R	                  UUUUUS9  U R                  R                  USU R                  S   U R                  S   S9  M|     g )Nr   )blackwhite)rS  selectforegroundr  selectbackgroundr   r   r  )r'  r   r+  
_ROW_COLOR	rowconfigitemconfigurero  )r2   rA  bgsbgfgsfgs         r5   r  DownloaderGUI._color_table;  s    T[[)*Coodkk#x-&@AGB(GBKK!!!$!$ "  KK%%Q4#3#3A#64CSCSTUCV &  +r8   c                     [        [        U R                  5      5       H+  nU R                  US4   U:X  d  M  SU R                  US4'   M-     g )Nr  rO   r   r'  r   r+  r  s      r5   r
  DownloaderGUI._clear_markL  sB    T[[)*C{{3,-3&(CF# +r8   c                 p    [        [        U R                  5      5       H  nSU R                  US4'   M     g )Nr  r   r   )r2   r  rA  s      r5   rx  DownloaderGUI._mark_allQ  s,    T[[)*C"%DKKQ +r8   c                     U R                   R                  5       nUS:  a9  U R                   U   S   S:w  a  SU R                   US4'   OSU R                   US4'   U R                   R                  SS9  g )Nr   rO   r  r   )r,  )r+  r  r,  )r2   r  r  s      r5   ru  DownloaderGUI._table_markU  sj    KK,,.	>{{9%a(B.,.IqL),/IqL)#r8   c                 h    SR                  U R                  5      n[        U R                  SU5        g )Nr   zNLTK Downloader Log)r,   r  r   r  )r2   rL  s     r5   r  DownloaderGUI._show_log^  s'    yy++,0$7r8   c                    / n[        U R                  5       H  u  p4US:X  a  UR                  S5        M  US:X  a  UR                  UR                  5        MA  US:X  a,  UR                  U R                  R                  U5      5        Ms  UR                  5       R                  SS5      nUR                  [        XS5      5        M     U$ )zl
Given a package, return a list of values describing that
package, one for each column in ``self.COLUMNS``.
r   rO   r  r   r   r~  zn/a)	r)  rk  r   r   r  r   r   replacer   )r2   r  rA  column_indexcolumn_nameattrs         r5   r  !DownloaderGUI._package_to_columnsb  s    
 )24<<)@%Lq 

2,

366"(

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

73e45 *A 
r8   c                 j    U R                   (       a  g U R                  R                  5         SU l         g )NT)r$  r  r#  r  s     r5   r#  DownloaderGUI.destroyx  s#    ??r8   c                 .   U R                   b<  U R                  R                  5        H  nU R                   R                  U5        M      U R                  (       a!  U R
                  (       a  U R                  5         U R                  R                  5         g rD   )	r  r  r   after_cancelr  r  _abort_downloadr%  rq  )r2   r  r  s      r5   r-  DownloaderGUI._destroy~  sh    88==//1%%g. 2 !2!2  "
 	!r8   c                 <    U R                   R                  " U0 UD6  g rD   )r  r  )r2   r  kwargss      r5   r  DownloaderGUI.mainloop  s    4*6*r8   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                      [        U R                  SU R                  R                  5       SSS9  g !   [        U R                  SU R                  R                  5       SS9   g = f)NzHelp: NLTK Downloaderr   fixed)r   rM  rT  )r   r  HELPra  r  s     r5   r  DownloaderGUI.help  sU    		U'		!	UTXX6		8IQSTs	   /2 0A$c                     SnSn SSK Jn  U" X#S9R                  5         g ! [         a    [	        U R
                  X25         g f = f)Nz'NLTK Downloader
Written by Edward LoperzAbout: NLTK Downloaderr   )Message)r   r  )tkinter.messageboxr<  rV  ImportErrorr   r  )r2   r  ABOUTTITLEr<  s        r5   r  DownloaderGUI.about  sB    ?(	-2E/446 	-TXXu,	-s   !  AAc                    U R                   n[        US   5      [        US   5      p2[        S[        US   5      S-  U R                  -  5       H]  nUR	                  X@R                  -  S-   SX@R                  -  U-
  S-
  US-   U R                  SS[        US	-  S
-
  5      S-  -   -  S9  M_     UR                  S5        UR                  SSS9  UR                  SUR                  SSSSU R                  S   S95        g )Nr   r?  r   r3  r   iz	#%02x0000r4  rE  r   r
  )r   r   gradienthiddenr  redbox)r   )r  r   r'  _gradient_widthcreate_lineabs
addtag_all
itemconfigaddtag_withtagcreate_rectangler  )r2   r  r   r?  r*  s        r5   r  DownloaderGUI._init_progressbar  s   AgJQx[)9vq3qz?Q.43G3GGHAMM(((2-(((61B6** BQUQY")<$<=   I 	
Z 	Zx0 	
a((Aq!$:N:Nq:Q(R	
r8   c                     U R                   nUc&  UR                  SSSSS5        UR                  SSS9  g [        US   5      [        US   5      pCU[        U5      -  S-  S	-   nUR                  SSSXTS	-   5        g )
NrF  r   rC  rD  rE  r   r?  r&  r   )r  coordsrK  r   )r2   percentr  r   r?  r   s         r5   r  DownloaderGUI._show_progress  s|    ?HHXq!Q*LL8L4'
OS8-=6#e*$+a/AHHXq!Q
3r8   c                    U R                   nU R                  (       d  UR                  SSS9  g UR                  SSS9  UR                  S5      u  p#pEUS::  a$  UR	                  SU R
                  S-  S-
  S5        OUR	                  SS	S5        U R                  R                  S
U R                  5      nX`R                  S'   g )NrC  rD  rE  r  irE  rD  r   r\  ra  _progress_alive)
r  r  rK  bboxmoverG  r  r  rT  r  )r2   r  x1y1x2y2r  s          r5   rT  DownloaderGUI._progress_alive  s      LL8L4LL8L4VVJ/NBBTzzD$8$81$<#A1Ez2q)hhnnS$*>*>?G/6MM+,r8   c                    U R                   (       a  U R                  5         g SU R                  S'   [        [	        U R
                  5      5       Vs/ s H+  nU R
                  US4   S:w  d  M  U R
                  US4   PM-     nnU R
                  R                  5       nU(       d  Ub  U R
                  US4   /n[        U R                  R                  U R                  R                  5      nU R                  / :X  d   eU R                  / :X  d   eU R                  UUU R                  U R                  U R                  5      R                  5         SU l        SU l         U R#                  5         U R%                  5         g s  snf )NCancelrL  r   rO   r  T)r  r2  r{  r'  r   r+  r  r   r  r   r   r  r  _DownloadThreadr  startr  _monitor_message_queuerT  )r2   r  rA  r  r  dss         r5   r   DownloaderGUI._download_threaded  si      " )1f% S-.
.{{36"b( +DKK\)*. 	 

 KK,,.	)/kk)\"9:;F
 dhh&;&;< ''2---))R///$$&&	
 %'  ##% 	A
s   F/Fc                     U R                   (       aP  U R                  R                  5         U R                  R	                  S5        U R                  R                  5         g g )Nabort)r  r  acquirer  r   releaserL   s    r5   r2  DownloaderGUI._abort_download)  sH    '')&&--g6'') r8   c                        \ rS rSrS rS rSrg)DownloaderGUI._DownloadThreadi/  c                 ~    Xl         X l        X0l        X@l        XPl        [
        R                  R                  U 5        g rD   )data_serverr  lockmessage_queuerd  r  Threadr6   )r2   rk  r  rl  rm  rd  s         r5   r6   &DownloaderGUI._DownloadThread.__init__0  s1    *JI!.J%%d+r8   c                 (   U R                   R                  U R                  5       H  nU R                  R	                  5         U R
                  R                  U5        U R                  (       a7  U R
                  R                  S5        U R                  R                  5           g U R                  R                  5         M     U R                  R	                  5         U R
                  R                  S5        U R                  R                  5         g )Nabortedfinished)	rk  r  r  rl  re  rm  r   rd  rf  r2  s     r5   r  !DownloaderGUI._DownloadThread.run8  s    ''55djjA		!!#""))#.::&&--i8II%%'		!!# B II%%j1IIr8   )rd  rk  r  rl  rm  N)rR   rS   rT   rU   r6   r  rX   r:   r8   r5   r^  ri  /  s    	,	 r8   r^  r&  c                   ^  U 4S jnT R                   R                  5       (       d  g T R                   GH  nUS:X  d  US:X  a  T R                  5         ST l        ST R
                  S'   T R                  S S 2	 T R                  S S 2	 T R                   R                  5         US:X  a  U" S5        T R                  S 5          g T R                  R                  ST R                  S 5      nUT R                  S	'     g [        U[        5      (       a  T R                  UR                  5        M  [        U[        5      (       a^  U" UR                   5        UR"                  b%  T R%                  UR"                  R&                  5        T R                  S 5        ST l          g [        U[(        5      (       a7  U" S
UR*                  R&                  -  5        T =R,                  S-  sl        GM  [        U[.        5      (       aQ  T R0                  R3                  UR"                  R&                  5        U" SUR"                  R&                  -  5        GM  [        U[4        5      (       a"  U" SUR"                  R&                  -  5        GMU  [        U[6        5      (       a"  U" SUR"                  R&                  -  5        GM  [        U[8        5      (       a"  U" SUR"                  R:                  -  5        GM  [        U[<        5      (       a"  U" SUR"                  R&                  -  5        GM  [        U[>        5      (       a\  T =R,                  S-  sl        U" SUR*                  R&                  -  5        T RA                  UR*                  R&                  5        GMk  [        U[B        5      (       d  GM  T R                  5         T RA                  UR"                  R&                  5        GM     T R                  (       a  ST RD                  S'   T R                  S S 2	 T R                   R                  5         T R                  R                  T RF                  T RH                  5      nUT R                  S	'   g )Nc                 F   > U TR                   S'   TR                  U 5        g r  r  r  s    r5   rV  2DownloaderGUI._monitor_message_queue.<locals>.showI  r  r8   rr  rq  Fr^  rL  zDownload aborted!r&  r`  r[  r   zDownloading package %rr  r  r  zFinished installing %sr  zAborting download...)%r  re  r  r  r  r{  r  rf  r  r  r  r  r;   r   r   r   r   r}   r	  r   rm   rp   r  rz   r  rs  r   r   r   r-   r   rv   r
  r   r~  _MONITOR_QUEUE_DELAYr`  )r2   rV  r   r  s   `   r5   r`  $DownloaderGUI._monitor_message_queueH  sQ   	
 ""**,,++Cj C9$4))+$)!0:%%f-,,Q/..q1##++-)#,-''-  #hhnnS$2E2EtLG>EDMM":; C11##CLL1C..S[[!;;*LL0##D)$)!C!78803>>3D3DDE  A%  C!455++CKKNN;->?C1103;;>>AB C!677/#++..@AC!233^ckk&:&::;C!344->?C!899  A% :S^^=N=NNO  !2!23C!566))+  0g ,p %%*@D' $$Q'##% ((..!:!:D<W<WX29./r8   )r  r%  r$  r  r{  r  r  r  r  ry  r  r  r  r~  r}  r  rg  r+  rh  r  r  TrD   )HrR   rS   rT   rU   rV   rk  rl  rp  rq  r  r  r!  r   r   r   r   r   r  ro  r  r  r  ri  r6   r  r&  r'  r*  r|  rZ  rz  rm  r  r  r)  rv  rw  rj  r  _rowsr(  r  rt  r  r  r	  r  r
  rx  ru  r  r  r#  r-  r  r   dedentr9  r  r  rG  r  r  rT  r  r2  r  rn  r^  rw  r`  rX   r:   r8   r5   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,"+ ??	D:U- O
(47$*X* )**  . I:r8   r  c                     [        U [        5      (       a!  [        U S5       n[        U5      sSSS5        $ [        U 5      $ ! , (       d  f       N= f)zn
Calculate and return the MD5 checksum for a given file.
``file`` may either be a filename or an open stream.
rbN)r;   r<   r<  _md5_hexdigest)rP  rG  s     r5   r  r    sA    
 $$!&) $ s   A
Ac                     [        5       n U R                  S5      nU(       d   UR                  5       $ UR                  U5        M<  )Nr2  )r   r@  r1   	hexdigest)fp
md5_digestrJ  s      r5   r~  r~    sD    J
	"!! 	% 	 r8   c                 j    [        XU5       H#  n[        U[        5      (       d  M  [        U5      e   g)zP
Extract the contents of the zip file ``filename`` into the
directory ``root``.
N)rE  r;   r   r   )r-   rootr7  r   s       r5   r/   r/     s-    
 xw7g|,,G$$ 8r8   c              #     #    U(       a`  [         R                  R                  S[        R                  R                  U 5      S   -  5        [         R                  R                  5          [        R                  " U 5      nUR                  U5        U(       a  [        5         g g ! [        R                   a    [        U S5      v    g [         a  n[        X5      v    S nAg S nAff = f7f)Nr  r   zError with downloaded zip file)r  stdoutrA  r(   r)   r+   flushzipfileZipFile
BadZipFiler   r   
extractallr   )r-   r  r7  zfr  s        r5   rE  rE    s     

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

__X& MM$   8%EFF 8''s<   A(C,+B% $C,%"C)C,		C)C$C,$C))C,c                 &   / n[        [        R                  R                  U S5      5       GH"  u  p4n[        R                  " UR
                  5      nU SU S[        R                  R                  UR
                  5      S    3n[        S UR                  5        5       5      nUR                  SSU-  5        UR                  SSUR                  -  5        UR                  SS[        UR
                  5      -  5        UR                  S	U5        UR                  S
5      (       d  UR                  S
U5        UR                  U5        GM%     [        [        [        R                  R                  U S5      5      5      n	[        5       n
X)-    HU  nUR                  S5      U
;   a  [!        SUR                  S5      -  5      eU
R#                  UR                  S5      5        MW     [$        R&                  " S5      nUR                  [$        R&                  " S5      5        US   R)                  [+        US S95        UR                  [$        R&                  " S5      5        US   R)                  [+        U	S S95        [-        U5        U$ )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.
r]   r   r   c              3   8   #    U  H  oR                   v   M     g 7frD   )	file_size)r#  zf_infos     r5   r$  build_index.<locals>.<genexpr>  s     K]'--]r  r!   z%sr    r"   r   r   r   r   zDuplicate UID: %sr  r   c                 $    U R                  S5      $ Nr   rc   r|   s    r5   r[  build_index.<locals>.<lambda>	  s    7;;t;Lr8   r   c                 $    U R                  S5      $ r  r  ro   s    r5   r[  r  	  s    PTAUr8   )_find_packagesr(   r)   r,   r{  r-   r+   r(  infolistr  r|  r  rc   r   r   _find_collectionsr  addr   Elementr  r   _indent_xml)r  base_urlr]   pkg_xmlr  r   zipstatr   r!   r   uidsr`   top_elts                r5   build_indexr    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Nr8   c                    [        U 5      S:  a  U R                  =(       d    SR                  5       S-   U-   S-   U l        U  H  n[        X!S-   5        M     U SS  H4  nUR                  =(       d    SR                  5       S-   U-   S-   Ul        M6     U S   R                  =(       d    SR                  5       S-   U-   U S   l        gg)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   rO   r   r]  Nr   )r   rL  ra  r  tail)r?   r   rd   s      r5   r  r  	  s     3x!|HHN))+d2V;dBE}- "XE***113d:VCdJEJ B*113d:VCB r8   c                   ^ [         R                  R                  [         R                  R                  U5      S   5      S   mU R	                  S5      T:w  a*  [        SR                  U R	                  S5      T5      5      e[        U4S jUR                  5        5       5      (       a  [        ST< ST< S35      eg	)
zf
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   l   >#    U  H)  oT:g  =(       a    UR                  TS -   5      (       + v   M+     g7fr   Nr  r#  r   uids     r5   r$  !_check_package.<locals>.<genexpr>9	  s+     
VCK:c	 :::s   14Zipfile ..zip does not expand to a single subdirectory r   N)	r(   r)   r*   r+   rc   r  r   r(  namelist)r  zipfilenamer  r  s      @r5   _check_packager  ,	  s     ''

277==5a8
9!
<C{{4C4;;GKK<MsS
 	

 
V
VVV"%s,
 	
 Wr8   c                    [         R                  " SSSU /[         R                  [         R                  S9nUR                  5       u  p#UR                  S:w  d  U(       d  U(       dG  [        S[        R                  R                  U 5      S   < S[        R                  " U5      < 35      eUR                  5       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  r3  )
subprocessPopenPIPEcommunicate
returncoder  r(   r)   r+   r   r   )r-   r  r  r  s       r5   _svn_revisionr  A	  s    
 		$)	A
 }}V||qF&ww}}X&q)8==+@B
 	
 <<>!r8   c              #     #    [         R                  " U 5       Hl  u  pnU H`  nUR                  S5      (       d  M  [         R                  R	                  X5      n[
        R                  " U5      R                  5       v   Mb     Mn     g7f)z
Helper for ``build_index()``: Yield a list of ElementTree.Element
objects, each holding the xml for a single package collection.
.xmlN)r(   r  rD  r)   r,   r   r=   r  )r  dirname_subdirsr  r-   xmlfiles         r5   r  r  T	  se     
 %'GGDM 5H  (('',,w9!''088::  %2s   6B
AB
c           
   #     ^#    SSK Jn  / n[        R                  " U 5       GH  u  p4nSR	                  U" X5      5      nU GH  nUR                  S5      (       Ga  [        R                  R	                  X75      nUSS S-   n	 [        R                  " U	5      n
 [        R                  " U5      R                  5       n[        R                  R                  USS 5      S
   mUR                  S5      T:w  a#  [        SUR                  S5      < ST< S35      e[!        U4S jU
R#                  5        5       5      (       a  [        ST< ST< S35      eXU4v   GM   UR                  S5      (       d  GM9  [        R                  R%                  U5      S   n[        R                  R	                  X=S-   5      n[        R                  R'                  U5      (       a  GM  [(        R*                  " U SUS-    SU S3SS9  GM      UR-                  S5        GM     g! [         a  n[        SU	< S	U 35      UeSnAff = f! [         a  n[        SU< S	U 35      UeSnAff = f! [         a     GMZ  f = f7f)ab  
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   r  Nr\  r6  zError reading file z!
r   r   zpackage identifier mismatch (z vs r   c              3   n   >#    U  H*  nUT:g  =(       a    UR                  TS -   5      (       + v   M,     g7fr  r  r  s     r5   r$  !_find_packages.<locals>.<genexpr>	  s4       - S[Cs)C%CC -s   25r  r  z exists, but z' cannot be found! This could mean that z can not be downloaded.r3  )
stacklevelz.svn)nltk.corpus.reader.utilr  r(   r  r,   rD  r)   r  r  r   r  r   r=   r  r+   rc   r(  r  r*   r9  warningswarnr:  )r  r  r]   r  subdirsr  relpathr-   xmlfilenamer  r  r  r  resourcenamer  s                 @r5   r  r  `	  sT     3 H#%774=%((:d45H  (( ggll7=)#2.7Y 5BY)//<DDFG
 ggmmK$45a8;;t$+$$+KK$5s<    "   %58#? 
 7**""6**!ww//9!< ggll764IJww~~k2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   BJ H$$I	 B6J ;A&J &&J I.J $
I.IIJ 	
I+I&&I++J .
I=8J <I==J c                  >    [        [        5      R                  5         g rD   )r  _downloaderr  r:   r8   r5   download_shellr  	  s    K $$&r8   c                  >    [        [        5      R                  5         g rD   )r  r  r  r:   r8   r5   download_guir  	  s    +'')r8   c                  ,    [         R                  5         g rD   )r  r1   r:   r8   r5   r1   r1   	  s    r8   __main__)OptionParserz-dz--dirdirz!download package to directory DIRDIR)destr  metavarz-qz--quietrc  
store_truezwork quietly)r  actiondefaultr  z-fz--forcer  z"download even if already installedz-ez--exit-on-errorrd  zexit if an error occursz-uz--urlr   NLTK_DOWNLOAD_URLzdownload server index url)r  r  r  )r   )r  r   rc  r  rd  )r   rc  r  rd  ry  r^  )]rV   r_  r>  r(   shutilr  r  r   r  r  r  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   rZ   rk   rm   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r~  r/   rE  r  r  r  r  r  r  r  rb  r  r  r1   rR   optparser  parser
add_optionr  rc   
parse_argsr  r  r   
downloaderpkg_idr  rc  r  rd  rvr:   r8   r5   <module>r     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4  	 ----!//	 	 	
w KH  GHs   *K 
K'&K'