xn-auth 0.2.68.dev1__tar.gz → 0.2.68.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/.pre-commit-config.yaml +1 -1
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/PKG-INFO +1 -1
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/models.py +23 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/PKG-INFO +1 -1
- xn_auth-0.2.68.dev3/xn_auth.egg-info/scm_version.json +8 -0
- xn_auth-0.2.68.dev1/xn_auth.egg-info/scm_version.json +0 -8
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/.env.dist +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/.gitignore +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/CLAUDE.md +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/README.md +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/makefile +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/pyproject.toml +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/setup.cfg +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/tests/test_proxy.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/controller.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/enums.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/exceptions.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/middleware.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/x_auth/types.py +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/SOURCES.txt +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/dependency_links.txt +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/requires.txt +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/scm_file_list.json +0 -0
- {xn_auth-0.2.68.dev1 → xn_auth-0.2.68.dev3}/xn_auth.egg-info/top_level.txt +0 -0
|
@@ -27,6 +27,7 @@ from tortoise.fields import (
|
|
|
27
27
|
CASCADE,
|
|
28
28
|
Now,
|
|
29
29
|
)
|
|
30
|
+
from tortoise.exceptions import IntegrityError
|
|
30
31
|
from tortoise.fields.data import CharEnumFieldInstance
|
|
31
32
|
|
|
32
33
|
from x_auth import types
|
|
@@ -103,6 +104,28 @@ class Country(Model):
|
|
|
103
104
|
|
|
104
105
|
proxies: BackwardFKRelation["Proxy"]
|
|
105
106
|
|
|
107
|
+
@classmethod
|
|
108
|
+
async def get_or_create_by_shortcode(cls, code: str, tries: int = 5) -> "Country":
|
|
109
|
+
"""Страна по ISO-коду с сайта; незнакомую заводим, как и город: справочник ведёт сайт.
|
|
110
|
+
|
|
111
|
+
Сайт кладёт в карточку код и молчит о названии, поэтому имя ставим тем же кодом. Id
|
|
112
|
+
считаем сами: у country он uint1 и без sequence.
|
|
113
|
+
|
|
114
|
+
Оттого и цикл, а не одна попытка: номер мы берём чтением, и пока считали, соседняя ветка
|
|
115
|
+
успевает занять и его, и сам код — карточки пачки заводят страны разом. Конфликт значит
|
|
116
|
+
«кто-то уже завёл», и после него всё начинается сначала: либо найдётся чужая строка, либо
|
|
117
|
+
возьмётся следующий свободный номер.
|
|
118
|
+
"""
|
|
119
|
+
while True:
|
|
120
|
+
if row := await cls.get_or_none(short=code):
|
|
121
|
+
return row
|
|
122
|
+
last = await cls.all().order_by("-id").first()
|
|
123
|
+
try:
|
|
124
|
+
return await cls.create(id=(last.id if last else 0) + 1, short=code, name=code)
|
|
125
|
+
except IntegrityError:
|
|
126
|
+
if (tries := tries - 1) <= 0:
|
|
127
|
+
raise
|
|
128
|
+
|
|
106
129
|
|
|
107
130
|
class Proxy(Model, TsTrait):
|
|
108
131
|
id: int = CharField(63, primary_key=True)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|