lemoncurry/lemonshort/convert.py

18 lines
510 B
Python
Raw Permalink Normal View History

from baseconv import BaseConverter
from string import ascii_lowercase, ascii_uppercase
# We have to create this collection ourselves because we want uppercase then
# lowercase, and string.ascii_letters is lowercase then uppercase.
chars = ascii_uppercase + ascii_lowercase
conv = BaseConverter(chars)
2023-08-10 02:52:37 -04:00
class AbcIdConverter:
2023-08-10 02:52:37 -04:00
regex = "[a-zA-Z]+"
def to_python(self, value: str) -> int:
return int(conv.decode(value))
def to_url(self, value: int) -> str:
return conv.encode(value)