ó
ù`]c           @   s¿   d  Z  d d l Z d d l m Z m Z d d l m Z m Z m Z d d l	 m
 Z
 d d l m Z d e f d „  ƒ  YZ e ƒ  Z e
 e ƒ d	 e f d
 „  ƒ  Yƒ Z d e f d „  ƒ  YZ d S(   sY   
This module provides an interface for TweetHandlers, and support for timezone
handling.
iÿÿÿÿN(   t   ABCMetat   abstractmethod(   t   tzinfot	   timedeltat   datetime(   t   add_metaclass(   t   UTCt   LocalTimezoneOffsetWithUTCc           B   sO   e  Z d  Z e d e j ƒ Z e j r> e d e j ƒ Z	 n e Z	 d „  Z
 RS(   s»  
    This is not intended to be a general purpose class for dealing with the
    local timezone. In particular:

    * it assumes that the date passed has been created using
      `datetime(..., tzinfo=Local)`, where `Local` is an instance of
      the object `LocalTimezoneOffsetWithUTC`;
    * for such an object, it returns the offset with UTC, used for date comparisons.

    Reference: https://docs.python.org/3/library/datetime.html
    t   secondsc         C   s   |  j  S(   s2   
        Access the relevant time offset.
        (   t	   DSTOFFSET(   t   selft   dt(    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt	   utcoffset,   s    (   t   __name__t
   __module__t   __doc__R   t   _timet   timezonet	   STDOFFSETt   daylightt   altzoneR	   R   (    (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyR      s   	t   BasicTweetHandlerc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s   
    Minimal implementation of `TweetHandler`.

    Counts the number of Tweets and decides when the client should stop
    fetching them.
    i   c         C   s(   | |  _  d |  _ t |  _ d  |  _ d  S(   Ni    (   t   limitt   countert   Falset   do_stopt   Nonet   max_id(   R
   R   (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt   __init__?   s    			c         C   s   |  j  |  j k  o |  j S(   sL   
        Returns `False` if the client should stop fetching Tweets.
        (   R   R   R   (   R
   (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt   do_continueN   s    (   R   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyR   6   s   t   TweetHandlerIc           B   sJ   e  Z d  Z d d d d „ Z e d „  ƒ Z e d „  ƒ Z e d „ Z	 RS(   su   
    Interface class whose subclasses should implement a handle method that
    Twitter clients can delegate to.
    i   c         C   sk   t  j |  | ƒ d |  _ d |  _ | r@ t d t | Œ |  _ n  | r^ t d t | Œ |  _ n  t |  _ d S(   s  
        :param int limit: The number of data items to process in the current        round of processing.

        :param tuple upper_date_limit: The date at which to stop collecting        new data. This should be entered as a tuple which can serve as the        argument to `datetime.datetime`.        E.g. `date_limit=(2015, 4, 1, 12, 40)` for 12:30 pm on April 1 2015.

        :param tuple lower_date_limit: The date at which to stop collecting        new data. See `upper_data_limit` for formatting.
        R   N(	   R   R   R   t   upper_date_limitt   lower_date_limitR   t   LOCALt   Truet
   startingup(   R
   R   R   R    (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyR   [   s    		c         C   s   d S(   sJ   
        Deal appropriately with data returned by the Twitter API
        N(    (   R
   t   data(    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt   handles   t    c         C   s   d S(   s?   
        Actions when the tweet limit has been reached
        N(    (   R
   (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt	   on_finishy   R&   c         C   sÄ   |  j  s |  j rÀ d } t j | d | ƒ j d t ƒ } |  j  rR | |  j  k sj |  j rÀ | |  j k  rÀ |  j  r… d } |  j  } n d } |  j } | r± d j | | | ƒ GHn  t |  _ qÀ n  d S(   s'   
        Validate date limits.
        s   %a %b %d %H:%M:%S +0000 %Yt
   created_atR   t   earliert   laters4   Date limit {0} is {1} than date of current tweet {2}N(	   R   R    R   t   strptimet   replaceR   t   formatR"   R   (   R
   R$   t   verboset   date_fmtt
   tweet_datet   messaget
   date_limit(    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt   check_date_limit   s    			N(
   R   R   R   R   R   R   R%   R'   R   R3   (    (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyR   U   s
   (   R   t   timeR   t   abcR    R   R   R   R   t   sixR   t   nltk.compatR   R   R!   t   objectR   R   (    (    (    s/   lib/python2.7/site-packages/nltk/twitter/api.pyt   <module>   s   	