Exemple #1
0
                FunctionParser, ObjectAccessParser
        ]:
            p.mappings = self.pre_exercise_mappings.copy()
        # run parser
        p.visit(getattr(self, tree_name))
        # cache
        self._parser_cache[cache_key] = p
    return getattr(p, ext_attr)


# put a property getter on state for each parsed ast tree output.
# since the getter takes only one argument, self, partial functions
# are used to set all other arguments on getx
for s in ['student', 'solution']:
    tree_name = s + '_tree'
    for k, Parser in parser_dict.items():
        setattr(State, s + '_' + k,
                property(partial(getx, tree_name, Parser, 'out')))

    # mappings from ObjectAccessParser
    prop_oa_map = property(
        partial(getx, tree_name, ObjectAccessParser, 'mappings'))
    setattr(State, s + '_oa_mappings', prop_oa_map)

    # mappings from FunctionParser
    prop_map = property(partial(getx, tree_name, FunctionParser, 'mappings'))
    setattr(State, s + '_mappings', prop_map)

# mappings for pre exercise code from FunctionParser
pec_prop_map = property(
    partial(getx, 'pre_exercise_tree', FunctionParser, 'mappings'))
Exemple #2
0
        p = Parser()
        # set mappings for parsers that inspect attribute access
        if ext_attr != 'mappings' and Parser in [FunctionParser, ObjectAccessParser]: 
            p.mappings = self.pre_exercise_mappings.copy()
        # run parser
        p.visit(getattr(self, tree_name))
        # cache
        self._parser_cache[cache_key] = p
    return getattr(p, ext_attr)

# put a property getter on state for each parsed ast tree output.
# since the getter takes only one argument, self, partial functions
# are used to set all other arguments on getx
for s in ['student', 'solution']:
    tree_name = s+'_tree'
    for k, Parser in parser_dict.items():
        setattr(State, s+'_'+k, property(partial(getx, tree_name, Parser, 'out')))

    # mappings from ObjectAccessParser
    prop_oa_map = property(partial(getx, tree_name, ObjectAccessParser, 'mappings'))
    setattr(State, s+'_oa_mappings', prop_oa_map)

    # mappings from FunctionParser
    prop_map = property(partial(getx, tree_name, FunctionParser, 'mappings'))
    setattr(State, s+'_mappings', prop_map)

# mappings for pre exercise code from FunctionParser
pec_prop_map = property(partial(getx, 'pre_exercise_tree', FunctionParser, 'mappings'))
setattr(State, 'pre_exercise_mappings', pec_prop_map)

# State subclasses based on parsed output -------------------------------------