# Path: oscar_mws/api.py
# class MWSObject(OrderedDict):
# 
#     def get_list(self, name):
#         value = self.get(name)
#         if not value:
#             return []
#         if isinstance(value, (list, tuple)):
#             return value
#         return [value]
# 
#     def __getattribute__(self, name):
#         try:
#             value = self[name]
#         except KeyError:
#             value = super(MWSObject, self).__getattribute__(name)
#         return value
# 
# class MWSError(Exception):
#     """
#     Main MWS Exception class
#     """
#     # Allows quick access to the response object.
#     # Do not rely on this attribute, always check if its not None.
#     response = None
#     url = None
# 
# Path: oscar_mws/signals.py

# 
# Path: oscar_mws/connection.py
# def get_merchant_connection(merchant_id, api_name):
#     global _mws_connections
# 
#     if merchant_id in _mws_connections:
#         return _mws_connections[merchant_id].get_api_class(api_name)
# 
#     try:
#         connection = Connection(merchant_id)
#     except ImproperlyConfigured as exc:
#         logger.error(exc.message)
#         return None
# 
#     _mws_connections[merchant_id] = connection
#     return _mws_connections[merchant_id].get_api_class(api_name)


import logging
from collections import defaultdict
from dateutil import parser as du_parser
from django.db.models import get_model
from django.core.exceptions import ObjectDoesNotExist
from oscar.core.loading import get_class
from ..api import MWSObject, MWSError
from ..signals import mws_fulfillment_created
from ..connection import get_merchant_connection





logger = logging.getLogger('oscar_mws')

Partner = get_model('partner', 'Partner')
Product = get_model('catalogue', 'Product')
StockRecord = get_model('partner', 'StockRecord')

Line = get_model('order', 'Line')
ShippingEvent = get_model('order', 'ShippingEvent')
ShippingEventType = get_model('order', 'ShippingEventType')
ShippingEventQuantity = get_model('order', 'ShippingEventQuantity')
EventHandler = get_class('order.processing', 'EventHandler')

ShipmentPackage = get_model('oscar_mws', 'ShipmentPackage')
FulfillmentOrder = get_model('oscar_mws', 'FulfillmentOrder')
FulfillmentOrderLine = get_model('oscar_mws', 'FulfillmentOrderLine')

# Path: oscar_mws/api.py
# class MWSObject(OrderedDict):
# 
#     def get_list(self, name):
#         value = self.get(name)
#         if not value:
#             return []
#         if isinstance(value, (list, tuple)):
#             return value
#         return [value]
# 
#     def __getattribute__(self, name):
#         try:
#             value = self[name]
#         except KeyError:
#             value = super(MWSObject, self).__getattribute__(name)
#         return value
# 
# class MWSError(Exception):
#     """
#     Main MWS Exception class
#     """
#     # Allows quick access to the response object.
#     # Do not rely on this attribute, always check if its not None.
#     response = None
#     url = None
# 
# Path: oscar_mws/signals.py

# 
# Path: oscar_mws/connection.py
# def get_merchant_connection(merchant_id, api_name):
#     global _mws_connections
# 
#     if merchant_id in _mws_connections:
#         return _mws_connections[merchant_id].get_api_class(api_name)
# 
#     try:
#         connection = Connection(merchant_id)
#     except ImproperlyConfigured as exc:
#         logger.error(exc.message)
#         return None
# 
#     _mws_connections[merchant_id] = connection
#     return _mws_connections[merchant_id].get_api_class(api_name)


# Path: oscar_mws/fulfillment/gateway.py
import logging
from collections import defaultdict
from dateutil import parser as du_parser
from django.db.models import get_model
from django.core.exceptions import ObjectDoesNotExist
from oscar.core.loading import get_class
from ..api import MWSObject, MWSError
from ..signals import mws_fulfillment_created
from ..connection import get_merchant_connection






logger = logging.getLogger('oscar_mws')

Partner = get_model('partner', 'Partner')
Product = get_model('catalogue', 'Product')
StockRecord = get_model('partner', 'StockRecord')

Line = get_model('order', 'Line')
ShippingEvent = get_model('order', 'ShippingEvent')
ShippingEventType = get_model('order', 'ShippingEventType')
ShippingEventQuantity = get_model('order', 'ShippingEventQuantity')
EventHandler = get_class('order.processing', 'EventHandler')

ShipmentPackage = get_model('oscar_mws', 'ShipmentPackage')
FulfillmentOrder = get_model('oscar_mws', 'FulfillmentOrder')
FulfillmentOrderLine = get_model('oscar_mws', 'FulfillmentOrderLine')

FulfillmentShipment = get_model('oscar_mws', 'FulfillmentShipment')