# Path: netvisor/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: netvisor/schemas/fields.py
# class Decimal(fields.Decimal):
#     def _deserialize(self, value, attr, data):
#         return super(Decimal, self)._deserialize(
#             value.replace(',', '.'),
#             attr,
#             data
#         )
# 
#     def serialize(self, attr, obj, accessor=None):
#         value = super(Decimal, self).serialize(attr, obj, accessor)
#         if value is missing:
#             return value
#         return str(value).replace('.', ',')


from marshmallow import (
    MarshalResult,
    Schema,
    ValidationError,
    fields,
    pre_dump,
    pre_load
)
from .._compat import string_types
from .fields import Decimal
# -*- coding: utf-8 -*-
"""
    netvisor.schemas.common
    ~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: (c) 2013-2016 by Fast Monkeys Oy.
    :license: MIT, see LICENSE for more details.
"""



class RejectUnknownFieldsSchema(Schema):
    @pre_dump
    def check_unknown_fields(self, data):
        field_names = set()
        for field_name, field in self.fields.items():
            attribute = getattr(field, 'attribute', None)
            field_names.add(field_name if attribute is None else attribute)
        for k in data:
            if k not in field_names:
                raise ValidationError("Unknown field name: '{}'".format(k))


class FlattenElementSchema(Schema):
    @pre_load
    def pre_load(self, data):

# Path: netvisor/_compat.py
# PY2 = sys.version_info[0] == 2
# 
# Path: netvisor/schemas/fields.py
# class Decimal(fields.Decimal):
#     def _deserialize(self, value, attr, data):
#         return super(Decimal, self)._deserialize(
#             value.replace(',', '.'),
#             attr,
#             data
#         )
# 
#     def serialize(self, attr, obj, accessor=None):
#         value = super(Decimal, self).serialize(attr, obj, accessor)
#         if value is missing:
#             return value
#         return str(value).replace('.', ',')


# Path: netvisor/schemas/common.py
from marshmallow import (
    MarshalResult,
    Schema,
    ValidationError,
    fields,
    pre_dump,
    pre_load
)
from .._compat import string_types
from .fields import Decimal

# -*- coding: utf-8 -*-
"""
    netvisor.schemas.common
    ~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: (c) 2013-2016 by Fast Monkeys Oy.
    :license: MIT, see LICENSE for more details.
"""



class RejectUnknownFieldsSchema(Schema):
    @pre_dump
    def check_unknown_fields(self, data):
        field_names = set()
        for field_name, field in self.fields.items():
            attribute = getattr(field, 'attribute', None)
            field_names.add(field_name if attribute is None else attribute)
        for k in data:
            if k not in field_names:
                raise ValidationError("Unknown field name: '{}'".format(k))


class FlattenElementSchema(Schema):
    @pre_load
    def pre_load(self, data):

        if isinstance(data, string_types):