-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from appwrite/dev
Fix msg91 params
- Loading branch information
Showing
7 changed files
with
32 additions
and
14 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
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
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 |
---|---|---|
@@ -1,8 +1,26 @@ | ||
from datetime import datetime | ||
import math | ||
import os | ||
|
||
class ID: | ||
# Generate an hex ID based on timestamp | ||
# Recreated from https://www.php.net/manual/en/function.uniqid.php | ||
@staticmethod | ||
def __hex_timestamp(): | ||
now = datetime.now() | ||
sec = int(now.timestamp()) | ||
usec = (now.microsecond % 1000) | ||
hex_timestamp = f'{sec:08x}{usec:05x}' | ||
return hex_timestamp | ||
|
||
@staticmethod | ||
def custom(id): | ||
return id | ||
|
||
# Generate a unique ID with padding to have a longer ID | ||
@staticmethod | ||
def unique(): | ||
return 'unique()' | ||
def unique(padding = 7): | ||
base_id = ID.__hex_timestamp() | ||
random_bytes = os.urandom(math.ceil(padding / 2)) | ||
random_padding = random_bytes.hex()[:padding] | ||
return base_id + random_padding |
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
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
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
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