# Path: papaye/schemas.py
# class APIMetadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = APIDescription(typ=NullableMapping(), missing=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)
# 
# class String(colander.String):
# 
#     def serialize(self, node, appstruct):
#         if appstruct is None:
#             appstruct = colander.null
#         return super().serialize(node, appstruct)
# 
# class APIReleaseFiles(colander.SequenceSchema):
#     release_files = ReleaseFile()
# 
# Path: papaye/schemas.py
# class APIOtherReleases(colander.SequenceSchema):
#     other_releases = APIOtherRelease()
# 
# class NullableMapping(colander.Mapping):
# 
#     def serialize(self, node, appstruct):
#         if appstruct is None or appstruct == {}:
#             return colander.null
#         return super(NullableMapping, self).serialize(node, appstruct)
# 
#     def deserialize(self, node, cstruct):
#         if cstruct == colander.null or cstruct == {}:
#             return None
#         return super(NullableMapping, self).deserialize(node, cstruct)


import colander
import hashlib
from papaye.schemas import APIMetadata, String, APIReleaseFiles
from papaye.schemas import APIOtherReleases, NullableMapping
                    schema.add(node)
                self._schema = schema
        return self._schema

    def serialize(self, obj):
        data = self.get_data(obj)
        cstruct = self.schema.serialize(data)
        return self.schema.deserialize(cstruct)

    def get_data(self, obj):
        return {key: getattr(obj, key) for key in self.fields.keys() if getattr(obj, key, None) is not None}


class PackageListSerializer(Serializer):
    name = colander.SchemaNode(colander.String())
    summary = colander.SchemaNode(String(), missing=None)

    def get_data(self, package):
        data = super().get_data(package)
        if package.metadata and 'summary' in package.metadata:
            data['summary'] = package.metadata.get('summary')
        else:
            data['summary'] = None
        return data


class ReleaseAPISerializer(Serializer):
    name = colander.SchemaNode(String())
    version = colander.SchemaNode(String())
    gravatar_hash = colander.SchemaNode(String(), missing=None)

# Path: papaye/schemas.py
# class APIMetadata(colander.MappingSchema):
#     version = colander.SchemaNode(String(), missing=None)
#     author = colander.SchemaNode(String(), missing=None)
#     author_email = colander.SchemaNode(String(), missing=None)
#     home_page = colander.SchemaNode(String(), missing=None)
#     keywords = colander.SchemaNode(Tags(), default=[])
#     license = colander.SchemaNode(String(), missing=None)
#     summary = colander.SchemaNode(String(), missing=None)
#     maintainer = colander.SchemaNode(String(), missing=None)
#     maintainer_email = colander.SchemaNode(String(), missing=None)
#     description = APIDescription(typ=NullableMapping(), missing=None)
#     platform = colander.SchemaNode(String(), missing=None)
#     classifiers = colander.SchemaNode(Classifiers(), default=[])
#     name = colander.SchemaNode(String(), missing=None)
# 
# class String(colander.String):
# 
#     def serialize(self, node, appstruct):
#         if appstruct is None:
#             appstruct = colander.null
#         return super().serialize(node, appstruct)
# 
# class APIReleaseFiles(colander.SequenceSchema):
#     release_files = ReleaseFile()
# 
# Path: papaye/schemas.py
# class APIOtherReleases(colander.SequenceSchema):
#     other_releases = APIOtherRelease()
# 
# class NullableMapping(colander.Mapping):
# 
#     def serialize(self, node, appstruct):
#         if appstruct is None or appstruct == {}:
#             return colander.null
#         return super(NullableMapping, self).serialize(node, appstruct)
# 
#     def deserialize(self, node, cstruct):
#         if cstruct == colander.null or cstruct == {}:
#             return None
#         return super(NullableMapping, self).deserialize(node, cstruct)


# Path: papaye/serializers.py
import colander
import hashlib
from papaye.schemas import APIMetadata, String, APIReleaseFiles
from papaye.schemas import APIOtherReleases, NullableMapping

                    schema.add(node)
                self._schema = schema
        return self._schema

    def serialize(self, obj):
        data = self.get_data(obj)
        cstruct = self.schema.serialize(data)
        return self.schema.deserialize(cstruct)

    def get_data(self, obj):
        return {key: getattr(obj, key) for key in self.fields.keys() if getattr(obj, key, None) is not None}


class PackageListSerializer(Serializer):
    name = colander.SchemaNode(colander.String())
    summary = colander.SchemaNode(String(), missing=None)

    def get_data(self, package):
        data = super().get_data(package)
        if package.metadata and 'summary' in package.metadata:
            data['summary'] = package.metadata.get('summary')
        else:
            data['summary'] = None
        return data


class ReleaseAPISerializer(Serializer):
    name = colander.SchemaNode(String())
    version = colander.SchemaNode(String())
    gravatar_hash = colander.SchemaNode(String(), missing=None)

    metadata = APIMetadata(typ=NullableMapping(), missing=None)