示例#1
0
    def _call_consumer(self, optname, optvalue, specargs):
        for constraint, func in self._get_consumers():
            match = constraint.match(optname)
            if match:
                return func(match, optvalue, specargs)

        raise ParsingError('The option "%s" is not valid.' % optname)
示例#2
0
    def _convert_transition_line(self, line):
        xpr = re.compile(r'([^\(]*?) ?\(([^=]*?) ?=> ?([^\(]*)\)')
        match = xpr.match(line)
        if not match:
            raise ParsingError(
                'Transition line has an invalid format: "%s"' % line)

        title, src_status_title, dest_status_title = match.groups()
        return Transition(title=title,
                          src_status_title=src_status_title,
                          dest_status_title=dest_status_title)
示例#3
0
    def _convert_role_mapping(self, match, value, specargs):
        lines = map(str.strip, value.strip().split('\n'))
        xpr = re.compile(r'^([^=]*?) ?=> ?(.*)$')
        mapping = specargs['role_mapping'] = {}

        for line in lines:
            match = xpr.match(line)
            if not match:
                raise ParsingError('Invalid format in role mapping: "%s"' % (
                        line))

            customer_role, plone_role = match.groups()
            mapping[customer_role.lower()] = plone_role
示例#4
0
def convert_statement(statement):
    result = _convert_worklist_statement(statement)
    if result:
        return WORKLIST_STATEMENT, result

    result = _convert_role_inheritance_statement(statement)
    if result:
        return ROLE_INHERITANCE_STATEMENT, result

    result = _convert_permission_statement(statement)
    if result:
        return PERMISSION_STATEMENT, result

    raise ParsingError('Unkown statement format: "%s"' % statement)
示例#5
0
    def _convert_general_statements(self, match, value, specargs):
        statements = specargs['generals'] = []
        role_inheritance = specargs['role_inheritance'] = []

        lines = map(str.strip, value.strip().split('\n'))
        for line in lines:
            type_, item = convert_statement(line)
            if type_ == PERMISSION_STATEMENT:
                statements.append(item)

            elif type_ == ROLE_INHERITANCE_STATEMENT:
                role_inheritance.append(item)

            elif type_ == WORKLIST_STATEMENT:
                raise ParsingError('Worklist statements are not allowed'
                                   ' in the "General" section.')
示例#6
0
    def _convert(self):
        """Convert the configparser `self._config` into a ISpecification
        object (`self._spec`).
        """

        if len(self._config.sections()) != 1:
            raise ParsingError(
                'Exactly one ini-style section is required,'
                ' containing the workflow title.')

        sectionname = self._config.sections()[0]
        specargs = {'title': sectionname,
                    'states': {}}

        for name, value in self._config.items(sectionname):
            self._call_consumer(name, value, specargs)

        self._spec = Specification(**specargs)