# Path: netvisor/exc.py
# class NetvisorError(Exception):
# 
#     @staticmethod
#     def from_status(status):
#         code, message = status.split(' :: ', 1)
#         error_cls = {
#             'AUTHENTICATION_FAILED': AuthenticationFailed,
#             'INVALID_DATA': InvalidData,
#             'INVALID_DATA_SIZE': InvalidDataSize,
#             'DUPLICATE_DATA': DuplicateData,
#             'REQUEST_NOT_UNIQUE': RequestNotUnique,
#             'PERIOD_LOCK': PeriodLock,
#             'SERVICE_ACCESS_ERROR': ServiceAccessError,
#             'SYSTEM_MAINTANANCE': SystemMaintenance,
#             'TECHNICAL_ERROR': TechnicalError
#         }[code]
#         return error_cls(message)


import inflection
import xmltodict
from ..exc import NetvisorError



class Response(object):
    def __init__(self, response):
        self.response = response
        self.parse()
        self.raise_for_failure()
        self.deserialize()

    def parse(self):
        self.raw_data = xmltodict.parse(
            self.response.text,
            postprocessor=self.postprocess,
            dict_constructor=dict
        )

    def postprocess(self, path, key, data):
        return inflection.underscore(key), data

    def deserialize(self):
        if self.schema_cls is not None:
            schema = self.schema_cls(strict=True)
            result = schema.load(self.raw_data['root'][self.tag_name])
            self.data = result.data
        else:
            self.data = None

    def raise_for_failure(self):
        if not self.is_ok:

# Path: netvisor/exc.py
# class NetvisorError(Exception):
# 
#     @staticmethod
#     def from_status(status):
#         code, message = status.split(' :: ', 1)
#         error_cls = {
#             'AUTHENTICATION_FAILED': AuthenticationFailed,
#             'INVALID_DATA': InvalidData,
#             'INVALID_DATA_SIZE': InvalidDataSize,
#             'DUPLICATE_DATA': DuplicateData,
#             'REQUEST_NOT_UNIQUE': RequestNotUnique,
#             'PERIOD_LOCK': PeriodLock,
#             'SERVICE_ACCESS_ERROR': ServiceAccessError,
#             'SYSTEM_MAINTANANCE': SystemMaintenance,
#             'TECHNICAL_ERROR': TechnicalError
#         }[code]
#         return error_cls(message)


# Path: netvisor/responses/base.py
import inflection
import xmltodict
from ..exc import NetvisorError




class Response(object):
    def __init__(self, response):
        self.response = response
        self.parse()
        self.raise_for_failure()
        self.deserialize()

    def parse(self):
        self.raw_data = xmltodict.parse(
            self.response.text,
            postprocessor=self.postprocess,
            dict_constructor=dict
        )

    def postprocess(self, path, key, data):
        return inflection.underscore(key), data

    def deserialize(self):
        if self.schema_cls is not None:
            schema = self.schema_cls(strict=True)
            result = schema.load(self.raw_data['root'][self.tag_name])
            self.data = result.data
        else:
            self.data = None

    def raise_for_failure(self):
        if not self.is_ok:

            raise NetvisorError.from_status(self.statuses[1])