# Path: prestans/exception.py
# class Base(Exception):
# class UnsupportedVocabularyError(Base):
# class UnsupportedContentTypeError(Base):
# class ValidationError(Base):
# class HandlerException(Base):
# class RequestException(HandlerException):
# class ResponseException(HandlerException):
# class UnimplementedVerbError(RequestException):
# class NoEndpointError(RequestException):
# class AuthenticationError(RequestException):
# class AuthorizationError(RequestException):
# class SerializationFailedError(RequestException):
# class DeSerializationFailedError(RequestException):
# class AttributeFilterDiffers(RequestException):
# class InconsistentPersistentDataError(Base):
# class DataValidationException(Base):
# class RequiredAttributeError(DataValidationException):
# class ParseFailedError(DataValidationException):
# class LessThanMinimumError(DataValidationException):
# class MoreThanMaximumError(DataValidationException):
# class InvalidChoiceError(DataValidationException):
# class MinimumLengthError(DataValidationException):
# class MaximumLengthError(DataValidationException):
# class InvalidTypeError(DataValidationException):
# class MissingParameterError(DataValidationException):
# class InvalidFormatError(DataValidationException):
# class InvalidMetaValueError(DataValidationException):
# class UnregisteredAdapterError(DataValidationException):
# class ServiceUnavailable(ResponseException):
# class BadRequest(ResponseException):
# class Conflict(ResponseException):
# class NotFound(ResponseException):
# class Unauthorized(ResponseException):
# class MovedPermanently(ResponseException):
# class Redirect(ResponseException):
# class TemporaryRedirect(Redirect):
# class PermanentRedirect(Redirect):
# class PaymentRequired(ResponseException):
# class Forbidden(ResponseException):
# class InternalServerError(ResponseException):
#     def __init__(self, http_status, message):
#     def http_status(self):
#     def http_status(self, value):
#     def stack_trace(self):
#     def push_trace(self, trace_object):
#     def message(self):
#     def __str__(self):
#     def __init__(self, accept_header, supported_types):
#     def __init__(self, requested_mime_type, content_type):
#     def __init__(self, message, attribute_name, value, blueprint):
#     def append_validation_trace(self, blueprint):
#     def __str__(self):
#     def __init__(self, code, message):
#     def request(self):
#     def request(self, value):
#     def log_message(self):
#     def __str__(self):
#     def __init__(self, code, message):
#     def __init__(self, code, message, response_model=None):
#     def response_model(self):
#     def __init__(self, verb_name):
#     def __init__(self):
#     def __init__(self, message=None):
#     def __init__(self, role_name):
#     def __init__(self, format):
#     def __init__(self, format):
#     def __init__(self, attribute_list):
#     def __init__(self, attribute_name, exception_message):
#     def __str__(self):
#     def __init__(self, message):
#     def __init__(self):
#     def __init__(self, message="Parser Failed"):
#     def __init__(self, value, allowed_min):
#     def __init__(self, value, allowed_max):
#     def __init__(self, value, allowed_choices):
#     def __init__(self, value, minimum):
#     def __init__(self, value, maximum):
#     def __init__(self, value, type_name):
#     def __init__(self):
#     def __init__(self, value):
#     def __init__(self):
#     def __init__(self, model_name):
#     def __init__(self, message="Service Unavailable", response_model=None):
#     def __init__(self, message="Bad Request", response_model=None):
#     def __init__(self, message="Conflict", response_model=None):
#     def __init__(self, message="Not Found", response_model=None):
#     def __init__(self, message="Unauthorized", response_model=None):
#     def __init__(self, message="Moved Permanently", response_model=None):
#     def __init__(self, code, url):
#     def url(self):
#     def __init__(self, url):
#     def __init__(self, url):
#     def __init__(self, message="Payment Required", response_model=None):
#     def __init__(self, message="Forbidden", response_model=None):
#     def __init__(self, message="Internal Server Error", response_model=None):
# 
# Path: prestans/types/base.py
# class DataStructure(DataType):
#     """
#     Wrappers on Python types generally represented as structures e.g DateTime
# 
#     as_serializable methods signature for %DataStructure is different to that of DataCollection
#     it requires a value to be passed in, this is because the python type of structures is
#     difference to what gets serialized.
# 
#     E.g DateTime serializes itself as a ISO string
#     """
# 
#     def blueprint(self):
#         raise NotImplementedError
# 
#     def validate(self, value):
#         raise NotImplementedError
# 
#     def as_serializable(self, value):
#         raise NotImplementedError


import base64
        import uuid
from prestans import exception
from prestans.types import DataStructure
    def mime_type(self):
        return self._mime_type

    @property
    def file_contents(self):
        return self._file_contents

    @property
    def base64_contents(self):
        return base64.b64encode(self._file_contents)

    def validate(self, value):

        _validated_value = self.__class__()

        if self._required and value is None:
            raise exception.RequiredAttributeError()

        if self._required is False and value is None:
            return value

        try:
            data_url, delimiter, base64_content = value.partition(',')
            _validated_value._mime_type = data_url.replace(';base64', '').replace('data:', '')
            _validated_value._file_contents = base64.b64decode(base64_content)
        except Exception as exp:
            raise exception.ParseFailedError("data url file encoding failed %s" % exp)

        if self._allowed_mime_types and len(self._allowed_mime_types) > 0 \
           and _validated_value._mime_type not in self._allowed_mime_types:

