Compare commits
10 Commits
main
...
acb22f053a
| Author | SHA1 | Date | |
|---|---|---|---|
| acb22f053a | |||
| 6597adf868 | |||
| 1dfd59ef88 | |||
| dbea7b607c | |||
| 7d623ba4ad | |||
| 3a13c94b78 | |||
| 5c01d319f5 | |||
| a3b1b9473c | |||
| 22d677d119 | |||
| 9a5ac4bcbf |
+176
@@ -0,0 +1,176 @@
|
|||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/python
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
||||||
|
|
||||||
|
### Python ###
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
*.py,cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
cover/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
db.sqlite3-journal
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
# PyBuilder
|
||||||
|
.pybuilder/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
# For a library or package, you might want to ignore these files since the code is
|
||||||
|
# intended to run in multiple environments; otherwise, check them in:
|
||||||
|
# .python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# poetry
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||||
|
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||||
|
# commonly ignored for libraries.
|
||||||
|
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||||
|
#poetry.lock
|
||||||
|
|
||||||
|
# pdm
|
||||||
|
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||||
|
#pdm.lock
|
||||||
|
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||||
|
# in version control.
|
||||||
|
# https://pdm.fming.dev/#use-with-ide
|
||||||
|
.pdm.toml
|
||||||
|
|
||||||
|
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||||
|
__pypackages__/
|
||||||
|
|
||||||
|
# Celery stuff
|
||||||
|
celerybeat-schedule
|
||||||
|
celerybeat.pid
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# pytype static type analyzer
|
||||||
|
.pytype/
|
||||||
|
|
||||||
|
# Cython debug symbols
|
||||||
|
cython_debug/
|
||||||
|
|
||||||
|
# PyCharm
|
||||||
|
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
||||||
|
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
|
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||||
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
|
#.idea/
|
||||||
|
|
||||||
|
### Python Patch ###
|
||||||
|
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
||||||
|
poetry.toml
|
||||||
|
|
||||||
|
# ruff
|
||||||
|
.ruff_cache/
|
||||||
|
|
||||||
|
# LSP config files
|
||||||
|
pyrightconfig.json
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
from typing import ClassVar
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Counter():
|
||||||
|
top: int
|
||||||
|
value: int
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Minter():
|
||||||
|
legalstring: ClassVar[str] = "0123456789bcdfghjkmnpqrstvwxz"
|
||||||
|
alphacount: ClassVar[int] = len(legalstring)
|
||||||
|
digitcount: ClassVar[int] = 10
|
||||||
|
|
||||||
|
oacounter: int = 0
|
||||||
|
oatop: int = 0
|
||||||
|
percounter: int = 0
|
||||||
|
template: str = ""
|
||||||
|
prefix: str = ""
|
||||||
|
mask: str = ""
|
||||||
|
active_counters: list[Counter] = field(default_factory=list)
|
||||||
|
inactive_counters: list[Counter] = field(default_factory=list)
|
||||||
|
|
||||||
|
def parse_template(self, template: str) -> int:
|
||||||
|
self.template = template
|
||||||
|
template = template.strip().removesuffix('/').strip()
|
||||||
|
try:
|
||||||
|
self.prefix, *_, self.mask = template.split(".")
|
||||||
|
except ValueError:
|
||||||
|
self.prefix = ""
|
||||||
|
self.mask = template
|
||||||
|
|
||||||
|
if self.mask[0] not in ("r", "s", "z"):
|
||||||
|
return -1 # mask must begin with of the letters: r, s or z
|
||||||
|
if "k" in self.mask and (self.mask.count("k") > 1 or self.mask[-1] != "k"):
|
||||||
|
return -1
|
||||||
|
if not all(char in ("d", "e") for char in self.mask.rstrip("k")[1:]):
|
||||||
|
return -1
|
||||||
|
self.oatop = 1
|
||||||
|
for chr in self.mask:
|
||||||
|
match chr:
|
||||||
|
case "e":
|
||||||
|
self.oatop *= self.alphacount
|
||||||
|
case "d":
|
||||||
|
self.oatop *= self.digitcount
|
||||||
|
return self.oatop
|
||||||
|
|
||||||
|
def genid(self) -> str:
|
||||||
|
# 1. Check if the oacounter >= oatop
|
||||||
|
# -> noid are exhausted
|
||||||
|
# -> At this time, all our noid are considered as longterm
|
||||||
|
# -> At this tile, all our noid are not sequential, thus random
|
||||||
|
# 2. Get the size of saclist (active counters list)
|
||||||
|
# 3. if that size is less than 1 then no more active counters then no noid
|
||||||
|
# 4. pick at random an active counter
|
||||||
|
# - rand → int (index to use)
|
||||||
|
# 5. get its value
|
||||||
|
# 6. increment its value
|
||||||
|
# 7. increment oacounter
|
||||||
|
# 8. deal with an exhausted subcounter
|
||||||
|
# - if new value is more more or equal to the top value of this counter
|
||||||
|
# - remove this counter from the saclist
|
||||||
|
# - add this counter to the siclist
|
||||||
|
# 9. Generate the noid with a call to n2xdig()
|
||||||
|
# - Arguments
|
||||||
|
# - value + (index * percounter)
|
||||||
|
# - mask
|
||||||
|
# 10. return the noid
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def initcounters(self) -> None:
|
||||||
|
# 1. [X] Initialize oacounter to 0
|
||||||
|
# 2. [X] Set up a maxcounters variable to 293
|
||||||
|
# 3. [X] Set up a percounter variable to int(total / maxcounters + 1)
|
||||||
|
# 4. [X] Divides $total into sub-counters of size $pctr, stores this
|
||||||
|
# distribution in $noid, and prepares the structure to generate
|
||||||
|
# IDs in a balanced manner.
|
||||||
|
# - copy the value of total to the variable t
|
||||||
|
# - copy the value of percounter to pctr
|
||||||
|
# - initialize saclist as an empty string (list)
|
||||||
|
# - while t is more than zero
|
||||||
|
# - set up the top value for the counter
|
||||||
|
# `$t >= $pctr ? $pctr : $t`
|
||||||
|
# - set value of this counter to 0
|
||||||
|
# - add the counter to saclist
|
||||||
|
# - substract pctr from t
|
||||||
|
maxcounters = 293
|
||||||
|
self.percounter = int(self.oatop / maxcounters + 1)
|
||||||
|
t = self.oatop
|
||||||
|
while t > 0:
|
||||||
|
top = self.percounter if t >= self.percounter else t
|
||||||
|
c = Counter(top=top, value=0)
|
||||||
|
self.active_counters.append(c)
|
||||||
|
t -= self.percounter
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
pass
|
||||||
@@ -3,3 +3,8 @@ name = "noid"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
requires-python = ">=3.14"
|
requires-python = ">=3.14"
|
||||||
dependencies = []
|
dependencies = []
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = [
|
||||||
|
"pytest>=9.1.1",
|
||||||
|
]
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import pytest
|
||||||
|
from noid import Minter
|
||||||
|
|
||||||
|
class TestParseTemplate:
|
||||||
|
"""Tests pour la méthode parse_template de la classe Minter"""
|
||||||
|
|
||||||
|
def test_parse_template_invalid_no_prefix_letter(self):
|
||||||
|
"""Test des templates invalides (mask ne commence pas par r, s ou z)"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("test")
|
||||||
|
assert result == -1
|
||||||
|
assert m.template == "test"
|
||||||
|
assert m.prefix == ""
|
||||||
|
assert m.mask == "test"
|
||||||
|
|
||||||
|
def test_parse_template_invalid_multiple_k(self):
|
||||||
|
"""Test des templates invalides (plusieurs 'k' dans le mask)"""
|
||||||
|
m = Minter()
|
||||||
|
assert m.parse_template("testkktest") == -1
|
||||||
|
|
||||||
|
def test_parse_template_invalid_k_not_at_end(self):
|
||||||
|
"""Test des templates invalides (k n'est pas à la fin)"""
|
||||||
|
m = Minter()
|
||||||
|
assert m.parse_template("rtesk") == -1
|
||||||
|
assert m.parse_template("rteksk") == -1
|
||||||
|
assert m.parse_template("rtkkes") == -1
|
||||||
|
|
||||||
|
def test_parse_template_invalid_chars_after_prefix(self):
|
||||||
|
"""Test des templates invalides (caractères autres que d/e après le préfixe)"""
|
||||||
|
m = Minter()
|
||||||
|
assert m.parse_template("ed") == -1
|
||||||
|
|
||||||
|
def test_parse_template_valid_reded(self):
|
||||||
|
"""Test d'une template valide 'reded'"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("reded")
|
||||||
|
assert result == 84100
|
||||||
|
assert m.template == "reded"
|
||||||
|
assert m.prefix == ""
|
||||||
|
assert m.mask == "reded"
|
||||||
|
|
||||||
|
def test_parse_template_valid_red(self):
|
||||||
|
"""Test d'une template valide 'red'"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("red")
|
||||||
|
assert result == 290
|
||||||
|
assert m.template == "red"
|
||||||
|
assert m.prefix == ""
|
||||||
|
assert m.mask == "red"
|
||||||
|
|
||||||
|
def test_parse_template_valid_redk(self):
|
||||||
|
"""Test d'une template valide 'redk' (k à la fin)"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("redk")
|
||||||
|
assert result == 290
|
||||||
|
assert m.template == "redk"
|
||||||
|
assert m.prefix == ""
|
||||||
|
assert m.mask == "redk"
|
||||||
|
|
||||||
|
def test_parse_template_with_prefix_and_mask(self):
|
||||||
|
"""Test d'une template avec préfixe et mask"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("prefix.rde")
|
||||||
|
assert result == 290
|
||||||
|
assert m.template == "prefix.rde"
|
||||||
|
assert m.prefix == "prefix"
|
||||||
|
assert m.mask == "rde"
|
||||||
|
|
||||||
|
def test_parse_template_with_suffix_slash(self):
|
||||||
|
"""Test d'une template avec suffixe '/'"""
|
||||||
|
m = Minter()
|
||||||
|
result = m.parse_template("test/")
|
||||||
|
assert result == -1 # car mask='test' ne commence pas par r/s/z
|
||||||
|
assert m.template == "test/"
|
||||||
|
assert m.prefix == ""
|
||||||
|
assert m.mask == "test"
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
version = 1
|
||||||
|
revision = 3
|
||||||
|
requires-python = ">=3.14"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorama"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "iniconfig"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "noid"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = { virtual = "." }
|
||||||
|
|
||||||
|
[package.dev-dependencies]
|
||||||
|
dev = [
|
||||||
|
{ name = "pytest" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.metadata]
|
||||||
|
|
||||||
|
[package.metadata.requires-dev]
|
||||||
|
dev = [{ name = "pytest", specifier = ">=9.1.1" }]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "packaging"
|
||||||
|
version = "26.2"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/d7/f1/e7a6dd94a8d4a5626c03e4e99c87f241ba9e350cd9e6d75123f992427270/packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661", size = 228134, upload-time = "2026-04-24T20:15:23.917Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/df/b2/87e62e8c3e2f4b32e5fe99e0b86d576da1312593b39f47d8ceef365e95ed/packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e", size = 100195, upload-time = "2026-04-24T20:15:22.081Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pluggy"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pygments"
|
||||||
|
version = "2.20.0"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pytest"
|
||||||
|
version = "9.1.1"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||||
|
{ name = "iniconfig" },
|
||||||
|
{ name = "packaging" },
|
||||||
|
{ name = "pluggy" },
|
||||||
|
{ name = "pygments" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/e4/47/b9efed96c114afcfa3c9d3fe98a76a1d14c74a9e266d397cf6eb64be5e01/pytest-9.1.1.tar.gz", hash = "sha256:1088fbde8f2b49d95a549a195707afa7a76a3ce9bcadc26b6d71f0ffda5fe313", size = 1636369, upload-time = "2026-06-19T10:58:32.857Z" }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/24/25/1de2678b631f5a49215c6c96fff41ba892b0a34df68d6d80292b1b48aa7f/pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c", size = 386536, upload-time = "2026-06-19T10:58:31.347Z" },
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user