# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/exceptions.py
# class Veto(Exception):
#     """ May be raised when an attempt is made to do something that the CMS doesn't allow,
#     such as adding an object to a folder with a name that's already in use.
#     Higher level code (such as views) may want to catch these Veto exceptions
#     and present them to end users in a friendly manner.
#     """
#     def __init__(self, msg):
#         Exception.__init__(self, msg)


from cms import dbutil
from cms.exceptions import Veto
import string

    # Avoid conflicting with view names.
    RESERVED_NAMES = (
        'add',
        'delete',
        'contents',
        'rename',
        'edit',
        'workflow_transition',
        'history',
        'comment',
        'local_roles',
        'search',
        'object_view',
    )

    ALLOWED_NAME_CHARACTERS = string.letters + string.digits + ".-_ "

    def veto_child_name(self, name, unique=True):
        if name is not None: name = name.strip()
        if not name: return "Name may not be blank."
        if name in self.RESERVED_NAMES: return "\"%s\" is a reserved name." % name
        for ch in name:
            if ch not in self.ALLOWED_NAME_CHARACTERS:
                return "The character \"%s\" is not allowed in names." % ch
        if unique and self.has_child(name): return "The name \"%s\" is already in use." % name
        return None

    def add_child(self, name, child):
        error = self.veto_add_child(name, child)

# Path: cms/dbutil.py
# def get_mongodb(request):
# def get_collection(request, name):
# def get_gridfs(request, collection='fs'):
# def encode_keys(d):
# def get_es_conn(request):
# def get_es_index_name(request):
# def serve_gridfs_file(file):
# def serve_gridfs_file_for_id(request, id, collection='fs'):
# 
# Path: cms/exceptions.py
# class Veto(Exception):
#     """ May be raised when an attempt is made to do something that the CMS doesn't allow,
#     such as adding an object to a folder with a name that's already in use.
#     Higher level code (such as views) may want to catch these Veto exceptions
#     and present them to end users in a friendly manner.
#     """
#     def __init__(self, msg):
#         Exception.__init__(self, msg)


# Path: cms/resources/collection.py
from cms import dbutil
from cms.exceptions import Veto
import string


    # Avoid conflicting with view names.
    RESERVED_NAMES = (
        'add',
        'delete',
        'contents',
        'rename',
        'edit',
        'workflow_transition',
        'history',
        'comment',
        'local_roles',
        'search',
        'object_view',
    )

    ALLOWED_NAME_CHARACTERS = string.letters + string.digits + ".-_ "

    def veto_child_name(self, name, unique=True):
        if name is not None: name = name.strip()
        if not name: return "Name may not be blank."
        if name in self.RESERVED_NAMES: return "\"%s\" is a reserved name." % name
        for ch in name:
            if ch not in self.ALLOWED_NAME_CHARACTERS:
                return "The character \"%s\" is not allowed in names." % ch
        if unique and self.has_child(name): return "The name \"%s\" is already in use." % name
        return None

    def add_child(self, name, child):
        error = self.veto_add_child(name, child)

        if error: raise Veto(error)