<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build(self, db=None, safe_mode=False, for_each_inst=None, extra=None):
 """Builds a dictionary that can be used as context for template rendering."""

        result = copy(self.initial)
        result.update(self.static)
        if self.dynamic:
            result.update(self.build_dynamic(db, extra=extra, safe_mode=safe_mode))
        if self.for_each and for_each_inst:
            result.update(self.build_for_each(db, safe_mode=safe_mode, extra=extra))
        if isinstance(extra, dict):
            result.update(extra)
        return result