# Path: cinje/util.py
# def stream(input, encoding=None, errors='strict'):
# def flatten(input, file=None, encoding=None, errors='strict'):
# def fragment(string, name="anonymous", **context):
# def interruptable(iterable):
# def iterate(obj):
# def xmlargs(_source=None, **values):
# def chunk(line, mapping={None: 'text', '${': 'escape', '#{': 'bless', '&{': 'args', '%{': 'format', '@{': 'json'}):
# def ensure_buffer(context, separate=True):
# 	def __init__(self, number, line, scope=None, kind=None):
# 	def process(self):
# 	def stripped(self):
# 	def partitioned(self):
# 	def __repr__(self):
# 	def __bytes__(self):
# 	def __str__(self):
# 	def clone(self, **kw):
# 	def __init__(self, input=None, Line=Line):
# 	def count(self):
# 	def __len__(self):
# 	def __repr__(self):
# 	def __iter__(self):
# 	def __next__(self):
# 	def __str__(self):
# 	def next(self):
# 	def peek(self):
# 	def push(self, *lines):
# 	def reset(self):
# 	def append(self, *lines):
# 	def __init__(self, input):
# 	def __repr__(self):
# 	def prepare(self):
# 	def stream(self):
# 	def classify(self, line):
# 	def __init__(self, callable, *args, **kw):
# 	def __repr__(self):
# 	def __ror__(self, other):
# 	def __call__(self, *args, **kw):
# 	def __init__(self):
# 	def handle_data(self, d):
# 	def get_data(self):
# def strip_tags(html):
# class Line(object):
# class Lines(object):
# class Context(object):
# class Pipe(object):
# class MLStripper(HTMLParser):
# 
# Path: cinje/block/module.py
# class Module(object):
# 	"""Module handler.
# 	
# 	This is the initial scope, and the highest priority to ensure its processing of the preamble happens first.
# 	"""
# 	
# 	priority = -100
# 	
# 	def match(self, context, line):
# 		return 'init' not in context.flag
# 	
# 	def __call__(self, context):
# 		input = context.input
# 		
# 		context.flag.add('init')
# 		context.flag.add('buffer')
# 		
# 		imported = False
# 		
# 		for line in input:
# 			if not line.stripped or line.stripped[0] == '#':
# 				if not line.stripped.startswith('##') and 'coding:' not in line.stripped:
# 					yield line
# 				continue
# 			
# 			input.push(line)  # We're out of the preamble, so put that line back and stop.
# 			break
# 		
# 		# After any existing preamble, but before other imports, we inject our own.
# 		
# 		if py == 2:
# 			yield Line(0, 'from __future__ import unicode_literals')
# 			yield Line(0, '')
# 		
# 		yield Line(0, 'import cinje')
# 		yield Line(0, 'from cinje.helpers import escape as _escape, bless as _bless, iterate, xmlargs as _args, _interrupt, _json')
# 		yield Line(0, '')
# 		yield Line(0, '')
# 		yield Line(0, '__tmpl__ = []  # Exported template functions.')
# 		yield Line(0, '')
# 		
# 		for i in context.stream:
# 			yield i
# 		
# 		if context.templates:
# 			yield Line(0, '')
# 			yield Line(0, '__tmpl__.extend(["' + '", "'.join(context.templates) + '"])')
# 			context.templates = []
# 		
# 		# Snapshot the line number mapping.
# 		mapping = deque(context.mapping)
# 		mapping.reverse()
# 		
# 		yield Line(0, '')
# 		
# 		if __debug__:
# 			yield Line(0, '__mapping__ = [' + ','.join(str(i) for i in mapping) + ']')
# 		
# 		yield Line(0, '__gzmapping__ = b"' + red(mapping).replace('"', '\"') + '"')
# 		
# 		context.flag.remove('init')
# 
# Path: cinje/inline/code.py
# class Code(object):
# 	"""General code handler.
# 	
# 	This captures all code segments not otherwise handled.  It has a very low priority to ensure other "code" handlers
# 	get a chance to run first.
# 	
# 	Syntax:
# 	
# 		: <code>
# 	"""
# 	
# 	priority = 100
# 	
# 	def match(self, context, line):
# 		return line.kind == 'code'
# 	
# 	def __call__(self, context):
# 		try:
# 			yield context.input.next()  # Pass through.
# 		except StopIteration:
# 			return


from cinje.util import py, Context
from cinje.block.module import Module
from cinje.inline.code import Code
# encoding: utf-8

from __future__ import unicode_literals



class TestContextBehaviours(object):
	def test_repr_is_reasonable(self):
		context = Context('')
		
		if py == 2:
			assert repr(context) == 'Context(Lines(1), 0, set([]))'
		else:
			assert repr(context) == 'Context(Lines(1), 0, set())'
	
	def test_prepare_required_translator_priority(self):
		context = Context('')
		context.prepare()

