3
OÉ6b\  ã               @   sD   d Z ddlZddlZddlmZ ddlmZ dZG dd„ deƒZ	dS )z4Tools for representing MongoDB internal Timestamps.
é    N)Úinteger_types)Úutcl        c               @   s|   e Zd ZdZdZdd„ Zedd„ ƒZedd„ ƒZd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú	Timestampz3MongoDB internal timestamps used in the opLog.
    é   c             C   sª   t |tjƒr6|jƒ dk	r$||jƒ  }ttj|jƒ ƒƒ}t |tƒsHtdƒ‚t |tƒsZtdƒ‚d|  kolt	k n  szt
dƒ‚d|  koŒt	k n  sšt
dƒ‚|| _|| _dS )a¦  Create a new :class:`Timestamp`.

        This class is only for use with the MongoDB opLog. If you need
        to store a regular timestamp, please use a
        :class:`~datetime.datetime`.

        Raises :class:`TypeError` if `time` is not an instance of
        :class: `int` or :class:`~datetime.datetime`, or `inc` is not
        an instance of :class:`int`. Raises :class:`ValueError` if
        `time` or `inc` is not in [0, 2**32).

        :Parameters:
          - `time`: time in seconds since epoch UTC, or a naive UTC
            :class:`~datetime.datetime`, or an aware
            :class:`~datetime.datetime`
          - `inc`: the incrementing counter
        Nztime must be an instance of intzinc must be an instance of intr   z$time must be contained in [0, 2**32)z#inc must be contained in [0, 2**32))Ú
isinstanceÚdatetimeÚ	utcoffsetÚintÚcalendarÚtimegmÚ	timetupler   Ú	TypeErrorÚ
UPPERBOUNDÚ
ValueErrorÚ_Timestamp__timeÚ_Timestamp__inc)ÚselfÚtimeÚinc© r   úM/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/bson/timestamp.pyÚ__init__!   s    

zTimestamp.__init__c             C   s   | j S )z9Get the time portion of this :class:`Timestamp`.
        )r   )r   r   r   r   r   C   s    zTimestamp.timec             C   s   | j S )z8Get the inc portion of this :class:`Timestamp`.
        )r   )r   r   r   r   r   I   s    zTimestamp.incc             C   s*   t |tƒr"| j|jko | j|jkS tS d S )N)r   r   r   r   r   r   ÚNotImplemented)r   Úotherr   r   r   Ú__eq__O   s    
zTimestamp.__eq__c             C   s   t | jƒt | jƒA S )N)Úhashr   r   )r   r   r   r   Ú__hash__U   s    zTimestamp.__hash__c             C   s
   | |k S )Nr   )r   r   r   r   r   Ú__ne__X   s    zTimestamp.__ne__c             C   s&   t |tƒr"| j| jf|j|jfk S tS )N)r   r   r   r   r   )r   r   r   r   r   Ú__lt__[   s    
zTimestamp.__lt__c             C   s&   t |tƒr"| j| jf|j|jfkS tS )N)r   r   r   r   r   )r   r   r   r   r   Ú__le__`   s    
zTimestamp.__le__c             C   s&   t |tƒr"| j| jf|j|jfkS tS )N)r   r   r   r   r   )r   r   r   r   r   Ú__gt__e   s    
zTimestamp.__gt__c             C   s&   t |tƒr"| j| jf|j|jfkS tS )N)r   r   r   r   r   )r   r   r   r   r   Ú__ge__j   s    
zTimestamp.__ge__c             C   s   d| j | jf S )NzTimestamp(%s, %s))r   r   )r   r   r   r   Ú__repr__o   s    zTimestamp.__repr__c             C   s   t j j| jtƒS )z®Return a :class:`~datetime.datetime` instance corresponding
        to the time portion of this :class:`Timestamp`.

        The returned datetime's timezone is UTC.
        )r   Úfromtimestampr   r   )r   r   r   r   Úas_datetimer   s    zTimestamp.as_datetimeN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z_type_markerr   Úpropertyr   r   r   r   r   r   r   r    r!   r"   r$   r   r   r   r   r      s   "r   )
r(   r
   r   Zbson.py3compatr   Zbson.tz_utilr   r   Úobjectr   r   r   r   r   Ú<module>   s   