Skip to content

Commit

Permalink
bug: fix some issues with pool URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
UpstreamData committed Nov 28, 2024
1 parent 0b524f9 commit 0c85f53
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pyasic/data/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from urllib.parse import urlparse

from pydantic import BaseModel, computed_field, model_serializer
from typing_extensions import Self


class Scheme(Enum):
Expand All @@ -28,8 +29,10 @@ def __str__(self) -> str:
return f"{self.scheme.value}://{self.host}:{self.port}"

@classmethod
def from_str(cls, url: str) -> "PoolUrl":
def from_str(cls, url: str) -> Self | None:
parsed_url = urlparse(url)
if not parsed_url.hostname:
return None
if not parsed_url.scheme.strip() == "":
scheme = Scheme(parsed_url.scheme)
else:
Expand Down Expand Up @@ -57,15 +60,15 @@ class PoolMetrics(BaseModel):
pool_stale_percent: Percentage of stale shares by the pool.
"""

url: PoolUrl
accepted: int = None
rejected: int = None
get_failures: int = None
remote_failures: int = None
active: bool = None
alive: bool = None
index: int = None
user: str = None
url: PoolUrl | None
accepted: int | None = None
rejected: int | None = None
get_failures: int | None = None
remote_failures: int | None = None
active: bool | None = None
alive: bool | None = None
index: int | None = None
user: str | None = None

@computed_field # type: ignore[misc]
@property
Expand Down

0 comments on commit 0c85f53

Please sign in to comment.