# Path: cinje/util.py
# def stream(input, encoding=None, errors='strict'):
# def flatten(input, file=None, encoding=None, errors='strict'):
# def fragment(string, name="anonymous", **context):
# def interruptable(iterable):
# def iterate(obj):
# def xmlargs(_source=None, **values):
# def chunk(line, mapping={None: 'text', '${': 'escape', '#{': 'bless', '&{': 'args', '%{': 'format', '@{': 'json'}):
# def ensure_buffer(context, separate=True):
# 	def __init__(self, number, line, scope=None, kind=None):
# 	def process(self):
# 	def stripped(self):
# 	def partitioned(self):
# 	def __repr__(self):
# 	def __bytes__(self):
# 	def __str__(self):
# 	def clone(self, **kw):
# 	def __init__(self, input=None, Line=Line):
# 	def count(self):
# 	def __len__(self):
# 	def __repr__(self):
# 	def __iter__(self):
# 	def __next__(self):
# 	def __str__(self):
# 	def next(self):
# 	def peek(self):
# 	def push(self, *lines):
# 	def reset(self):
# 	def append(self, *lines):
# 	def __init__(self, input):
# 	def __repr__(self):
# 	def prepare(self):
# 	def stream(self):
# 	def classify(self, line):
# 	def __init__(self, callable, *args, **kw):
# 	def __repr__(self):
# 	def __ror__(self, other):
# 	def __call__(self, *args, **kw):
# 	def __init__(self):
# 	def handle_data(self, d):
# 	def get_data(self):
# def strip_tags(html):
# class Line(object):
# class Lines(object):
# class Context(object):
# class Pipe(object):
# class MLStripper(HTMLParser):
# 
# Path: cinje/block/module.py
# class Module(object):
# 	"""Module handler.
# 	
# 	This is the initial scope, and the highest priority to ensure its processing of the preamble happens first.
# 	"""
# 	
# 	priority = -100
# 	
# 	def match(self, context, line):
# 		return 'init' not in context.flag
# 	
# 	def __call__(self, context):
# 		input = context.input
# 		
# 		context.flag.add('init')
# 		context.flag.add('buffer')
# 		
# 		imported = False
# 		
# 		for line in input:
# 			if not line.stripped or line.stripped[0] == '#':
# 				if not line.stripped.startswith('##') and 'coding:' not in line.stripped:
# 					yield line
# 				continue
# 			
# 			input.push(line)  # We're out of the preamble, so put that line back and stop.
# 			break
# 		
# 		# After any existing preamble, but before other imports, we inject our own.
# 		
# 		if py == 2:
# 			yield Line(0, 'from __future__ import unicode_literals')
# 			yield Line(0, '')
# 		
# 		yield Line(0, 'import cinje')
# 		yield Line(0, 'from cinje.helpers import escape as _escape, bless as _bless, iterate, xmlargs as _args, _interrupt, _json')
# 		yield Line(0, '')
# 		yield Line(0, '')
# 		yield Line(0, '__tmpl__ = []  # Exported template functions.')
# 		yield Line(0, '')
# 		
# 		for i in context.stream:
# 			yield i
# 		
# 		if context.templates:
# 			yield Line(0, '')
# 			yield Line(0, '__tmpl__.extend(["' + '", "'.join(context.templates) + '"])')
# 			context.templates = []
# 		
# 		# Snapshot the line number mapping.
# 		mapping = deque(context.mapping)
# 		mapping.reverse()
# 		
# 		yield Line(0, '')
# 		
# 		if __debug__:
# 			yield Line(0, '__mapping__ = [' + ','.join(str(i) for i in mapping) + ']')
# 		
# 		yield Line(0, '__gzmapping__ = b"' + red(mapping).replace('"', '\"') + '"')
# 		
# 		context.flag.remove('init')
# 
# Path: cinje/inline/code.py
# class Code(object):
# 	"""General code handler.
# 	
# 	This captures all code segments not otherwise handled.  It has a very low priority to ensure other "code" handlers
# 	get a chance to run first.
# 	
# 	Syntax:
# 	
# 		: <code>
# 	"""
# 	
# 	priority = 100
# 	
# 	def match(self, context, line):
# 		return line.kind == 'code'
# 	
# 	def __call__(self, context):
# 		try:
# 			yield context.input.next()  # Pass through.
# 		except StopIteration:
# 			return


# Path: test/test_util/test_context.py
from cinje.util import py, Context
from cinje.block.module import Module
from cinje.inline.code import Code

# encoding: utf-8

from __future__ import unicode_literals



class TestContextBehaviours(object):
	def test_repr_is_reasonable(self):
		context = Context('')
		
		if py == 2:
			assert repr(context) == 'Context(Lines(1), 0, set([]))'
		else:
			assert repr(context) == 'Context(Lines(1), 0, set())'
	
	def test_prepare_required_translator_priority(self):
		context = Context('')
		context.prepare()

		assert isinstance(context._handler[0], Module), "Module must be first priority."