# Path: cinje/util.py
# class Line(object):
# 	"""A rich description for a line of input, allowing for annotation."""
# 	
# 	__slots__ = ('number', 'line', 'scope', 'kind', 'continued')
# 	
# 	def __init__(self, number, line, scope=None, kind=None):
# 		if isinstance(line, bytes):
# 			line = line.decode('utf-8')
# 		
# 		self.number = number
# 		self.line = line
# 		self.scope = scope
# 		self.kind = kind
# 		self.continued = self.stripped.endswith('\\')
# 		
# 		if not kind: self.process()
# 		
# 		super(Line, self).__init__()
# 	
# 	def process(self):
# 		if self.stripped.startswith('#') and not self.stripped.startswith('#{'):
# 			self.kind = 'comment'
# 		elif self.stripped.startswith(':'):
# 			self.kind = 'code'
# 			self.line = self.stripped[1:].lstrip()
# 		else:
# 			self.kind = 'text'
# 	
# 	@property
# 	def stripped(self):
# 		return self.line.strip()
# 	
# 	@property
# 	def partitioned(self):
# 		prefix, _, remainder = self.stripped.partition(' ')
# 		return prefix.rstrip(), remainder.lstrip()
# 	
# 	def __repr__(self):
# 		return '{0.__class__.__name__}({0.number}, {0.kind}, "{0.stripped}")'.format(self)
# 	
# 	def __bytes__(self):
# 		return str(self).encode('utf8')
# 	
# 	def __str__(self):
# 		if self.scope is None:
# 			return self.line
# 		
# 		return '\t' * self.scope + self.line.lstrip()
# 	
# 	if py == 2:  # pragma: no cover
# 		__unicode__ = __str__
# 		__str__ = __bytes__
# 		del __bytes__
# 	
# 	def clone(self, **kw):
# 		values = dict(
# 				number = self.number,
# 				line = self.line,
# 				scope = self.scope,
# 				kind = self.kind,
# 			)
# 		
# 		values.update(kw)
# 		
# 		instance = self.__class__(**values)
# 		
# 		return instance
# 
# def ensure_buffer(context, separate=True):
# 	if 'text' in context.flag or 'buffer' not in context.flag:
# 		return
# 	
# 	if separate: yield Line(0, "")
# 	yield Line(0, "_buffer = []")
# 	
# 	if not pypy:
# 		yield Line(0, "__w, __ws = _buffer.extend, _buffer.append")
# 	
# 	yield Line(0, "")
# 	
# 	context.flag.add('text')


from ..util import Line, ensure_buffer
# encoding: utf-8



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:

# Path: cinje/util.py
# class Line(object):
# 	"""A rich description for a line of input, allowing for annotation."""
# 	
# 	__slots__ = ('number', 'line', 'scope', 'kind', 'continued')
# 	
# 	def __init__(self, number, line, scope=None, kind=None):
# 		if isinstance(line, bytes):
# 			line = line.decode('utf-8')
# 		
# 		self.number = number
# 		self.line = line
# 		self.scope = scope
# 		self.kind = kind
# 		self.continued = self.stripped.endswith('\\')
# 		
# 		if not kind: self.process()
# 		
# 		super(Line, self).__init__()
# 	
# 	def process(self):
# 		if self.stripped.startswith('#') and not self.stripped.startswith('#{'):
# 			self.kind = 'comment'
# 		elif self.stripped.startswith(':'):
# 			self.kind = 'code'
# 			self.line = self.stripped[1:].lstrip()
# 		else:
# 			self.kind = 'text'
# 	
# 	@property
# 	def stripped(self):
# 		return self.line.strip()
# 	
# 	@property
# 	def partitioned(self):
# 		prefix, _, remainder = self.stripped.partition(' ')
# 		return prefix.rstrip(), remainder.lstrip()
# 	
# 	def __repr__(self):
# 		return '{0.__class__.__name__}({0.number}, {0.kind}, "{0.stripped}")'.format(self)
# 	
# 	def __bytes__(self):
# 		return str(self).encode('utf8')
# 	
# 	def __str__(self):
# 		if self.scope is None:
# 			return self.line
# 		
# 		return '\t' * self.scope + self.line.lstrip()
# 	
# 	if py == 2:  # pragma: no cover
# 		__unicode__ = __str__
# 		__str__ = __bytes__
# 		del __bytes__
# 	
# 	def clone(self, **kw):
# 		values = dict(
# 				number = self.number,
# 				line = self.line,
# 				scope = self.scope,
# 				kind = self.kind,
# 			)
# 		
# 		values.update(kw)
# 		
# 		instance = self.__class__(**values)
# 		
# 		return instance
# 
# def ensure_buffer(context, separate=True):
# 	if 'text' in context.flag or 'buffer' not in context.flag:
# 		return
# 	
# 	if separate: yield Line(0, "")
# 	yield Line(0, "_buffer = []")
# 	
# 	if not pypy:
# 		yield Line(0, "__w, __ws = _buffer.extend, _buffer.append")
# 	
# 	yield Line(0, "")
# 	
# 	context.flag.add('text')


# Path: cinje/inline/flush.py
from ..util import Line, ensure_buffer

# encoding: utf-8



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