Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
§

Õg²*ã
óš—dZdZddlZddlZddlZddlZddlmZmZm	Z	ddl
Z
ejZddegd¢gd¢fdeedee
degefd	e	e
je
eeffd
„Zddeed	e
fd„Z	ddeegefd	e
fd
„Z	dde	e
e
jefd	eefd„Z	dde	e
e
jefd	eejfd„ZdS)zÅ
Implementation of UUID v7 per the October 2021 draft update
to RFC4122 from 2005:
https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format

Stephen Simmons, v0.1.0, 2021-12-27
)Úuuid7Úuuid7strÚtime_nsÚcheck_timing_precisionÚuuid_to_datetimeéN)ÚCallableÚOptionalÚUnion)rrrrÚnsÚas_typeÚ	time_funcÚreturnc
ó—|€
|¦«}|}n|}t|¦«}|dkrdx}x}x}}	d}
n±d}t||¦«\}}t|dz|¦«\}}
t|
dz|¦«\}}|dz}||dkr5||dkr)||d	kr|d
dkr|d
xxdz
cc<n|||df|dd…<d|d
z}	tjd
¦«}
|dkr&|d›d|d›d|d›d|	d›d|
 ¦«›	St |
d¦«}|dz|dzz|dzz|	dzz|z}|dkr|S|dkr|d›S|dkr| dd¦«Stj|¬¦«S)u-

    UUID v7, following the proposed extension to RFC4122 described in
    https://www.ietf.org/id/draft-peabody-dispatch-new-uuid-format-02.html.
    All representations (string, byte array, int) sort chronologically,
    with a potential time resolution of 50ns (if the system clock
    supports this).

    Parameters
    ----------

    ns      - Optional integer with the whole number of nanoseconds
                since Unix epoch, to set the "as of" timestamp.
                As a special case, uuid7(ns=0) returns the zero UUID.

    as_type - Optional string to return the UUID in a different format.
                A uuid.UUID (version 7, variant 0x10) is returned unless
                this is one of 'str', 'int', 'hex' or 'bytes'.

    time_func - Set the time function, which must return integer
                nanoseconds since the Unix epoch, midnight on 1-Jan-1970.
                Defaults to time.time_ns(). This is exposed because
                time.time_ns() may have a low resolution on Windows.

    _last and _last_as_of - Used internally to trigger incrementing a
                sequence counter when consecutive calls have the same time
                values. The values [t1, t2, t3, seq] are described below.

    Returns
    -------

    A UUID object, or if as_type is specified, a string, int or
    bytes of length 16.

    Implementation notes
    --------------------

    The 128 bits in the UUID are allocated as follows:
    - 36 bits of whole seconds
    - 24 bits of fractional seconds, giving approx 50ns resolution
    - 14 bits of sequential counter, if called repeatedly in same time tick
    - 48 bits of randomness
    plus, at locations defined by RFC4122, 4 bits for the
    uuid version (0b111) and 2 bits for the uuid variant (0b10).

             0                   1                   2                   3
             0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    t1      |                 unixts (secs since epoch)                     |
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    t2/t3   |unixts |  frac secs (12 bits)  |  ver  |  frac secs (12 bits)  |
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    t4/rand |var|       seq (14 bits)       |          rand (16 bits)       |
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    rand    |                          rand (32 bits)                       |
            +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

    Indicative timings:
    - uuid.uuid4()            2.4us
    - uuid7()                 3.7us
    - uuid7(as_type='int')    1.6us
    - uuid7(as_type='str')    2.5us

    Examples
    --------

    >>> uuid7()
    UUID('061cb26a-54b8-7a52-8000-2124e7041024')

    >>> uuid7(0)
    UUID('00000000-0000-0000-0000-00000000000')

    >>> for fmt in ('bytes', 'hex', 'int', 'str', 'uuid', None):
    ...     print(fmt, repr(uuid7(as_type=fmt)))
    bytes b'¸þ|9€	jt…³»'
    hex '061cb8fe0f0b7c3980011863b956b758'
    int 8124504378724980906989670469352026642
    str '061cb8fe-0f0b-7c39-8003-d44a7ee0bdf6'
    uuid UUID('061cb8fe-0f0b-7c39-8004-0489578299f6')
    None UUID('061cb8fe-0f0f-7df2-8000-afd57c2bf446')
    Nrsl Ysééipééééÿ?i€éÚstrz>08xú-z>04xÚbigé`éPé@é0ÚintÚhexz>032xÚbytes)r)	rÚdivmodÚosÚurandomrÚ
from_bytesÚto_bytesÚuuidÚUUID)rrr
Ú_lastÚ_last_as_ofÚlastÚt1Út2Út3Út4ÚrandÚsixteen_secsÚrest1Úrest2Ú_ÚrÚuuid_ints                 ú</tmp/pip-target-6culloxw/lib/python/uuid_extensions/uuid7.pyrrs€ðn
€zØ
ˆY‰[Œ[ˆØˆˆàˆÝ
‰WŒWˆà	ˆQ‚w€wàЈЈRА"r؈ˆð&ˆݘ2˜|Ñ,Ô,‰	ˆˆEݘ5 B™;¨Ñ5Ô5‰	ˆˆEݐu ‘{ LÑ1Ô1‰ˆˆAØ
ˆg‰
ˆð
a”Š=ˆ=˜R 4¨¤7š]˜]¨r°T¸!´Wª}¨}ðAŒw˜ÒÐØQ”˜1‘‘øà˜2˜r 1oˆD‰Gؘ˜aœÑ
 ˆõŒz˜!‰}Œ}ˆð%ÒÐØÐFÐFÐF˜BÐFÐFÐF bÐFÐFÐF°ÐFÐFÐF¸$¿(º(¹*¼*ÐFÐFÐF及t˜UÑ#Ô#€Aؐb‘˜R 2™XÑ&¨"°©(Ñ3°r¸R±xÑ@À1ÑD€Hؐ%ÒÐØˆØ	EÒ	Ð	ØÐ"Ð"Ð"Ø	GÒ	Ð	Ø× Ò   UÑ+Ô+Ð+åŒy˜XÐ&Ñ&Ô&Ð&ócó$—t|d¬¦«S)z9uuid7() as a string without creating a UUID object first.r)r)r)rs r6rr¬s€å˜UÐ#Ñ#Ô#Ð#r7Útiming_funccóF—dtjfdtjfdd„fg}|| d|f¦«g}|D]Ï\}}tj¦«}t	¦«}d}	| |¦«¦«|d	z
}tj¦«|z
}|d
kst
|¦«dkrnŒS|t
|¦«z}	||z}
| |›d|	d
›d|
d
›d|d›dt
|¦«d›d|dzd›d¦«ŒÐd |¦«S)aL
    Message indicating the timing precision from various time/clock
    functions that might be used for UUIDv7 generation.

    This tests time.time_ns(), time.perf_counter_ns()
    and datetime.datetime.utcnow converted to ns.

    A user-supplied timing function may also be provided.
    It must return the number of ns since the Unix Epoch
    (midnight at 1-Jan-1970).

    Note that time.time_ns() updates every 200us under Linux
    and potentially as infrequently as every 5ms under Windows.

    Usage:
    >>> check_timing_precision()
    # Under Linux
    time.time_ns()           has a timing precision of   221ns rather than 221ns (1,000 distinct samples in 0.00s)
    time.perf_counter_ns()   has a timing precision of   215ns rather than 215ns (1,000 distinct samples in 0.00s)
    datetime.datetime.utcnow has a timing precision of 1,046ns rather than 679ns (1,000 distinct samples in 0.00s)
    # Under Windows
    time.time_ns()           has a timing precision of 4,950,500ns rather than   709ns (705,068 samples of which 101 are distinct, in 0.50s)
    time.perf_counter_ns()   has a timing precision of       823ns rather than   823ns (1,000 samples of which 1,000 are distinct, in 0.00s)
    datetime.datetime.utcnow has a timing precision of 5,882,365ns rather than 2,812ns (177,792 samples of which 85 are distinct, in 0.50s)
    ztime.time_ns()ztime.perf_counter_ns()zdatetime.datetime.utcnowcó‚—ttj ¦« ¦«dz¦«S)Néʚ;)rÚdatetimeÚutcnowÚ	timestamp©r7r6ú<lambda>z(check_timing_precision.<locals>.<lambda>Ðs5€­SÝÔ×$Ò$Ñ&Ô&×0Ò0Ñ2Ô2°]ÑBñ.Dô.D€r7Nz
user-suppliedrTrieÍièz has a timing precision of z0,.0fzns rather than zns (ú,z samples of which z are distinct, in r<z0.2fzs)ú
)ÚtimerÚperf_counter_nsÚappendÚsetÚaddÚlenÚjoin)r9Útiming_funcsÚlinesÚdescÚfnÚ
started_nsÚvaluesÚctrÚ
elapsed_nsÚprecision_nsÚideal_precision_nss           r6rr±sº€ð:
4œ<Ð(Ø	!¥4Ô#7Ð8Ø	#ð&Dð&Dð	Eð€LðÐØ×Ò˜_¨kÐ:Ñ;Ô;Ð;à€EØ ð
ð
‰ˆˆbÝÔ)Ñ+Ô+ˆ
Ý‘”ˆØˆð	ØJŠJrr‘t”tÑÔÐØ1‰HˆCÝÔ-Ñ/Ô/°*Ñ<ˆJؘKÒ'Ð'­3¨v©;¬;¸$Ò+>Ð+>Øð	ð"¥C¨¡K¤KÑ/ˆØ'¨#Ñ-ÐØ
ŠØð
Fð
F°ð
Fð
Fð
FØ
ð
Fð
Fð
FØ+.ð
Fð
Fð
Få€V„ð
Fð
Fð
Fà",¨}Ñ"<ð
Fð
Fð
Fð
Fñ	
ô	
ð	
ð	
ð9Š9UÑÔÐr7TÚscóÈ—t|tj¦«r|j}n‡|sd}n‚t|t¦«rt |dd¬¦«}nOt	t
|¦« dd¦«d¬¦«}t |dd¬¦«}|dd	z	}|d
krƒtj	d|¦«}|dd
z	dz}|dd	z|dd
z	z}|ddzdz|ddzdzz|ddzz}t|dzd¦«\}}	|dz|z}
|
S|rdStt
|¦«›d|›d¦«‚)a\
    Recover the timestamp from a UUIDv7, passed in
    as a string, integer or a UUID object.

    If the UUID is not a version 7 UUID, either raise a ValueError
    or return None, depending on suppress_error.

    Usage:
    >>> uuid_to_datetime("1eb22fe4-3f0c-62b1-a88c-8dc55231702f")
    datetime.datetime(2020, 11, 10, 2, 41, 42, 182162)
    srr)ÚlengthÚ	byteorderrÚ)Úbaserééz>IHHHHIrrérriÿéérrr<lNz is a version z1 UUID, not v7 so we cannot extract the timestamp.)Ú
isinstancer&r'r rr%rÚreplaceÚstructÚunpackr!Ú
ValueError)rUÚsuppress_errorÚxÚint_uuidÚuuid_versionÚbitsÚ
whole_secsÚfrac_binaryÚfrac_nsr3Úns_since_epochs           r6Útimestamp_nsrnìsœ€õ!•T”YÑÔð?Ø
ŒGˆˆØ
ð?ØˆˆÝ	A•sÑ	Ô	ð?ÝLŠL˜ 2°ˆLÑ7Ô7ˆˆå•s˜1‘v”v—~’~ c¨2Ñ.Ô.°RÐ8Ñ8Ô8ˆÝLŠL˜¨"¸ˆLÑ>Ô>ˆàQ”4˜1‘9€LؐqÒÐÝŒ}˜Y¨Ñ*Ô*ˆØ˜Qœ 2™
¨Ñ,ˆà˜1”g ‘l t¨A¤w°"¡}Ñ5ˆ
à1Œg˜Ñ 2Ñ
%ؐQ”˜&Ñ  RÑ'ñ
)àQ”˜&Ñ ñ
#ð	õ
˜K¨-Ñ7¸ÑAÔA‰
ˆØ# mÑ3°gÑ=ˆØÐØ	ð
؈tåݐ1‰vŒvð
,ð
, \ð
,ð
,ð
,ñ
ô
ð	
r7có’—t||¬¦«}|€dStj |dztjj¬¦«S)N)rer<)Útz)rnr=Ú
fromtimestampÚtimezoneÚutc)rUrerms   r6rrsR€õ" !°NÐCÑCÔC€NØÐ؈tåÔ ×.Ò.Ø˜]Ñ*ÝÔ Ô$ð/ñ
ô
ð	
r7)N)T)Ú__doc__Ú__all__r=r"rbrDÚtypingrr	r
r&rrrr'r rrrrnrr@r7r6ú<module>rwsèðððð€ð€€€Ø	€	€	€	Ø
€
€
€
Ø€€€Ø,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ð,Ø€€€ðŒ,€ðØ!Ø#*Ø
ˆ,ˆ,ؐðM'ðM'ؐŒ
ðM'à
cŒ]ðM'ð˜˜C˜Ô ðM'ðˆ4Œ9c˜3 Ð%Ô&ð
M'ðM'ðM'ðM'ð`$ð$˜#”ð$¨#ð$ð$ð$ð$ð04ð8ð8ؘ( 2 s 7Ô+Ô,ð8àð8ð8ð8ð8ðzð-
ð-
ØˆS$”)˜SÐ
 Ô!ð-
ðˆc„]ð-
ð-
ð-
ð-
ðdð
ð
ØˆS$”)˜SÐ
 Ô!ð
ðˆhÔÔ ð
ð
ð
ð
ð
ð
r7