# 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/exception.py
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)
# 
# Path: roulier/carriers/gls_fr/glsbox/encoder.py
# def merge_dict(mydict):
#     mydict.update(AUTH_MAPPING)
#     mydict.update(ACCOUNT_MAPPING)
#     mydict.update(DELIVERY_MAPPING)
#     mydict.update(PARCEL_MAPPING)


import base64
import logging
import os
import re
from io import BytesIO
from string import Template
from roulier.codec import DecoderGetLabel
from roulier.exception import CarrierError
from .encoder import merge_dict
        if len(components) == 3:
            # Not sure we always have 3 components
            value = components[2]
        if code == "E000":
            return False
        ctx_except = "Web service error : code: %s ; tag: %s ; value: %s" % (
            code,
            tag,
            value,
        )
        if code == "E999":
            exception = (
                "Unibox server (web service) is not responding.\n"
                "Check network connection, webservice accessibility."
            )
        elif tag == "T330":
            zip_code = ""
            if data["T330"]:
                zip_code = data["T330"]
            exception = (
                "Postal code '%s' is wrong (relative to the "
                "destination country)" % zip_code
            )
        elif tag == "T100":
            cnty_code = ""
            if data["T100"]:
                cnty_code = data["T100"]
            exception = "Country code '%s' is wrong" % cnty_code
        else:
            info = {}

# 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/exception.py
# class CarrierError(Exception):
#     """Error from WS.
# 
#     Use this class in your application to manage
#     exception with the carrier WS
#     """
# 
#     def __init__(self, response, msg=None):
#         if msg is None:
#             msg = "An error occured with WS"
#         super(CarrierError, self).__init__(msg)
#         self.response = response
#         if self.response:
#             if hasattr(self.response, "text"):
#                 log.debug(response.text)
#             else:
#                 log.debug(response)
# 
# Path: roulier/carriers/gls_fr/glsbox/encoder.py
# def merge_dict(mydict):
#     mydict.update(AUTH_MAPPING)
#     mydict.update(ACCOUNT_MAPPING)
#     mydict.update(DELIVERY_MAPPING)
#     mydict.update(PARCEL_MAPPING)


# Path: roulier/carriers/gls_fr/glsbox/decoder.py
import base64
import logging
import os
import re
from io import BytesIO
from string import Template
from roulier.codec import DecoderGetLabel
from roulier.exception import CarrierError
from .encoder import merge_dict

        if len(components) == 3:
            # Not sure we always have 3 components
            value = components[2]
        if code == "E000":
            return False
        ctx_except = "Web service error : code: %s ; tag: %s ; value: %s" % (
            code,
            tag,
            value,
        )
        if code == "E999":
            exception = (
                "Unibox server (web service) is not responding.\n"
                "Check network connection, webservice accessibility."
            )
        elif tag == "T330":
            zip_code = ""
            if data["T330"]:
                zip_code = data["T330"]
            exception = (
                "Postal code '%s' is wrong (relative to the "
                "destination country)" % zip_code
            )
        elif tag == "T100":
            cnty_code = ""
            if data["T100"]:
                cnty_code = data["T100"]
            exception = "Country code '%s' is wrong" % cnty_code
        else:
            info = {}

            merge_dict(info)