o
    7Di                     @   s   d Z ddlZddlZddlZddlmZmZ G dd dejZdedefdd	Z	dedefd
dZ
dejdefddZdadadaddee dee defddZdefddZdefddZdS )zUUID objects (universally unique identifiers) according to RFC 9562.

This module provides the functions uuid6(), uuid7(), and uuid8() for
generating version 6, 7, and 8 UUIDs as specified in RFC 9562.
    N)OptionalTuplec                       s   e Zd ZdZdZ						dejjddee	 dee
 dee
 deeeeeeeef  d	ee d
ee dejddf fddZedefddZedef fddZ  ZS )UUIDzEInstances of the UUID class represent UUIDs as specified in RFC 9562. N)is_safehexbytesbytes_lefieldsintversionr   returnc             	      s   |du s||||g ddkrt j|||||||dS d|  kr+dd> k s0td td|durXd|  krAd	ksFtd
 td
|dM }|dO }|dM }||d> O }t j||d dS )zCreate a UUID.N   )r   r   r	   r
   r   r   r   r         z*int is out of range (need a 128-bit value)      zillegal version numberl        l            l          L   )r   r   )countsuper__init__
ValueError)selfr   r   r	   r
   r   r   r   	__class__r   G/var/www/Datamplify/venv/lib/python3.10/site-packages/uuid6/__init__.pyr      s0   	zUUID.__init__c                 C   s    | j d? d@ d> | j d? d@ B S )N@     r   6      )r   r   r   r   r   subsec6   s    zUUID.subsecc                    sf   | j dkr| jd> | jd> B | jd@ B S | j dkr| jd? S | j dkr/| jd? d t| j S t jS )	Nr         r      P   r   @B )	r   time_lowtime_midtime_hi_versionr   _subsec_decoder!   r   timer    r   r   r   r+   :   s   



z	UUID.time)NNNNNN)__name__
__module____qualname____doc__	__slots__uuidSafeUUIDunknownr   strr   r   r   r   propertyr!   r+   __classcell__r   r   r   r   r      s@    		
$r   valuer   c                 C   s   |  d d  S )Nr&      r   r7   r   r   r   r*   I   s   r*   c                 C   s   | d d S )Nr8   r&   r   r9   r   r   r   _subsec_encodeM   s   r:   uuid1c                 C   sf   | j dkr	td| j}|dd |dd  |dd  d	 |dd  |dd
  }t|| jdS )z>Generate a UUID version 6 object from a UUID version 1 object.r   z%given UUID's version number must be 1      r   r#   r      6N)r   r   )r   r   r   r   r   )r;   hr   r   r   uuid1_to_uuid6Q   s
   
@rA   node	clock_seqc                 C   s   t  }|d d }tdur|tkrtd }|a|du r!td}| du r*td} |d? d@ }|d	@ }|d
> }||d> O }||d@ d> O }|| d@ O }t|ddS )a  UUID version 6 is a field-compatible version of UUIDv1, reordered for
    improved DB locality. It is expected that UUIDv6 will primarily be
    used in contexts where there are existing v1 UUIDs. Systems that do
    not involve legacy UUIDv1 SHOULD consider using UUIDv7 instead.

    If 'node' is not given, a random 48-bit number is chosen.

    If 'clock_seq' is given, it is used as the sequence number;
    otherwise a random 14-bit sequence number is chosen.d   l    @'HwNr      0   r#       r   r%   r   i?  r   r   r   )r+   time_ns_last_v6_timestampsecretsrandbitsr   )rB   rC   nanoseconds	timestamptime_high_and_time_midtime_low_and_versionuuid_intr   r   r   uuid6_   s    

rR   c                  C   sR   t  } | d }tdur|tkrtd }|a|d@ d> }|tdO }t|ddS )	a  UUID version 7 features a time-ordered value field derived from the
    widely implemented and well known Unix Epoch timestamp source, the
    number of milliseconds since midnight 1 Jan 1970 UTC, leap seconds
    excluded. As well as improved entropy characteristics over versions
    1 or 6.

    Implementations SHOULD utilize UUID version 7 over UUID version 1 and
    6 if possible.r&   Nr   rG   r%   r   r$   rH   )r+   rI   _last_v7_timestamprK   rL   r   )rM   timestamp_msrQ   r   r   r   uuid7   s   rU   c                  C   s   t  } tdur| tkrtd } | at| d\}}t|}|d? }|d@ }|d@ d> }||d> O }||d	> O }|td	O }t|dd
S )zUUID version 8 features a time-ordered value field derived from the
    widely implemented and well known Unix Epoch timestamp source, the
    number of nanoseconds since midnight 1 Jan 1970 UTC, leap seconds
    excluded.Nr   r&   r   r   rG   r%   r   r   rH   )r+   rI   _last_v8_timestampdivmodr:   rK   rL   r   )rM   rT   timestamp_nsr!   subsec_asubsec_brQ   r   r   r   uuid8   s   r[   )NN)r/   rK   r+   r1   typingr   r   r   r   r*   r:   rA   rJ   rS   rV   rR   rU   r[   r   r   r   r   <module>   s    <	 !