def _processReusedPy(self, specnames, specdict, specials=[], dovars=True, dopars=True, doinps=True, illegal=[]): """Process reused subexpression terms for Python code.""" reused, specupdated, new_protected, order = _processReused( specnames, specdict, self.fspec.reuseterms, _indentstr) self.fspec._protected_reusenames = new_protected # symbols to parse are at indices 2 and 4 of 'reused' dictionary reusedParsed = self._parseReusedTermsPy(reused, [2, 4], specials=specials, dovars=dovars, dopars=dopars, doinps=doinps, illegal=illegal) reusedefs = {}.fromkeys(new_protected) for _, deflist in reusedParsed.items(): for d in deflist: reusedefs[d[2]] = d return (concatStrDict(reusedefs, intersect(order, reusedefs.keys())), specupdated)
def _processReusedC(self, specnames, specdict): """Process reused subexpression terms for C code.""" if self.fspec.auxfns: def addParToCall(s): return addArgToCalls( self._processSpecialC(s), list(self.fspec.auxfns.keys()), "p_, wk_, xv_", ) parseFunc = addParToCall else: parseFunc = self._processSpecialC reused, specupdated, new_protected, order = _processReused( specnames, specdict, self.fspec.reuseterms, "", "double", ";", parseFunc ) self.fspec._protected_reusenames = new_protected reusedefs = {}.fromkeys(new_protected) for _, deflist in reused.items(): for d in deflist: reusedefs[d[2]] = d return ( concatStrDict(reusedefs, intersect(order, reusedefs.keys())), specupdated, )
def _generate_reusestr(reused, reuseterms, order): """Build string with reused term definitions from data returned by `_processReused`""" reusedefs = {}.fromkeys(reuseterms) for deflist in reused.itervalues(): for d in deflist: reusedefs[d[2]] = d return concatStrDict(reusedefs, intersect(order, reusedefs.keys()))
def _generate_reusestr(reused, reuseterms, order): """Build string with reused term definitions from data returned by `_processReused`""" reusedefs = {}.fromkeys(reuseterms) for deflist in reused.values(): for d in deflist: reusedefs[d[2]] = d return concatStrDict(reusedefs, intersect(order, reusedefs.keys()))
def _processReusedPy(self, specnames, specdict, specials=[], dovars=True, dopars=True, doinps=True, illegal=[]): """Process reused subexpression terms for Python code.""" reused, specupdated, new_protected, order = _processReused( specnames, specdict, self.fspec.reuseterms, _indentstr ) self.fspec._protected_reusenames = new_protected # symbols to parse are at indices 2 and 4 of 'reused' dictionary reusedParsed = self._parseReusedTermsPy( reused, [2, 4], specials=specials, dovars=dovars, dopars=dopars, doinps=doinps, illegal=illegal ) reusedefs = {}.fromkeys(new_protected) for _, deflist in reusedParsed.items(): for d in deflist: reusedefs[d[2]] = d return (concatStrDict(reusedefs, intersect(order, reusedefs.keys())), specupdated)
def _processReusedC(self, specnames, specdict): """Process reused subexpression terms for C code.""" if self.fspec.auxfns: def addParToCall(s): return addArgToCalls(self._processSpecialC(s), list(self.fspec.auxfns.keys()), "p_, wk_, xv_") parseFunc = addParToCall else: parseFunc = self._processSpecialC reused, specupdated, new_protected, order = _processReused(specnames, specdict, self.fspec.reuseterms, '', 'double', ';', parseFunc) self.fspec._protected_reusenames = new_protected reusedefs = {}.fromkeys(new_protected) for _, deflist in reused.items(): for d in deflist: reusedefs[d[2]] = d return (concatStrDict(reusedefs, intersect(order, reusedefs.keys())), specupdated)
def test_concatStrDict_with_order(): d = {'a': ['a'] * 3, 'b': ['b'] * 2, 'c': ['c\n']} order = ['a', 'b', 'c'] assert 'aaabbc\n' == concatStrDict(d, order) assert 'c\nbbaaa' == concatStrDict(d, reversed(order))
def test_concatStrDict_without_order(): d = {'a': ['a'] * 3, 'b': ['b'] * 2, 'c': ['c\n']} s = concatStrDict(d) assert 'aaa' in s assert 'bb' in s assert 'c\n' in s
def test_concatStrDict_for_empty_dict(): assert '' == concatStrDict({})