5555import  os 
5656import  sys 
5757import  time 
58- 
5958from  enum  import  Enum , _simple_enum 
6059
6160
@@ -439,6 +438,7 @@ def _get_command_stdout(command, *args):
439438# 
440439# See https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local_(U/L_bit) 
441440
441+ 
442442def  _is_universal (mac ):
443443    return  not  (mac  &  (1  <<  41 ))
444444
@@ -554,6 +554,7 @@ def _ifconfig_getnode():
554554            return  mac 
555555    return  None 
556556
557+ 
557558def  _ip_getnode ():
558559    """Get the hardware address on Unix by running ip.""" 
559560    # This works on Linux with iproute2. 
@@ -562,6 +563,7 @@ def _ip_getnode():
562563        return  mac 
563564    return  None 
564565
566+ 
565567def  _arp_getnode ():
566568    """Get the hardware address on Unix by running arp.""" 
567569    import  os , socket 
@@ -590,11 +592,13 @@ def _arp_getnode():
590592        return  mac 
591593    return  None 
592594
595+ 
593596def  _lanscan_getnode ():
594597    """Get the hardware address on Unix by running lanscan.""" 
595598    # This might work on HP-UX. 
596599    return  _find_mac_near_keyword ('lanscan' , '-ai' , [b'lan0' ], lambda  i : 0 )
597600
601+ 
598602def  _netstat_getnode ():
599603    """Get the hardware address on Unix by running netstat.""" 
600604    # This works on AIX and might work on Tru64 UNIX. 
@@ -618,12 +622,14 @@ def _unix_getnode():
618622        uuid_time , _  =  _generate_time_safe ()
619623        return  UUID (bytes = uuid_time ).node 
620624
625+ 
621626def  _windll_getnode ():
622627    """Get the hardware address on Windows using the _uuid extension module.""" 
623628    if  _UuidCreate :
624629        uuid_bytes  =  _UuidCreate ()
625630        return  UUID (bytes_le = uuid_bytes ).node 
626631
632+ 
627633def  _random_getnode ():
628634    """Get a random node ID.""" 
629635    # RFC 4122, $4.1.6 says "For systems with no IEEE address, a randomly or 
@@ -667,6 +673,7 @@ def _random_getnode():
667673
668674_node  =  None 
669675
676+ 
670677def  getnode ():
671678    """Get the hardware address as a 48-bit positive integer. 
672679
@@ -691,6 +698,7 @@ def getnode():
691698
692699_last_timestamp  =  None 
693700
701+ 
694702def  uuid1 (node = None , clock_seq = None ):
695703    """Generate a UUID from a host ID, sequence number, and the current time. 
696704    If 'node' is not given, getnode() is used to obtain the hardware 
@@ -739,13 +747,15 @@ def uuid3(namespace, name):
739747    int_uuid_3  |=  _RFC_4122_VERSION_3_FLAGS 
740748    return  UUID ._from_int (int_uuid_3 )
741749
750+ 
742751def  uuid4 ():
743752    """Generate a random UUID.""" 
744753    int_uuid_4  =  int .from_bytes (os .urandom (16 ))
745754    int_uuid_4  &=  _RFC_4122_CLEARFLAGS_MASK 
746755    int_uuid_4  |=  _RFC_4122_VERSION_4_FLAGS 
747756    return  UUID ._from_int (int_uuid_4 )
748757
758+ 
749759def  uuid5 (namespace , name ):
750760    """Generate a UUID from the SHA-1 hash of a namespace UUID and a name.""" 
751761    if  isinstance (name , str ):
@@ -757,8 +767,6 @@ def uuid5(namespace, name):
757767    int_uuid_5  |=  _RFC_4122_VERSION_5_FLAGS 
758768    return  UUID ._from_int (int_uuid_5 )
759769
760- _last_timestamp_v7  =  None 
761- _last_counter_v7  =  0   # 42-bit counter 
762770
763771def  _uuid7_get_counter_and_tail ():
764772    rand  =  int .from_bytes (os .urandom (10 ))
@@ -768,6 +776,11 @@ def _uuid7_get_counter_and_tail():
768776    tail  =  rand  &  0xffff_ffff 
769777    return  counter , tail 
770778
779+ 
780+ _last_timestamp_v7  =  None 
781+ _last_counter_v7  =  0   # 42-bit counter 
782+ 
783+ 
771784def  uuid7 ():
772785    """Generate a UUID from a Unix timestamp in milliseconds and random bits. 
773786
@@ -828,6 +841,7 @@ def uuid7():
828841    _last_counter_v7  =  counter 
829842    return  res 
830843
844+ 
831845def  uuid8 (a = None , b = None , c = None ):
832846    """Generate a UUID from three custom blocks. 
833847
@@ -853,6 +867,7 @@ def uuid8(a=None, b=None, c=None):
853867    int_uuid_8  |=  _RFC_4122_VERSION_8_FLAGS 
854868    return  UUID ._from_int (int_uuid_8 )
855869
870+ 
856871def  main ():
857872    """Run the uuid command line interface.""" 
858873    uuid_funcs  =  {
0 commit comments