# Path: rakuten_ws/compat.py
#     def iteritems(d):
#     def is_bytes(x):
#     def callable(obj):
#     def iteritems(d):
#     def is_bytes(x):
# def to_unicode(obj, encoding='utf-8'):


import re
import requests
from collections import OrderedDict, MutableMapping
from shutil import copyfileobj
from mimetypes import guess_type
from io import BytesIO, open
from xmljson import Parker
from lxml.etree import Element, fromstring, tostring
from .compat import iteritems, to_unicode, is_py2, str, urlparse, pathname2url
                    unflat_list = []
                    for key in sorted(unflat_dict.keys()):
                        unflat_list.append(unflat_dict[key])
                    new_value = unflat_list
                else:
                    new_value = unflat_dict
                unflat_list_dict[k] = new_value
            else:
                unflat_list_dict[k] = v
        return unflat_list_dict

    return unflatten_list_dict(unflat_dict)


def load_file(url, session=None, timeout=None):
    """Load the content from the given URL and return it as a `BytesIO`"""
    scheme = urlparse(url).scheme
    if scheme in ('http', 'https'):
        if session is None:
            session = requests.Session()
        response = session.get(url, timeout=timeout)
        response.raise_for_status()
        return BytesIO(response.content), response.headers['Content-Type']
    elif scheme in ('', 'file'):
        if url.startswith('file://'):
            url = url[7:]
        fileobj = BytesIO()
        with open(url, 'rb') as fd:
            copyfileobj(fd, fileobj)
        fileobj.seek(0)

# Path: rakuten_ws/compat.py
#     def iteritems(d):
#     def is_bytes(x):
#     def callable(obj):
#     def iteritems(d):
#     def is_bytes(x):
# def to_unicode(obj, encoding='utf-8'):


# Path: rakuten_ws/utils.py
import re
import requests
from collections import OrderedDict, MutableMapping
from shutil import copyfileobj
from mimetypes import guess_type
from io import BytesIO, open
from xmljson import Parker
from lxml.etree import Element, fromstring, tostring
from .compat import iteritems, to_unicode, is_py2, str, urlparse, pathname2url

                    unflat_list = []
                    for key in sorted(unflat_dict.keys()):
                        unflat_list.append(unflat_dict[key])
                    new_value = unflat_list
                else:
                    new_value = unflat_dict
                unflat_list_dict[k] = new_value
            else:
                unflat_list_dict[k] = v
        return unflat_list_dict

    return unflatten_list_dict(unflat_dict)


def load_file(url, session=None, timeout=None):
    """Load the content from the given URL and return it as a `BytesIO`"""
    scheme = urlparse(url).scheme
    if scheme in ('http', 'https'):
        if session is None:
            session = requests.Session()
        response = session.get(url, timeout=timeout)
        response.raise_for_status()
        return BytesIO(response.content), response.headers['Content-Type']
    elif scheme in ('', 'file'):
        if url.startswith('file://'):
            url = url[7:]
        fileobj = BytesIO()
        with open(url, 'rb') as fd:
            copyfileobj(fd, fileobj)
        fileobj.seek(0)

        return fileobj, guess_type(pathname2url(url))[0]