Skip to content

Commit 5d8fb0b

Browse files
committed
feat(proxy-checker): add serialization helpers to ProxyChekerResult
- import dataclasses.asdict and json - add ProxyChekerResult.to_dict() to produce a plain dict - add ProxyChekerResult.to_json() to produce a JSON string - add ProxyChekerResult.__str__() to return JSON for easy printing Improves result serialization and logging for proxy check results.
1 parent 5c09530 commit 5d8fb0b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎proxy_checker/ProxyChekerResult.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from dataclasses import dataclass
22
from typing import List, Optional
3+
from dataclasses import asdict
4+
import json
35

46

57
@dataclass
@@ -11,3 +13,15 @@ class ProxyChekerResult:
1113
country_code: Optional[str] = None
1214
proxy: Optional[str] = None
1315
error: bool = False
16+
17+
def to_dict(self) -> dict:
18+
"""Return a plain dict representation of the result."""
19+
return asdict(self)
20+
21+
def to_json(self) -> str:
22+
"""Return a JSON string representation of the result."""
23+
return json.dumps(self.to_dict())
24+
25+
def __str__(self) -> str:
26+
"""Human-readable JSON string for printing."""
27+
return self.to_json()

0 commit comments

Comments
 (0)