Skip to content

Commit 2637d88

Browse files
committed
Updates the lengths
1 parent f4ea991 commit 2637d88

File tree

1 file changed

+28
-35
lines changed

1 file changed

+28
-35
lines changed

bittensor_cli/src/bittensor/utils.py

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,38 +1097,30 @@ def prompt_for_identity(
10971097
identity_fields = {}
10981098

10991099
fields = [
1100-
("name", "[blue]Display name[/blue]", name),
1101-
("url", "[blue]Web URL[/blue]", web_url),
1102-
("image", "[blue]Image URL[/blue]", image_url),
1103-
("discord", "[blue]Discord handle[/blue]", discord),
1104-
("description", "[blue]Description[/blue]", description),
1105-
("additional", "[blue]Additional information[/blue]", additional),
1106-
("github_repo", "[blue]GitHub repository URL[/blue]", github_repo),
1100+
("name", "[blue]Display name[/blue]", name, 256),
1101+
("url", "[blue]Web URL[/blue]", web_url, 256),
1102+
("image", "[blue]Image URL[/blue]", image_url, 1024),
1103+
("discord", "[blue]Discord handle[/blue]", discord, 256),
1104+
("description", "[blue]Description[/blue]", description, 1024),
1105+
("additional", "[blue]Additional information[/blue]", additional, 1024),
1106+
("github_repo", "[blue]GitHub repository URL[/blue]", github_repo, 256),
11071107
]
11081108

1109-
text_rejection = partial(
1110-
retry_prompt,
1111-
rejection=lambda x: sys.getsizeof(x) > 113,
1112-
rejection_text="[red]Error:[/red] Identity field must be <= 64 raw bytes.",
1113-
)
1114-
11151109
if not any(
1116-
[
1117-
name,
1118-
web_url,
1119-
image_url,
1120-
discord,
1121-
description,
1122-
additional,
1123-
github_repo,
1124-
]
1110+
[name, web_url, image_url, discord, description, additional, github_repo]
11251111
):
11261112
console.print(
11271113
"\n[yellow]All fields are optional. Press Enter to skip and keep the default/existing value.[/yellow]\n"
11281114
"[dark_sea_green3]Tip: Entering a space and pressing Enter will clear existing default value.\n"
11291115
)
11301116

1131-
for key, prompt, value in fields:
1117+
for key, prompt, value, byte_limit in fields:
1118+
text_rejection = partial(
1119+
retry_prompt,
1120+
rejection=lambda x: len(x.encode("utf-8")) > byte_limit,
1121+
rejection_text=f"[red]Error:[/red] {key} field must be <= {byte_limit} bytes.",
1122+
)
1123+
11321124
if value:
11331125
identity_fields[key] = value
11341126
else:
@@ -1170,50 +1162,51 @@ def prompt_for_subnet_identity(
11701162
"subnet_name",
11711163
"[blue]Subnet name [dim](optional)[/blue]",
11721164
subnet_name,
1173-
lambda x: x and sys.getsizeof(x) > 113,
1174-
"[red]Error:[/red] Subnet name must be <= 64 raw bytes.",
1165+
lambda x: x and len(x.encode("utf-8")) > 256,
1166+
"[red]Error:[/red] Subnet name must be <= 256 bytes.",
11751167
),
11761168
(
11771169
"github_repo",
11781170
"[blue]GitHub repository URL [dim](optional)[/blue]",
11791171
github_repo,
1180-
lambda x: x and not is_valid_github_url(x),
1172+
lambda x: x
1173+
and (not is_valid_github_url(x) or len(x.encode("utf-8")) > 1024),
11811174
"[red]Error:[/red] Please enter a valid GitHub repository URL (e.g., https://github.com/username/repo).",
11821175
),
11831176
(
11841177
"subnet_contact",
11851178
"[blue]Contact email [dim](optional)[/blue]",
11861179
subnet_contact,
1187-
lambda x: x and not is_valid_contact(x),
1180+
lambda x: x and (not is_valid_contact(x) or len(x.encode("utf-8")) > 1024),
11881181
"[red]Error:[/red] Please enter a valid email address.",
11891182
),
11901183
(
11911184
"subnet_url",
11921185
"[blue]Subnet URL [dim](optional)[/blue]",
11931186
subnet_url,
1194-
lambda x: x and sys.getsizeof(x) > 113,
1195-
"[red]Error:[/red] Please enter a valid URL.",
1187+
lambda x: x and len(x.encode("utf-8")) > 1024,
1188+
"[red]Error:[/red] Please enter a valid URL <= 1024 bytes.",
11961189
),
11971190
(
11981191
"discord",
11991192
"[blue]Discord handle [dim](optional)[/blue]",
12001193
discord,
1201-
lambda x: x and sys.getsizeof(x) > 113,
1202-
"[red]Error:[/red] Please enter a valid Discord handle.",
1194+
lambda x: x and len(x.encode("utf-8")) > 256,
1195+
"[red]Error:[/red] Please enter a valid Discord handle <= 256 bytes.",
12031196
),
12041197
(
12051198
"description",
12061199
"[blue]Description [dim](optional)[/blue]",
12071200
description,
1208-
lambda x: x and sys.getsizeof(x) > 113,
1209-
"[red]Error:[/red] Description must be <= 64 raw bytes.",
1201+
lambda x: x and len(x.encode("utf-8")) > 1024,
1202+
"[red]Error:[/red] Description must be <= 1024 bytes.",
12101203
),
12111204
(
12121205
"additional",
12131206
"[blue]Additional information [dim](optional)[/blue]",
12141207
additional,
1215-
lambda x: x and sys.getsizeof(x) > 113,
1216-
"[red]Error:[/red] Additional information must be <= 64 raw bytes.",
1208+
lambda x: x and len(x.encode("utf-8")) > 1024,
1209+
"[red]Error:[/red] Additional information must be <= 1024 bytes.",
12171210
),
12181211
]
12191212

0 commit comments

Comments
 (0)