<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def flush_template(context, declaration=None, reconstruct=True):
 	"""Emit the code needed to flush the buffer. 		 	Will only emit the yield and clear if the buffer is known to be dirty. 	"""

	
	if declaration is None:
		declaration = Line(0, '')
	
	if {'text', 'dirty'}.issubset(context.flag):
		yield declaration.clone(line='yield "".join(_buffer)')
		
		context.flag.remove('text')  # This will force a new buffer to be constructed.
		context.flag.remove('dirty')
		
		if reconstruct:
			for i in ensure_buffer(context):
				yield i
	
	if declaration.stripped == 'yield':
		yield declaration