σ
ω`]c           @@ sά  d  d l  m Z m Z d  d l Z d  d l Z d  d l m Z m Z d  d l Z d  d l	 Z	 d  d l
 m Z m Z e j d  d k Z e rή d   Z d  d l Z e j Z e j Z d  d l m Z e j Z d  d l m Z nd	   Z y d  d
 l m Z Wn! e k
 rd  d
 l m Z n Xe Z d  d l m Z m Z e d   Z e d d  Z d e f d     YZ e   Z d  d l Z d  d l  Z  d  d l Z d d( d     YZ! d  d l" Z# d  d l Z$ d  d l m% Z% d e& f d     YZ d) d* d+ d, g Z' g  e' D] Z( e j) j* e(   ^ qZ+ d   Z, d   Z- d   Z. y d  d  l/ m/ Z0 Wn? e k
 ry d  d  l1 m/ Z0 Wqe k
 re. Z0 qXn Xd!   Z2 d"   Z3 d#   Z4 d$   Z5 d%   Z6 d& e j7 f d'     YZ7 d S(-   i    (   t   absolute_importt   print_functionN(   t   update_wrappert   wraps(   t   string_typest	   text_typei   c         C@ s
   |  j  j S(   N(   t   __self__t	   __class__(   t   meth(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   get_im_class   s    (   t   timezone(   t   TemporaryDirectoryc         C@ s   |  j  S(   N(   t   im_class(   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR	   (   s    (   t   StringIO(   t   tzinfot	   timedeltat   hoursi   t   UTCc           B@ s)   e  Z d  Z d   Z d   Z d   Z RS(   R   c         C@ s   t  S(   N(   t   ZERO(   t   selft   dt(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt	   utcoffset:   s    c         C@ s   d S(   NR   (    (   R   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   tzname=   s    c         C@ s   t  S(   N(   R   (   R   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   dst@   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   7   s   		t   UnicodeWriterc           B@ s5   e  Z d  Z e j d d d  Z d   Z d   Z RS(   s¬   
        A CSV writer which will write rows to CSV file "f",
        which is encoded in the given encoding.
        see https://docs.python.org/2/library/csv.html
        s   utf-8t   replacec         K@ s[   t  j   |  _ t j |  j d | | |  _ | |  _ t j |  } | d |  |  _ d  S(   Nt   dialectt   errors(	   t	   cStringIOR   t   queuet   csvt   writert   streamt   codecst   getincrementalencodert   encoder(   R   t   fR   t   encodingR   t   kwdst   encoder_cls(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   __init__P   s
    	c         C@ s$   t  | t  r | j d  S| Sd  S(   Ns   utf-8(   t
   isinstanceR   t   encode(   R   t   data(    (    s*   lib/python2.7/site-packages/nltk/compat.pyR-   Z   s    c         C@ s   |  j  j g  | D] } |  j |  ^ q  |  j j   } | j d  } |  j j | d  } |  j j |  |  j j	 d  d  S(   Ns   utf-8R   i    (
   R"   t   writerowR-   R    t   getvaluet   decodeR&   R#   t   writet   truncate(   R   t   rowt   sR.   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR/   `   s    ,(   R   R   R   R!   t   excelR+   R-   R/   (    (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   I   s   		(   t   mkdtempR   c           B@ sΕ   e  Z d  Z d d d
 d  Z d   Z d   Z e d  Z d   Z	 d   Z
 e e j  Z e e j j  Z e e j j  Z e e j j  Z e e j  Z e e j  Z e j Z d	   Z RS(   sΆ  Create and return a temporary directory.  This has the same
        behavior as mkdtemp but can be used as a context manager.  For
        example:

            with TemporaryDirectory() as tmpdir:
                ...

        Upon exiting the context, the directory and everything contained
        in it are removed.

        http://stackoverflow.com/questions/19296146/tempfile-temporarydirectory-context-manager-in-python-2-7
        t    t   tmpc         C@ s+   t  |  _ d  |  _ t | | |  |  _ d  S(   N(   t   Falset   _closedt   Nonet   nameR7   (   R   t   suffixt   prefixt   dir(    (    s*   lib/python2.7/site-packages/nltk/compat.pyR+   ~   s    		c         C@ s   d j  |  j j |  j  S(   Ns	   <{} {!r}>(   t   formatR   R   R=   (   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   __repr__   s    c         C@ s   |  j  S(   N(   R=   (   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt	   __enter__   s    c         C@ s­   |  j  r© |  j r© y |  j |  j   WnQ t t f k
 rz } d t |  k rW   n  t d j | |   d t j	 d  SXt
 |  _ | r© |  j d j |   t  q© n  d  S(   NR<   s"   ERROR: {!r} while cleaning up {!r}t   files   Implicitly cleaning up {!r}(   R=   R;   t   _rmtreet	   TypeErrort   AttributeErrort   strt   printRA   t   syst   stderrt   Truet   _warnt   Warning(   R   RM   t   ex(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   cleanup   s    
	c         C@ s   |  j    d  S(   N(   RP   (   R   t   exct   valuet   tb(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   __exit__   s    c         C@ s   |  j  d t  d  S(   NRM   (   RP   RL   (   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   __del__   s    c         C@ sΝ   x‘ |  j  |  D] } |  j | |  } y# |  j |  oG |  j |  } Wn t k
 rd t } n X| r{ |  j |  q y |  j |  Wq t k
 r q Xq Wy |  j |  Wn t k
 rΘ n Xd  S(   N(	   t   _listdirt
   _path_joint   _isdirt   _islinkt   OSErrorR:   RE   t   _removet   _rmdir(   R   t   pathR=   t   fullnamet   isdir(    (    s*   lib/python2.7/site-packages/nltk/compat.pyRE   ―   s     #
N(   R   R   R   R<   R+   RB   RC   R:   RP   RT   RU   t   staticmethodt   _ost   listdirRV   R]   t   joinRW   R_   RX   t   islinkRY   t   removeR[   t   rmdirR\   t	   _warningst   warnRM   RE   (    (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   p   s   					t   chunkerst   maxent_ne_chunkert   helpt   tagsetst   taggerst   maxent_treebank_pos_taggert
   tokenizerst   punktc         C@ s   t  r x t D] } | t |   k r d t |   k r |  j |  t |  } |  | | d !d k rt | d 7} n  |  |  d |  | }  Pq q Wn  |  S(   Ns   /PY3i   s   .zip(   t   PY3t   _PY3_DATA_UPDATESRH   t   indext   len(   R]   t   itemt   pos(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   add_py3_dataΣ   s    $c         @ s     f d   } t     |  S(   Nc          @ s/   |  d t  |  d  f |  d }    |  |   S(   Ni    i   i   (   Rw   (   t   argst   kwargs(   t	   init_func(    s*   lib/python2.7/site-packages/nltk/compat.pyt
   _decoratorβ   s    "(   R   (   Rz   R{   (    (   Rz   s*   lib/python2.7/site-packages/nltk/compat.pyt   py3_dataα   s    c         @ sS   t  |  t  r! |  j d  }  n  t j   d j   f d   t j d |   D  S(   Nt   asciiR8   c         3@ s'   |  ] }   |  d  k r | Vq d S(   t   MnN(    (   t   .0t   c(   t   category(    s*   lib/python2.7/site-packages/nltk/compat.pys	   <genexpr>ρ   s    t   NFKD(   R,   t   bytesR1   t   unicodedataR   Rc   t	   normalize(   t   text(    (   R   s*   lib/python2.7/site-packages/nltk/compat.pyt   remove_accentsκ   s
    	(   t	   unidecodec         C@ s   t  |  t  s t d   n  t |  j  s] |  j |  _ t s] t t |  j   |  _ q] n  t |  j	  s |  j	 |  _
 t s t |  j
  |  _	 q n  |  S(   s  
    This decorator defines __unicode__ method and fixes
    __repr__ and __str__ methods under Python 2.

    To support Python 2 and 3 with a single code base,
    define __str__ and __repr__ methods returning unicode
    text and apply this decorator to the class.

    Original __repr__ and __str__ would be available
    as unicode_repr and __unicode__ (under both Python 2
    and Python 3).
    s1   This decorator doesn't work for old-style classes(   t
   issubclasst   objectt
   ValueErrort
   _was_fixedt   __str__t   __unicode__Rq   t   _7bitt   _transliteratedRB   t   unicode_repr(   t   klass(    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   python_2_unicode_compatible  s    	c         C@ sP   t  r t |   St |  d  r) |  j   St |  t  rF t |   d St |   S(   s0  
    For classes that was fixed with @python_2_unicode_compatible
    ``unicode_repr`` returns ``obj.unicode_repr()``; for unicode strings
    the result is returned without "u" letter (to make output the
    same under Python 2.x and Python 3.x); for other variables
    it is the same as ``repr``.
    R   i   (   Rq   t   reprt   hasattrR   R,   R   (   t   obj(    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   *  s    

c         @ sP     f d   } t  |   d d g  t   d  rC   j | _ n  t | _ | S(   Nc         @ s   t    |    S(   N(   t   transliterate(   R   (   t   method(    s*   lib/python2.7/site-packages/nltk/compat.pyt   wrapper@  s    R   R   t   _nltk_compat_7bit(   R   R   R   RL   t   _nltk_compat_transliterated(   R   R   (    (   R   s*   lib/python2.7/site-packages/nltk/compat.pyR   ?  s    	c         @ sP     f d   } t  |   d d g  t   d  rC   j | _ n  t | _ | S(   Nc         @ s     |   j  d d  S(   NR}   t   backslashreplace(   R-   (   R   (   R   (    s*   lib/python2.7/site-packages/nltk/compat.pyR   L  s    R   R   R   (   R   R   R   RL   R   (   R   R   (    (   R   s*   lib/python2.7/site-packages/nltk/compat.pyR   K  s    	c         C@ s"   t  |  d t  p! t  |  d t  S(   NR   R   (   t   getattrR:   (   R   (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   X  s    t   Fractionc           B@ s    e  Z d  Z d d e d  Z RS(   s‘  
    This is a simplified backwards compatible version of fractions.Fraction
    from Python >=3.5. It adds the `_normalize` parameter such that it does
    not normalize the denominator to the Greatest Common Divisor (gcd) when
    the numerator is 0.

    This is most probably only used by the nltk.translate.bleu_score.py where
    numerator and denominator of the different ngram precisions are mutable.
    But the idea of "mutable" fraction might not be applicable to other usages,
    See http://stackoverflow.com/questions/34561265

    This objects should be deprecated once NLTK stops supporting Python < 3.5
    See https://github.com/nltk/nltk/issues/1330
    i    c         C@ sV   t  t |   j |  | |  }  | rR t |  t k rR | rR | |  _ | |  _ n  |  S(   N(   t   superR   t   __new__t   typet   intt
   _numeratort   _denominator(   t   clst	   numeratort   denominatort
   _normalize(    (    s*   lib/python2.7/site-packages/nltk/compat.pyR    n  s
    	N(   R   R   R   R<   RL   R    (    (    (    s*   lib/python2.7/site-packages/nltk/compat.pyR   ^  s   (    (   Ri   Rj   (   Rk   Rl   (   Rm   Rn   (   Ro   Rp   (8   t
   __future__R    R   t   osRJ   t	   functoolsR   R   t	   fractionsR   t   sixR   R   t   version_infoRq   R	   t   ioR   t   BytesIOt   datetimeR
   t   utcR   t   tempfileR   R   t   ImportErrorR   R   R   t   HOURR!   R$   R   t   warningsRg   Ra   R7   R   t   DATA_UPDATESt	   path_listR]   Rc   Rr   Rw   R|   R   R   R   t   text_unidecodeR   R   R   R   R   R   (    (    (    s*   lib/python2.7/site-packages/nltk/compat.pyt   <module>	   sn   						#Z	%					%				