|
7 | 7 | # they're correct regardless, so it's okay if the checks are stripped out. |
8 | 8 | # ruff: noqa: S101 |
9 | 9 |
|
10 | | -from dataclasses import dataclass |
| 10 | +from dataclasses import dataclass, field |
11 | 11 | from enum import Enum |
12 | | -from typing import TYPE_CHECKING, ClassVar |
| 12 | +from typing import TYPE_CHECKING, ClassVar, Mapping |
13 | 13 |
|
14 | | -from .types import TimestampFormat |
| 14 | +from .types import TimestampFormat, PathPattern |
15 | 15 | from .shapes import ShapeID |
16 | 16 |
|
17 | 17 | if TYPE_CHECKING: |
@@ -193,3 +193,117 @@ def __post_init__(self): |
193 | 193 | @property |
194 | 194 | def value(self) -> str: |
195 | 195 | return self.document_value # type: ignore |
| 196 | + |
| 197 | + |
| 198 | +# TODO: Get all this moved over to the http package |
| 199 | +@dataclass(init=False, frozen=True) |
| 200 | +class HTTPTrait(Trait, id=ShapeID("smithy.api#http")): |
| 201 | + path: PathPattern = field(repr=False, hash=False, compare=False) |
| 202 | + code: int = field(repr=False, hash=False, compare=False) |
| 203 | + query: str | None = field(default=None, repr=False, hash=False, compare=False) |
| 204 | + |
| 205 | + def __init__(self, value: "DocumentValue | DynamicTrait" = None): |
| 206 | + super().__init__(value) |
| 207 | + assert isinstance(self.document_value, Mapping) |
| 208 | + assert isinstance(self.document_value["method"], str) |
| 209 | + |
| 210 | + code = self.document_value.get("code", 200) |
| 211 | + assert isinstance(code, int) |
| 212 | + object.__setattr__(self, "code", code) |
| 213 | + |
| 214 | + uri = self.document_value["uri"] |
| 215 | + assert isinstance(uri, str) |
| 216 | + parts = uri.split("?", 1) |
| 217 | + |
| 218 | + object.__setattr__(self, "path", PathPattern(parts[0])) |
| 219 | + object.__setattr__(self, "query", parts[1] if len(parts) == 2 else None) |
| 220 | + |
| 221 | + @property |
| 222 | + def method(self) -> str: |
| 223 | + return self.document_value["method"] # type: ignore |
| 224 | + |
| 225 | + |
| 226 | +@dataclass(init=False, frozen=True) |
| 227 | +class HTTPErrorTrait(Trait, id=ShapeID("smithy.api#httpError")): |
| 228 | + def __post_init__(self): |
| 229 | + assert isinstance(self.document_value, int) |
| 230 | + |
| 231 | + @property |
| 232 | + def code(self) -> int: |
| 233 | + return self.document_value # type: ignore |
| 234 | + |
| 235 | + |
| 236 | +@dataclass(init=False, frozen=True) |
| 237 | +class HTTPHeaderTrait(Trait, id=ShapeID("smithy.api#httpHeader")): |
| 238 | + def __post_init__(self): |
| 239 | + assert isinstance(self.document_value, str) |
| 240 | + |
| 241 | + @property |
| 242 | + def key(self) -> str: |
| 243 | + return self.document_value # type: ignore |
| 244 | + |
| 245 | + |
| 246 | +@dataclass(init=False, frozen=True) |
| 247 | +class HTTPLabelTrait(Trait, id=ShapeID("smithy.api#httpLabel")): |
| 248 | + def __post_init__(self): |
| 249 | + assert self.document_value is None |
| 250 | + |
| 251 | + |
| 252 | +@dataclass(init=False, frozen=True) |
| 253 | +class HTTPPayloadTrait(Trait, id=ShapeID("smithy.api#httpPayload")): |
| 254 | + def __post_init__(self): |
| 255 | + assert self.document_value is None |
| 256 | + |
| 257 | + |
| 258 | +@dataclass(init=False, frozen=True) |
| 259 | +class HTTPPrefixHeadersTrait(Trait, id=ShapeID("smithy.api#httpPrefixHeaders")): |
| 260 | + def __post_init__(self): |
| 261 | + assert isinstance(self.document_value, str) |
| 262 | + |
| 263 | + @property |
| 264 | + def prefix(self) -> str: |
| 265 | + return self.document_value # type: ignore |
| 266 | + |
| 267 | + |
| 268 | +@dataclass(init=False, frozen=True) |
| 269 | +class HTTPQueryTrait(Trait, id=ShapeID("smithy.api#httpQuery")): |
| 270 | + def __post_init__(self): |
| 271 | + assert isinstance(self.document_value, str) |
| 272 | + |
| 273 | + @property |
| 274 | + def name(self) -> str: |
| 275 | + return self.document_value # type: ignore |
| 276 | + |
| 277 | + |
| 278 | +@dataclass(init=False, frozen=True) |
| 279 | +class HTTPQueryParamsTrait(Trait, id=ShapeID("smithy.api#httpQueryParams")): |
| 280 | + def __post_init__(self): |
| 281 | + assert self.document_value is None |
| 282 | + |
| 283 | + |
| 284 | +@dataclass(init=False, frozen=True) |
| 285 | +class HTTPResponseCodeTrait(Trait, id=ShapeID("smithy.api#httpResponseCode")): |
| 286 | + def __post_init__(self): |
| 287 | + assert self.document_value is None |
| 288 | + |
| 289 | + |
| 290 | +@dataclass(init=False, frozen=True) |
| 291 | +class HTTPChecksumRequiredTrait(Trait, id=ShapeID("smithy.api#httpChecksumRequired")): |
| 292 | + def __post_init__(self): |
| 293 | + assert self.document_value is None |
| 294 | + |
| 295 | + |
| 296 | +@dataclass(init=False, frozen=True) |
| 297 | +class EndpointTrait(Trait, id=ShapeID("smithy.api#endpoint")): |
| 298 | + def __post_init__(self): |
| 299 | + assert isinstance(self.document_value, str) |
| 300 | + |
| 301 | + @property |
| 302 | + def host_prefix(self) -> str: |
| 303 | + return self.document_value["hostPrefix"] # type: ignore |
| 304 | + |
| 305 | + |
| 306 | +@dataclass(init=False, frozen=True) |
| 307 | +class HostLabelTrait(Trait, id=ShapeID("smithy.api#hostLabel")): |
| 308 | + def __post_init__(self): |
| 309 | + assert self.document_value is None |
0 commit comments