-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
56 lines (39 loc) · 1.62 KB
/
base.py
File metadata and controls
56 lines (39 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Base class for category clients."""
from __future__ import annotations
from astroapi.utils.http import HttpHelper
class BaseCategoryClient:
"""Base class for all category clients.
Provides common functionality for building URLs and making requests.
Attributes:
API_PREFIX: URL prefix for this category (overridden in subclasses)
"""
API_PREFIX: str = ""
def __init__(self, http: HttpHelper) -> None:
"""Initialize category client.
Args:
http: HTTP helper for making requests
"""
self._http = http
def _build_url(self, *segments: str | None) -> str:
"""Build URL from prefix and segments.
Filters out None values and properly joins path segments.
Args:
*segments: URL path segments (None values are filtered out)
Returns:
Complete URL path starting with /
"""
parts = [self.API_PREFIX] + [s for s in segments if s is not None]
clean_parts = [p.strip("/") for p in parts if p]
return "/" + "/".join(clean_parts)
def _build_custom_url(self, prefix: str, *segments: str | None) -> str:
"""Build URL with custom prefix.
Used by clients that need non-standard prefixes (e.g., EnhancedClient).
Args:
prefix: Custom URL prefix
*segments: URL path segments (None values are filtered out)
Returns:
Complete URL path starting with /
"""
parts = [prefix] + [s for s in segments if s is not None]
clean_parts = [p.strip("/") for p in parts if p]
return "/" + "/".join(clean_parts)