# 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

    >>> node = find(response.element, node_name)

    """
    if "/" in node_name:
        node_name = "//ns:".join(node_name.split("/"))
    return element.find(
        ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
    )


def extract_text(element, node_name):
    """Extract the text from the selected node

    If no text is found, the empty string is returned.

    """
    inner_element = find(element, node_name)
    return inner_element.text if inner_element is not None else ""


def xml2dict(xml):
    """Returns a dictionary from the input XML

    :type xml: unicode
    :param xml: The XML

    :rtype: dict
    :returns: the dictionary correspoding to the input XML
    """

# 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


    >>> node = find(response.element, node_name)

    """
    if "/" in node_name:
        node_name = "//ns:".join(node_name.split("/"))
    return element.find(
        ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
    )


def extract_text(element, node_name):
    """Extract the text from the selected node

    If no text is found, the empty string is returned.

    """
    inner_element = find(element, node_name)
    return inner_element.text if inner_element is not None else ""


def xml2dict(xml):
    """Returns a dictionary from the input XML

    :type xml: unicode
    :param xml: The XML

    :rtype: dict
    :returns: the dictionary correspoding to the input XML
    """

    xmlepured = remove_namespace(to_unicode(xml))