
    g                     :   d Z ddlZdZ	 ej                  Zy# e$ r ddlZddlZddlZddlZddl	Z		 ej                  dk(  ru ej                  dd      Z G d d	ej                        Zej                  Zej                   e_         e       Zej'                   ej(                  e             d
Zd Zn)ej                  j-                  d      sej                  j-                  d      rej                  j-                  d      r>	 ej.                  j0                  Zn<# e$ r ej.                  j5                  d      ZY nw xY wej6                  j0                  Z eedd      Zerej<                  e_        d Znbej>                  Zej@                  e_         e	jB                         Z"da#da$d Zn+	  ej                  ejJ                  jM                  d      d      jN                  Z'nB# e($ r:  ej                  ejJ                  jM                  d      d      jN                  Z'Y nw xY w G d dej                        Z)ej                  j-                  d      rdZ*nzej                  j-                  d      rdZ*n\ej                  j-                  d      rdZ*n>dej                  v rdZ*n-ej                  j-                  d      r ejV                  d      Z*d Z e        e       z
  dkD  r e,d       Y y# e($ rZ- e.d! e/e-      z         dZ-[-ww xY ww xY w)"a  
  monotonic
  ~~~~~~~~~

  This module provides a ``monotonic()`` function which returns the
  value (in fractional seconds) of a clock which never goes backwards.

  On Python 3.3 or newer, ``monotonic`` will be an alias of
  ``time.monotonic`` from the standard library. On older versions,
  it will fall back to an equivalent implementation:

  +-------------+----------------------------------------+
  | Linux, BSD  | ``clock_gettime(3)``                   |
  +-------------+----------------------------------------+
  | Windows     | ``GetTickCount`` or ``GetTickCount64`` |
  +-------------+----------------------------------------+
  | OS X        | ``mach_absolute_time``                 |
  +-------------+----------------------------------------+

  If no suitable implementation exists for the current platform,
  attempting to import this module (or to import from it) will
  cause a ``RuntimeError`` exception to be raised.


  Copyright 2014, 2015, 2016 Ori Livneh <ori@wikimedia.org>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

    N)	monotonicdarwinz/usr/lib/libc.dylibT)	use_errnoc                   H    e Zd ZdZdej
                  fdej
                  ffZy)mach_timebase_info_data_tz4System timebase info. Defined in <mach/mach_time.h>.numerdenomN)__name__
__module____qualname____doc__ctypesc_uint32_fields_     >/var/www/openai/venv/lib/python3.12/site-packages/monotonic.pyr   r   =   s$    J$foo6$foo68r   r       eAc                  l    t               t        j                  z  t        j                  z  } | t        z  S )$Monotonic clock, cannot go backward.)mach_absolute_timetimebaser   r	   nanoseconds_in_second)nanosecondss    r   r   r   I   s(    02X^^ChnnT"%:::r   win32cygwinzkernel32.dllGetTickCount64c                      t               dz  S )r        @@)r   r   r   r   r   r   i   s    )+f44r   c                      t         5  t               } | t        k  r	t        dz  a| at        dz  }|t        z  }|dz  cddd       S # 1 sw Y   yxY w)r          r   N)get_tick_count_lockGetTickCountget_tick_count_last_sampleget_tick_count_wraparounds)current_samplefinal_millisecondss     r   r   r   v   sS    
 -)5),FF6!;65C2-G2-M**.HH*1F: -,,s   5AAcrtc                   H    e Zd ZdZdej
                  fdej
                  ffZy)timespecz5Time specification, as described in clock_gettime(3).tv_sectv_nsecN)r
   r   r   r   r   c_longr   r   r   r   r,   r,      s$    K%v}}5&68r   r,   linuxr!   freebsd   sunos5bsd   aix
   c                      t               } t        t        t        j                  |             r3t        j
                         }t        |t        j                  |            | j                  | j                  dz  z   S )r   r   )r,   clock_gettimeCLOCK_MONOTONICr   pointer	get_errnoOSErrorosstrerrorr-   r.   )tserrnos     r   r   r      sX    Z &..2DE",,.E!%U);<<yy2::#555r   zmonotonic() is not monotonic!z,no suitable implementation for this system: )0r   time__all__r   AttributeErrorr   ctypes.utilr>   sys	threadingplatformCDLLlibc	Structurer   r   c_uint64restyper   mach_timebase_infobyrefr   
startswithcdllkernel32r=   LoadLibrarywindllgetattrr   c_ulonglongr$   r   Lockr#   r%   r&   utilfind_libraryr9   	Exceptionr,   r:   
c_longlong
ValueErroreRuntimeErrorreprr   r   r   <module>r`      s  &N  {UI yUsU<<8# 6;;4ED8F,<,< 8
 "&!8!8)/&02H##LFLL$:;$)!;
 \\$$W-1H1H1R||&&x0G%{{33H G%{{66~FHG "==11$X/?FN)/););&5  (44'-$&4inn&6#-.*-.*; J +FKK,D,DS,I6:!<<IM  J +FKK,D,DT,J6:!<<IM J86++ 8
 ||&&w/"#((3"#((2"##,,&"#((/"3&"3"3B"76 ;$q(<== )  UIDQRGSTTUqyUsq    LCK;DK; E?K;EA2K;57G-,K;-<H,)K;+H,,CK;;L LLL