# Path: fnapy/compat.py
# def to_unicode(obj, encoding="utf-8"):
#     """
#     Convert ``obj`` to unicode"""
#     # unicode support
#     if isinstance(obj, str):
#         return obj
# 
#     # bytes support
#     if is_bytes(obj):
#         if hasattr(obj, "tobytes"):
#             return str(obj.tobytes(), encoding)
#         return str(obj, encoding)
# 
#     # string support
#     if isinstance(obj, basestring):
#         if hasattr(obj, "decode"):
#             # ignoring utf8 errors, as fnac send us malformed
#             # utf8 xml sometimes ...
#             return obj.decode(encoding, errors="ignore")
#         else:
#             return str(obj, encoding)
# 
#     return str(obj)
# 
# Path: fnapy/exceptions.py
# class FnapyUpdateOfferError(FnapyException):
#     """Raised when the update of an offer is not valid"""
# 
# class FnapyResponseError(FnapyException):
#     """Raised when the response is incorrect"""


import os
import re
import xmltodict
import requests
from codecs import open
from collections import OrderedDict
from xml.parsers.expat import ExpatError
from lxml import etree
from fnapy.config import *
from fnapy.compat import to_unicode
from fnapy.exceptions import FnapyUpdateOfferError, FnapyResponseError
    :returns: the text enclosed in the tag

    """
    xml = etree.XML(response.content)
    elements = xml.xpath("//ns:{}".format(tag_name), namespaces={"ns": XHTML_NAMESPACE})
    return elements[0].text if len(elements) else ""


def check_offer_data(offer_data):
    """Check the offer_data passed to update_offers is valid

    :type offer_data: dict
    :param offer_data: the parameters used to update an offer

    :returns: None

    offer_data must be a dictionary with at least 2 keys:
    - offer_reference (the sku)
    - any other parameter allowed by the service (price, quantity,
    product_state, ...)

    Raises a FnapyUpdateOfferError if the offer_data is not valid.

    """
    if not isinstance(offer_data, dict):
        msg = "The argument must be a dictionary."
        raise FnapyUpdateOfferError(msg)

    if "offer_reference" not in offer_data:
        msg = 'The dictionary must contain the key "offer_reference" (the sku)'

# Path: fnapy/compat.py
# def to_unicode(obj, encoding="utf-8"):
#     """
#     Convert ``obj`` to unicode"""
#     # unicode support
#     if isinstance(obj, str):
#         return obj
# 
#     # bytes support
#     if is_bytes(obj):
#         if hasattr(obj, "tobytes"):
#             return str(obj.tobytes(), encoding)
#         return str(obj, encoding)
# 
#     # string support
#     if isinstance(obj, basestring):
#         if hasattr(obj, "decode"):
#             # ignoring utf8 errors, as fnac send us malformed
#             # utf8 xml sometimes ...
#             return obj.decode(encoding, errors="ignore")
#         else:
#             return str(obj, encoding)
# 
#     return str(obj)
# 
# Path: fnapy/exceptions.py
# class FnapyUpdateOfferError(FnapyException):
#     """Raised when the update of an offer is not valid"""
# 
# class FnapyResponseError(FnapyException):
#     """Raised when the response is incorrect"""


# Path: fnapy/utils.py
import os
import re
import xmltodict
import requests
from codecs import open
from collections import OrderedDict
from xml.parsers.expat import ExpatError
from lxml import etree
from fnapy.config import *
from fnapy.compat import to_unicode
from fnapy.exceptions import FnapyUpdateOfferError, FnapyResponseError

    :returns: the text enclosed in the tag

    """
    xml = etree.XML(response.content)
    elements = xml.xpath("//ns:{}".format(tag_name), namespaces={"ns": XHTML_NAMESPACE})
    return elements[0].text if len(elements) else ""


def check_offer_data(offer_data):
    """Check the offer_data passed to update_offers is valid

    :type offer_data: dict
    :param offer_data: the parameters used to update an offer

    :returns: None

    offer_data must be a dictionary with at least 2 keys:
    - offer_reference (the sku)
    - any other parameter allowed by the service (price, quantity,
    product_state, ...)

    Raises a FnapyUpdateOfferError if the offer_data is not valid.

    """
    if not isinstance(offer_data, dict):
        msg = "The argument must be a dictionary."
        raise FnapyUpdateOfferError(msg)

    if "offer_reference" not in offer_data:
        msg = 'The dictionary must contain the key "offer_reference" (the sku)'

        raise FnapyUpdateOfferError(msg)