<commit_before>#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program 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 Common Public License for
# full details.
#
import re
import urllib

class _Controller(object):

    modelName = None
    processSuburls = False
    urls = None
    modelRegex = '[^/]*'

    def __init__(self, parent, path, subhandlerParams=None):
        self.parent = parent
        if parent:
            self._url = '%s/%s' % (parent._url, path)
            self.root = parent.root
        else:
            self._url = ''
            self.root = self

        if self.modelName:
            self.baseMethods = dict(POST='create',
                                    GET='index')
            self.modelMethods = dict(POST='process',
                                GET='get',
                                PUT='update',
                                DELETE='destroy')
        else:
            self.baseMethods = dict(POST='process',
                                    GET='index',
                                    PUT='update',
                                    DELETE='destroy')


        if not subhandlerParams:
            subhandlerParams = []
        self.urls = self._initializeUrls(self.urls, subhandlerParams)

    def _initializeUrls(self, urls, subhandlerParams):
        if not urls:
            return {}
        newUrls = {}
        for key, handler in urls.items():
            if isinstance(handler, str):
                newUrls[key] = getattr(self, handler)
            elif isinstance(handler, dict):
                d = {}
                for method, handlerStr in handler.iteritems():
                    d[method] = getattr(self, handlerStr)
                newUrls[key] = d
            else:
                newUrls[key] = handler(self, key, *subhandlerParams)<commit_msg>Add destroy_all and update_all for updating/deleting list of objects<commit_after>#
# Copyright (c) 2008 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.rpath.com/permanent/licenses/CPL-1.0.
#
# This program 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 Common Public License for
# full details.
#
import re
import urllib

class _Controller(object):

    modelName = None
    processSuburls = False
    urls = None
    modelRegex = '[^/]*'

    def __init__(self, parent, path, subhandlerParams=None):
        self.parent = parent
        if parent:
            self._url = '%s/%s' % (parent._url, path)
            self.root = parent.root
        else:
            self._url = ''
            self.root = self

        if self.modelName:
            self.baseMethods = dict(POST='create',
                                    DELETE='destroy_all',
                                    PUT='update_all',
                                    GET='index')
            self.modelMethods = dict(POST='process',
                                GET='get',
                                PUT='update',
                                DELETE='destroy')
        else:
            self.baseMethods = dict(POST='process',
                                    GET='index',
                                    PUT='update',
                                    DELETE='destroy')


        if not subhandlerParams:
            subhandlerParams = []
        self.urls = self._initializeUrls(self.urls, subhandlerParams)

    def _initializeUrls(self, urls, subhandlerParams):
        if not urls:
            return {}
        newUrls = {}
        for key, handler in urls.items():
            if isinstance(handler, str):
                newUrls[key] = getattr(self, handler)
            elif isinstance(handler, dict):
                d = {}
                for method, handlerStr in handler.iteritems():
                    d[method] = getattr(self, handlerStr)
                newUrls[key] = d
            else:
                newUrls[key] = handler(self, key, *subhandlerParams)
{'fraction_non_alphanumeric': 0.08943436499466383, 'fraction_numerical': 0.003415154749199573, 'mean_word_length': 1.6325842696629214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2186874', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1159, 'n_words': 371}