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)
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)
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
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)
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.')
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)