
    i$                     b    d Z ddlZddlZddlmZ  ej        e          Z G d de          Z	dS )zc
This module contains utilities for generating timestamps for client-side
timestamp specification.
    N)Lockc                   >    e Zd ZdZdZ	 dZ	 dZ	 d	dZd Zd Z	d Z
dS )
MonotonicTimestampGeneratoras  
    An object that, when called, returns ``int(time.time() * 1e6)`` when
    possible, but, if the value returned by ``time.time`` doesn't increase,
    drifts into the future and logs warnings.
    Exposed configuration attributes can be configured with arguments to
    ``__init__`` or by changing attributes on an initialized object.

    .. versionadded:: 3.8.0
    T   c                     t                      | _        | j        5  d| _        d| _        d d d            n# 1 swxY w Y   || _        || _        || _        d S )Nr   )r   locklast
_last_warnwarn_on_driftwarning_thresholdwarning_interval)selfr   r   r   s       f/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/cassandra/timestamps.py__init__z$MonotonicTimestampGenerator.__init__:   s    FF	Y 	  	 DIDO	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  +!2 0s   6::c                 n    ||k    r	|| _         |S |                     |           |dz   | _         | j         S )a4  
        Returns the timestamp that should be used if ``now`` is the current
        time and ``last`` is the last timestamp returned by this object.
        Intended for internal and testing use only; to generate timestamps,
        call an instantiated ``MonotonicTimestampGenerator`` object.

        :param int now: an integer to be used as the current time, typically
            representing the current time in microseconds since the UNIX epoch
        :param int last: an integer representing the last timestamp returned by
            this object
        )nowr   )r	   _maybe_warn)r   r   r	   s      r   _next_timestampz+MonotonicTimestampGenerator._next_timestampC   sC     ::DIJ%%%qDI9    c                     | j         5  |                     t          t          j                    dz            | j                  cddd           S # 1 swxY w Y   dS )zw
        Makes ``MonotonicTimestampGenerator`` objects callable; defers
        internally to _next_timestamp.
            .A)r   r	   N)r   r   inttimer	   )r   s    r   __call__z$MonotonicTimestampGenerator.__call__W   s    
 Y 	8 	8''C	c0A,B,B-1Y ( 8 8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   =AAAc                     | j         |z
  }|| j        z
  }| j        o|| j        dz  k    o|| j        dz  k    }|r>t
                              d                    ||| j                              || _        d S d S )Nr   zClock skew detected: current tick ({now}) was {diff} microseconds behind the last generated timestamp ({last}), returned timestamps will be artificially incremented to guarantee monotonicity.)r   diffr	   )r	   r
   r   r   r   logwarningformat)r   r   r   since_last_warnwarns        r   r   z'MonotonicTimestampGenerator._maybe_warn`   s    y3/" A/#55A D$9C$?? 	  	"KK9 :@$TY :@ :8 :8	9 9 9 "DOOO	" 	"r   N)Tr   r   )__name__
__module____qualname____doc__r   r   r   r   r   r   r    r   r   r   r      s          M
  
1 1 1 1  (8 8 8" " " " "r   r   )
r%   loggingr   	threadingr   	getLoggerr"   r   objectr   r&   r   r   <module>r+      s   " 
        g!!S" S" S" S" S"& S" S" S" S" S"r   