020 update city code resolving
This commit is contained in:
+9
-14
@@ -21,7 +21,6 @@ class RequestLike(Protocol):
|
||||
entity: object
|
||||
from_city: object
|
||||
to_city: object
|
||||
country_code: object
|
||||
weight_kg: object
|
||||
length_cm: object
|
||||
width_cm: object
|
||||
@@ -31,9 +30,8 @@ class RequestLike(Protocol):
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class NormalizedDeliveryRequest:
|
||||
entity: str
|
||||
from_city: str
|
||||
to_city: str
|
||||
country_code: str | None
|
||||
from_city: int
|
||||
to_city: int
|
||||
weight_kg: Decimal
|
||||
length_cm: Decimal
|
||||
width_cm: Decimal
|
||||
@@ -61,9 +59,8 @@ def normalize_delivery_request(
|
||||
|
||||
return NormalizedDeliveryRequest(
|
||||
entity=str(_get_required_attr(request, "entity")),
|
||||
from_city=_normalize_text(_get_required_attr(request, "from_city")),
|
||||
to_city=_normalize_text(_get_required_attr(request, "to_city")),
|
||||
country_code=_normalize_country_code(_get_optional_attr(request, "country_code")),
|
||||
from_city=_normalize_city_id(_get_required_attr(request, "from_city")),
|
||||
to_city=_normalize_city_id(_get_required_attr(request, "to_city")),
|
||||
weight_kg=_normalize_weight(
|
||||
_to_decimal(_get_required_attr(request, "weight_kg")),
|
||||
normalized_weight_scale,
|
||||
@@ -219,13 +216,11 @@ def _normalize_text(value: object) -> str:
|
||||
return str(value).strip()
|
||||
|
||||
|
||||
def _normalize_country_code(value: object) -> str | None:
|
||||
if value is _MISSING or value is None:
|
||||
return None
|
||||
normalized = str(value).strip().upper()
|
||||
if not normalized:
|
||||
return None
|
||||
return normalized
|
||||
def _normalize_city_id(value: object) -> int:
|
||||
city_id = _try_to_int(value)
|
||||
if city_id is None:
|
||||
raise ValueError(f"City identifier must be an integer: {value!r}")
|
||||
return city_id
|
||||
|
||||
|
||||
def _clamp_scale(scale: int) -> int:
|
||||
|
||||
Reference in New Issue
Block a user