
    Wh                     t    d Z ddlZddlZddlZddlZddlZ G d d          Zd ZddZd Z	dd	Z
d
 Zd ZdS )z4Utilities for use by the uploader command line tool.    Nc                       e Zd ZdZd Zd ZdS )RateLimiterz>Helper class for rate-limiting using a fixed minimum interval.c                 :    t           | _        || _        d| _        dS )zMConstructs a RateLimiter that permits a tick() every
        `interval_secs`.r   N)time_time_interval_secs_last_called_secs)selfinterval_secss     _/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/tensorboard/uploader/util.py__init__zRateLimiter.__init__   s!     
+!"    c                     | j         | j        z   | j                                        z
  }|dk    r| j                            |           | j                                        | _         dS )zLBlocks until it has been at least `interval_secs` since last
        tick().r   N)r	   r   r   r   sleep)r
   	wait_secss     r   tickzRateLimiter.tick#   sc     "T%884:??;L;LL 	 q==JY'''!%!2!2r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s8        HH# # #3 3 3 3 3r   r   c                  0   t           j        dk    r2t          j        d          } | r| S t          j        d          } | r| S dS t          j        d          }|r|S t           j                            t           j                            d          d          S )zDReturns a platform-specific root directory for user config settings.ntLOCALAPPDATAAPPDATANXDG_CONFIG_HOME~z.config)osnamegetenvpathjoin
expanduser)appdataxdg_config_homes     r   get_user_config_directoryr&   .   s     
w$)N++ 	N)I&& 	Nti 122O 7<<**3//;;;r   Fc                 >   |rt           j        dk    rt          d          	 t           j                            |           } t           j                            |           }	 t          j        |           n-# t          $ r }|j        t          j	        k    r Y d}~nd}~ww xY w|rt          j
        |d           t          | d                                           |rt          j
        | d           dS dS # t          $ r}t          d| d|          d}~ww xY w)	a  Creates a file and its containing directories, if they don't already
    exist.

    If `private` is True, the file will be made private (readable only by the
    current user) and so will the leaf directory. Pre-existing contents of the
    file are not modified.

    Passing `private=True` is not supported on Windows because it doesn't support
    the relevant parts of `os.chmod()`.

    Args:
      path: str, The path of the file to create.
      private: boolean, Whether to make the file and leaf directory readable only
        by the current user.

    Raises:
      RuntimeError: If called on Windows with `private` set to True.
    r   z.Creating private file not supported on WindowsNi  ai  zFailed to create file z: )r   r   RuntimeErrorr!   realpathdirnamemakedirsOSErrorerrnoEEXISTchmodopencloseEnvironmentError)r!   privateleaf_dires       r   make_file_with_directoriesr7   C   sL   &  M27d??KLLLGw%%7??4((	K!!!! 	 	 	w%,&& '&&&&	  	&HXu%%%T3 	"HT5!!!!!	" 	" G G GlTTT11EFFFGsB   >C8 "A7 6C8 7
B!BC8 B!!AC8 8
DDDc                 |    t          |          | _        t          t          |dz  dz                      | _        dS )aE  Sets a `Timestamp` proto message to a floating point UNIX time.

    This is like `pb.FromNanoseconds(int(seconds_since_epoch * 1e9))` but
    without introducing floating-point error.

    Args:
      pb: A `google.protobuf.Timestamp` message to mutate.
      seconds_since_epoch: A `float`, as returned by `time.time`.
       i ʚ;N)intsecondsroundnanos)pbseconds_since_epochs     r   set_timestampr@   i   s:     ())BJ5-1U:;;<<BHHHr   c                    t           j                             | j        dz             }|t          j        d          z
  }|t           j                                         }|                    d          |z
  }d }d}|t          j        d          k     rd}n|t          j        d	
          k     r- |t          |                                          dd          }n|t          j        d	          k     r0 |t          |                                          dz  dd          }nH|t          j        d	          k     r/ |t          |                                          dz  dd          }|d|z  nd}t          |          |z   S )a  Converts a `timestamp_pb2.Timestamp` to human-readable string.

    This always includes the absolute date and time, and for recent dates
    may include a relative time like "(just now)" or "(2 hours ago)". It
    should thus be used for ephemeral values. Use `format_time_absolute`
    if the output will be persisted.

    Args:
      timestamp_pb: A `google.protobuf.timestamp_pb2.Timestamp` value to
        convert to string. The input will not be modified.
      now: A `datetime.datetime` object representing the current time,
        used for determining relative times like "just now". Optional;
        defaults to `datetime.datetime.now()`.

    Returns:
      A string suitable for human consumption.
    iQ )r;   Nr   )microsecondc                      d| | dk    r|n|fz  S Nz	%d %s agor9   r   nsingularplurals      r   ago_textzformat_time.<locals>.ago_text   s    aQ!VV@@@r      zjust nowr9   )minutessecondr;   )hours<   minuterK   )daysi  hourrM   z (%s) )	datetimefromtimestampr;   	timedeltanowreplacer:   total_secondsstr)timestamp_pbrV   dtagorI   relativerelative_parts          r   format_timer_   w   s   , 
		(	()=)E	F	FB	h ///	/B
{##%%
++!+
$
$r
)CA A A H
X*****	x!!,,,	,	,8C 1 1 3 344h	JJ	x!***	*	*8C 1 1 3 344:HiPP	x!q)))	)	)8C 1 1 3 344<fgNN*2*>Gh&&BMr77]""r   c                     t           j                             | j        t           j        j                  }|                    d          S )a;  Converts a `timestamp_pb2.Timestamp` to UTC time string.

    This will always be of the form "2001-02-03T04:05:06Z".

    Args:
      timestamp_pb: A `google.protobuf.timestamp_pb2.Timestamp` value to
        convert to string. The input will not be modified.

    Returns:
      An RFC 3339 date-time string.
    )tzz%Y-%m-%dT%H:%M:%SZ)rS   rT   r;   timezoneutcstrftime)rZ   r[   s     r   format_time_absolutere      sD     
		(	(!2!6 
) 
 
B ;;+,,,r   c                      d| | dk    r|n|fz  S rD   r   rE   s      r   	_ngettextrg      s    !aXXV<<<r   )F)N)r   rS   r.   r   os.pathr   r   r&   r7   r@   r_   re   rg   r   r   r   <module>ri      s    ; :   				  3 3 3 3 3 3 3 3*< < <*#G #G #G #GL= = =+# +# +# +#\- - -$= = = = =r   