# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/i18n.py
# def deform_translator(term):
# def locale_negotiator(request):


import colander
from deform.widget import TextAreaWidget, TextInputWidget
from yithlibraryserver.compat import string_types
from yithlibraryserver.i18n import TranslationString as _
# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.




class AuthorizedOriginsNode(colander.SchemaNode):
    """Converts a node of type string into and from a list of strings"""

    def serialize(self, appstruct=colander.null):
        if not appstruct is colander.null and isinstance(appstruct, list):
            appstruct = '\n'.join(appstruct)
        return super(AuthorizedOriginsNode, self).serialize(appstruct)

    def deserialize(self, cstruct=colander.null):
        result = super(AuthorizedOriginsNode, self).deserialize(cstruct)
        if not result is colander.null and isinstance(result, string_types):
            result = [item.strip() for item in result.split('\n')
                      if item.strip()]

        return result


class ApplicationSchema(colander.MappingSchema):


# Path: yithlibraryserver/compat.py
# PY3 = sys.version_info[0] == 3
#     def encode_header(obj):  # pragma: no cover
#     def encode_header(obj):  # pragma: no cover
# 
# Path: yithlibraryserver/i18n.py
# def deform_translator(term):
# def locale_negotiator(request):


# Path: yithlibraryserver/oauth2/schemas.py
import colander
from deform.widget import TextAreaWidget, TextInputWidget
from yithlibraryserver.compat import string_types
from yithlibraryserver.i18n import TranslationString as _

# Yith Library Server is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Yith Library Server.  If not, see <http://www.gnu.org/licenses/>.




class AuthorizedOriginsNode(colander.SchemaNode):
    """Converts a node of type string into and from a list of strings"""

    def serialize(self, appstruct=colander.null):
        if not appstruct is colander.null and isinstance(appstruct, list):
            appstruct = '\n'.join(appstruct)
        return super(AuthorizedOriginsNode, self).serialize(appstruct)

    def deserialize(self, cstruct=colander.null):
        result = super(AuthorizedOriginsNode, self).deserialize(cstruct)
        if not result is colander.null and isinstance(result, string_types):
            result = [item.strip() for item in result.split('\n')
                      if item.strip()]

        return result


class ApplicationSchema(colander.MappingSchema):


    name = colander.SchemaNode(colander.String(), title=_('Name'))