def parse_non_contract_shipment_response(
        response: Element,
        settings: Settings) -> Tuple[ShipmentDetails, List[Message]]:
    shipment = (_extract_shipment(response, settings) if len(
        response.xpath(".//*[local-name() = $name]", name="shipment-id")) > 0
                else None)
    return shipment, parse_error_response(response, settings)
예제 #2
0
def parse_price_quotes(
    response: Element, settings: Settings
) -> Tuple[List[RateDetails], List[Message]]:
    price_quotes = response.xpath(".//*[local-name() = $name]", name="price-quote")
    quotes: List[RateDetails] = [
        _extract_quote(price_quote_node, settings) for price_quote_node in price_quotes
    ]
    return quotes, parse_error_response(response, settings)
예제 #3
0
def parse_tracking_summary(
        response: Element,
        settings: Settings) -> Tuple[List[TrackingDetails], List[Message]]:
    pin_summaries = response.xpath(".//*[local-name() = $name]",
                                   name="pin-summary")
    tracking: List[TrackingDetails] = [
        _extract_tracking(pin, settings) for pin in pin_summaries
    ]
    return tracking, parse_error_response(response, settings)
예제 #4
0
def _extract_shipment(response: Element, settings: Settings) -> ShipmentDetails:
    info_node = next(
        iter(response.xpath(".//*[local-name() = $name]", name="shipment-info"))
    )
    label = next(iter(response.xpath(".//*[local-name() = $name]", name="label")))
    errors = parse_error_response(label, settings)
    info: ShipmentInfoType = ShipmentInfoType()
    info.build(info_node)

    return ShipmentDetails(
        carrier_name=settings.carrier_name,
        carrier_id=settings.carrier_id,
        tracking_number=info.tracking_pin,
        label=label.text if len(errors) == 0 else None,
    )