-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# Copyright (c) 2021 The Anvil Extras project team members listed at | ||
# https://github.com/anvilistas/anvil-extras/graphs/contributors | ||
# | ||
# This software is published at https://github.com/anvilistas/anvil-extras | ||
|
||
from anvil.js.window import Function as _F | ||
|
||
from .utils._component_helpers import _add_script | ||
|
||
__version__ = "1.3.1" | ||
|
||
from time import time | ||
|
||
js_uuid4, js_uuid_parse = _F( | ||
""" | ||
return new Promise(resolve => { | ||
window.anvilExtrasResolve = resolve; | ||
const s = document.createElement('script'); | ||
s.type = "module"; | ||
s.textContent = ` | ||
import { v4, parse } from 'https://jspm.dev/uuid@8.3.2'; | ||
window.anvilExtrasResolve([v4, parse]); | ||
` | ||
document.body.appendChild(s); | ||
}); | ||
""" | ||
)() | ||
|
||
|
||
class UUID(str): | ||
def __repr__(self): | ||
return "UUID('" + self + "')" | ||
|
||
@property | ||
def bytes(self): | ||
return js_uuid_parse(self) | ||
|
||
|
||
def uuid4(): | ||
"""returns a uuid""" | ||
return UUID(js_uuid4()) |