<commit_before>#
# Paasmaker - Platform as a Service
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import unittest
import uuid
import logging
import json

import paasmaker
from paasmaker.common.controller import BaseController, BaseControllerTest
from paasmaker.common.core import constants

import colander
import tornado
import tornado.testing
import sqlalchemy.exc

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

class WorkspaceSchema(colander.MappingSchema):
	name = colander.SchemaNode(colander.String(),
		title="Workspace Name",
		description="The name of this workspace.",
		validator=colander.Length(min=2))
	# TODO: Put proper validation on this.
	stub = colander.SchemaNode(colander.String(),
		title="Workspace stub",
		description="A short, URL friendly name for the workspace.")
	tags = colander.SchemaNode(colander.Mapping(unknown='preserve'),
		title="Workspace Tags",
		description="A set of tags for this workspace.",
		missing={},
		default={})
	serialised_tags = colander.SchemaNode(colander.String(),<commit_msg>Tightened up server side validation when creating or editing a workspace.<commit_after>#
# Paasmaker - Platform as a Service
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

import unittest
import uuid
import logging
import json
import re

import paasmaker
from paasmaker.common.controller import BaseController, BaseControllerTest
from paasmaker.common.core import constants

import colander
import tornado
import tornado.testing
import sqlalchemy.exc

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

VALID_IDENTIFIER = re.compile(r"^[-A-Za-z0-9.]{1,}$")

class WorkspaceSchema(colander.MappingSchema):
	name = colander.SchemaNode(colander.String(),
		title="Workspace Name",
		description="The name of this workspace.",
		validator=colander.Length(min=2))
	# TODO: Put proper validation on this.
	stub = colander.SchemaNode(colander.String(),
		title="Workspace stub",
		description="A short, URL friendly name for the workspace.",
		validator=colander.Regex(VALID_IDENTIFIER, "Workspace stub must match " + VALID_IDENTIFIER.pattern))
	tags = colander.SchemaNode(colander.Mapping(unknown='preserve'),
		title="Workspace Tags",
		description="A set of tags for this workspace.",
		missing={},
		default={})
	serialised_tags = colander.SchemaNode(colander.String(),
{'fraction_non_alphanumeric': 0.10209424083769633, 'fraction_numerical': 0.0048616305160807775, 'mean_word_length': 5.430288461538462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4430335', 'n_tokens_mistral': 797, 'n_tokens_neox': 774, 'n_words': 249}