# Path: roulier/codec.py
# class DecoderGetLabel(ABC):
#     def __init__(self, config_object):
#         """
#         items in parcels list should be a dict of this form
#         label = {
#             "id": 1,
#             "reference": "",
#             "tracking": {
#                 "number":"",
#                 "url": "",
#                 "partner": "",
#             },
#             "label": {
#                 "data": base64 label,
#                 "name": "",
#                 "type": "",
#             },
#         }
#         """
#         self.config = config_object
#         self.result = {
#             "parcels": [],
#             "annexes": [],
#         }
# 
#     @abstractmethod
#     def decode(self, response, payload):
#         """Transform a specific representation to python dict.
#         Args:
#             response : answer from the webservice
#             payload : data sent initially to the webservice
#         Need to increment the result attribute of the object, it does not need to return
#         anything
#         """
#         pass
# 
#     # helper to get the reference in case of mono_parcel
#     def _get_parcel_number(self, payload):
#         parcel_ref = ""
#         roulier_input = self.config.roulier_input or {}
#         parcels = roulier_input.get("parcels", [])
#         if len(parcels) == 1:
#             parcel_ref = parcels[0].get("reference", "")
#         return parcel_ref
# 
# Path: roulier/codec.py
# class DecoderGetPackingSlip(ABC):
#     def __init__(self, config_object):
#         """
#         packing_slip should be a dict of this form
#         {
#             "number": "string" or None,
#             "published_datetime": aware_datetime or None,
#             "number_of_parcels": int or None,
#             "client": {
#                 "number": "string" or None,
#                 "adress": "string" or None,
#                 "company": "string" or None,
#             }
#         }
#         """
#         self.config = config_object
#         self.result = {
#             "packing_slip": {},
#             "annexes": [],
#         }
# 
#     @abstractmethod
#     def decode(self, response, payload):
#         """Transform a specific representation to python dict.
#         Args:
#             response : answer from the webservice
#             payload : data sent initially to the webservice
#         Need to increment the result attribute of the object, it does not need to return
#         anything
#         """
#         pass


from datetime import datetime
from lxml import objectify
from ...codec import DecoderGetLabel
from ...codec import DecoderGetPackingSlip
import base64
            annexes.append(
                {"name": "cn23", "data": base64.b64encode(data), "type": "pdf"}
            )

        if rep.find("pdfUrl"):
            annexes.append({"name": "label", "data": rep.find("pdfUrl"), "type": "url"})

        parcel = {
            "id": 1,  # no multi parcel management for now.
            "reference": self._get_parcel_number(input_payload),
            "tracking": {
                # we need to force to real string because of those data can be reused
                # and cerberus won't accept an ElementString insteadof a string.
                "number": _get_text(rep, "parcelNumber"),
                "url": "",
                "partner": _get_text(rep, "parcelNumberPartner", ""),
            },
            "label": {
                "data": base64.b64encode(parts.get(label_cid)),
                "name": "label_1",
                "type": output_format,
            },
        }
        if hasattr(rep, "fields") and hasattr(rep.fields, "field"):
            for field in rep.fields.field:
                parcel["tracking"][_get_text(field, "key")] = _get_text(field, "value")
        self.result["parcels"].append(parcel)
        self.result["annexes"] += annexes



# Path: roulier/codec.py
# class DecoderGetLabel(ABC):
#     def __init__(self, config_object):
#         """
#         items in parcels list should be a dict of this form
#         label = {
#             "id": 1,
#             "reference": "",
#             "tracking": {
#                 "number":"",
#                 "url": "",
#                 "partner": "",
#             },
#             "label": {
#                 "data": base64 label,
#                 "name": "",
#                 "type": "",
#             },
#         }
#         """
#         self.config = config_object
#         self.result = {
#             "parcels": [],
#             "annexes": [],
#         }
# 
#     @abstractmethod
#     def decode(self, response, payload):
#         """Transform a specific representation to python dict.
#         Args:
#             response : answer from the webservice
#             payload : data sent initially to the webservice
#         Need to increment the result attribute of the object, it does not need to return
#         anything
#         """
#         pass
# 
#     # helper to get the reference in case of mono_parcel
#     def _get_parcel_number(self, payload):
#         parcel_ref = ""
#         roulier_input = self.config.roulier_input or {}
#         parcels = roulier_input.get("parcels", [])
#         if len(parcels) == 1:
#             parcel_ref = parcels[0].get("reference", "")
#         return parcel_ref
# 
# Path: roulier/codec.py
# class DecoderGetPackingSlip(ABC):
#     def __init__(self, config_object):
#         """
#         packing_slip should be a dict of this form
#         {
#             "number": "string" or None,
#             "published_datetime": aware_datetime or None,
#             "number_of_parcels": int or None,
#             "client": {
#                 "number": "string" or None,
#                 "adress": "string" or None,
#                 "company": "string" or None,
#             }
#         }
#         """
#         self.config = config_object
#         self.result = {
#             "packing_slip": {},
#             "annexes": [],
#         }
# 
#     @abstractmethod
#     def decode(self, response, payload):
#         """Transform a specific representation to python dict.
#         Args:
#             response : answer from the webservice
#             payload : data sent initially to the webservice
#         Need to increment the result attribute of the object, it does not need to return
#         anything
#         """
#         pass


# Path: roulier/carriers/laposte_fr/decoder.py
from datetime import datetime
from lxml import objectify
from ...codec import DecoderGetLabel
from ...codec import DecoderGetPackingSlip
import base64

            annexes.append(
                {"name": "cn23", "data": base64.b64encode(data), "type": "pdf"}
            )

        if rep.find("pdfUrl"):
            annexes.append({"name": "label", "data": rep.find("pdfUrl"), "type": "url"})

        parcel = {
            "id": 1,  # no multi parcel management for now.
            "reference": self._get_parcel_number(input_payload),
            "tracking": {
                # we need to force to real string because of those data can be reused
                # and cerberus won't accept an ElementString insteadof a string.
                "number": _get_text(rep, "parcelNumber"),
                "url": "",
                "partner": _get_text(rep, "parcelNumberPartner", ""),
            },
            "label": {
                "data": base64.b64encode(parts.get(label_cid)),
                "name": "label_1",
                "type": output_format,
            },
        }
        if hasattr(rep, "fields") and hasattr(rep.fields, "field"):
            for field in rep.fields.field:
                parcel["tracking"][_get_text(field, "key")] = _get_text(field, "value")
        self.result["parcels"].append(parcel)
        self.result["annexes"] += annexes



class LaposteFrDecoderGetPackingSlip(DecoderGetPackingSlip):