Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/mdurl/_decode.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from __future__ import annotations

from collections.abc import Sequence
import functools
import re

TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Sequence


DECODE_DEFAULT_CHARS = ";/?:@&=+$,#"
DECODE_COMPONENT_CHARS = ""

Expand Down
13 changes: 9 additions & 4 deletions src/mdurl/_encode.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from __future__ import annotations

from collections.abc import Sequence
from string import ascii_letters, digits, hexdigits
from urllib.parse import quote as encode_uri_component

ASCII_LETTERS_AND_DIGITS = ascii_letters + digits
TYPE_CHECKING = False
if TYPE_CHECKING:
from collections.abc import Sequence

ASCII_LETTERS_AND_DIGITS = (
"abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789"
)
HEXDIGITS = "0123456789" "abcdef" "ABCDEF"

ENCODE_DEFAULT_CHARS = ";/?:@&=+$,-_.!~*'()#"
ENCODE_COMPONENT_CHARS = "-_.!~*'()"
Expand Down Expand Up @@ -56,7 +61,7 @@ def encode(

# %
if keep_escaped and code == 0x25 and i + 2 < l:
if all(c in hexdigits for c in string[i + 1 : i + 3]):
if all(c in HEXDIGITS for c in string[i + 1 : i + 3]):
result += string[i : i + 3]
i += 2
i += 1 # JS for loop statement3
Expand Down
3 changes: 1 addition & 2 deletions src/mdurl/_format.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING

TYPE_CHECKING = False
if TYPE_CHECKING:
from mdurl._url import URL

Expand Down
42 changes: 30 additions & 12 deletions src/mdurl/_url.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
from __future__ import annotations

from typing import NamedTuple


class URL(NamedTuple):
protocol: str | None
slashes: bool
auth: str | None
port: str | None
hostname: str | None
hash: str | None # noqa: A003
search: str | None
pathname: str | None
from collections import namedtuple

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import NamedTuple

class URL(NamedTuple):
protocol: str | None
slashes: bool
auth: str | None
port: str | None
hostname: str | None
hash: str | None # noqa: A003
search: str | None
pathname: str | None

else:
URL = namedtuple(
"URL",
[
"protocol",
"slashes",
"auth",
"port",
"hostname",
"hash",
"search",
"pathname",
],
)