# Path: prestans/exception.py
# class Base(Exception):
# class UnsupportedVocabularyError(Base):
# class UnsupportedContentTypeError(Base):
# class ValidationError(Base):
# class HandlerException(Base):
# class RequestException(HandlerException):
# class ResponseException(HandlerException):
# class UnimplementedVerbError(RequestException):
# class NoEndpointError(RequestException):
# class AuthenticationError(RequestException):
# class AuthorizationError(RequestException):
# class SerializationFailedError(RequestException):
# class DeSerializationFailedError(RequestException):
# class AttributeFilterDiffers(RequestException):
# class InconsistentPersistentDataError(Base):
# class DataValidationException(Base):
# class RequiredAttributeError(DataValidationException):
# class ParseFailedError(DataValidationException):
# class LessThanMinimumError(DataValidationException):
# class MoreThanMaximumError(DataValidationException):
# class InvalidChoiceError(DataValidationException):
# class MinimumLengthError(DataValidationException):
# class MaximumLengthError(DataValidationException):
# class InvalidTypeError(DataValidationException):
# class MissingParameterError(DataValidationException):
# class InvalidFormatError(DataValidationException):
# class InvalidMetaValueError(DataValidationException):
# class UnregisteredAdapterError(DataValidationException):
# class ServiceUnavailable(ResponseException):
# class BadRequest(ResponseException):
# class Conflict(ResponseException):
# class NotFound(ResponseException):
# class Unauthorized(ResponseException):
# class MovedPermanently(ResponseException):
# class Redirect(ResponseException):
# class TemporaryRedirect(Redirect):
# class PermanentRedirect(Redirect):
# class PaymentRequired(ResponseException):
# class Forbidden(ResponseException):
# class InternalServerError(ResponseException):
#     def __init__(self, http_status, message):
#     def http_status(self):
#     def http_status(self, value):
#     def stack_trace(self):
#     def push_trace(self, trace_object):
#     def message(self):
#     def __str__(self):
#     def __init__(self, accept_header, supported_types):
#     def __init__(self, requested_mime_type, content_type):
#     def __init__(self, message, attribute_name, value, blueprint):
#     def append_validation_trace(self, blueprint):
#     def __str__(self):
#     def __init__(self, code, message):
#     def request(self):
#     def request(self, value):
#     def log_message(self):
#     def __str__(self):
#     def __init__(self, code, message):
#     def __init__(self, code, message, response_model=None):
#     def response_model(self):
#     def __init__(self, verb_name):
#     def __init__(self):
#     def __init__(self, message=None):
#     def __init__(self, role_name):
#     def __init__(self, format):
#     def __init__(self, format):
#     def __init__(self, attribute_list):
#     def __init__(self, attribute_name, exception_message):
#     def __str__(self):
#     def __init__(self, message):
#     def __init__(self):
#     def __init__(self, message="Parser Failed"):
#     def __init__(self, value, allowed_min):
#     def __init__(self, value, allowed_max):
#     def __init__(self, value, allowed_choices):
#     def __init__(self, value, minimum):
#     def __init__(self, value, maximum):
#     def __init__(self, value, type_name):
#     def __init__(self):
#     def __init__(self, value):
#     def __init__(self):
#     def __init__(self, model_name):
#     def __init__(self, message="Service Unavailable", response_model=None):
#     def __init__(self, message="Bad Request", response_model=None):
#     def __init__(self, message="Conflict", response_model=None):
#     def __init__(self, message="Not Found", response_model=None):
#     def __init__(self, message="Unauthorized", response_model=None):
#     def __init__(self, message="Moved Permanently", response_model=None):
#     def __init__(self, code, url):
#     def url(self):
#     def __init__(self, url):
#     def __init__(self, url):
#     def __init__(self, message="Payment Required", response_model=None):
#     def __init__(self, message="Forbidden", response_model=None):
#     def __init__(self, message="Internal Server Error", response_model=None):
# 
# Path: prestans/types/base.py
# class DataStructure(DataType):
#     """
#     Wrappers on Python types generally represented as structures e.g DateTime
# 
#     as_serializable methods signature for %DataStructure is different to that of DataCollection
#     it requires a value to be passed in, this is because the python type of structures is
#     difference to what gets serialized.
# 
#     E.g DateTime serializes itself as a ISO string
#     """
# 
#     def blueprint(self):
#         raise NotImplementedError
# 
#     def validate(self, value):
#         raise NotImplementedError
# 
#     def as_serializable(self, value):
#         raise NotImplementedError


# Path: prestans/types/data_url_file.py
import base64
        import uuid
from prestans import exception
from prestans.types import DataStructure

    def mime_type(self):
        return self._mime_type

    @property
    def file_contents(self):
        return self._file_contents

    @property
    def base64_contents(self):
        return base64.b64encode(self._file_contents)

    def validate(self, value):

        _validated_value = self.__class__()

        if self._required and value is None:
            raise exception.RequiredAttributeError()

        if self._required is False and value is None:
            return value

        try:
            data_url, delimiter, base64_content = value.partition(',')
            _validated_value._mime_type = data_url.replace(';base64', '').replace('data:', '')
            _validated_value._file_contents = base64.b64decode(base64_content)
        except Exception as exp:
            raise exception.ParseFailedError("data url file encoding failed %s" % exp)

        if self._allowed_mime_types and len(self._allowed_mime_types) > 0 \
           and _validated_value._mime_type not in self._allowed_mime_types:

            raise exception.InvalidChoiceError(_validated_value._mime_type, self._allowed_mime_types)