def check_for_leak(host, port=6235):
    raw = mir3console.run('print statements', host, port)
    regex = re.compile(r'(.*)There are currently', re.DOTALL)
    m = regex.search(raw)
    if m is not None:
        ids = m.group(1).split()
        for id in ids:
            inspect_statement(id, host, port)
    else:
        return []
def check_for_leak(host, port=6235):
	raw = mir3console.run('print statements', host, port)
	regex = re.compile(r'(.*)There are currently', re.DOTALL)
	m = regex.search(raw)
	if m is not None:
		ids = m.group(1).split()
		for id in ids:
			inspect_statement(id, host, port)
	else:
		return []
def inspect_statement(id, host, port):
	global ALL_LINES
	raw = mir3console.run('print statement %s' % id, host, port)
	get_next_line = False
	for line in raw.splitlines():
		if get_next_line: 
			if not ALL_LINES.has_key(line): ALL_LINES[line]=0
			ALL_LINES[line] += 1
			break
		if line.find('SawtoothConnection.prepareStatement') > 0: get_next_line = True
def inspect_statement(id, host, port):
    global ALL_LINES
    raw = mir3console.run('print statement %s' % id, host, port)
    get_next_line = False
    for line in raw.splitlines():
        if get_next_line:
            if not ALL_LINES.has_key(line): ALL_LINES[line] = 0
            ALL_LINES[line] += 1
            break
        if line.find('SawtoothConnection.prepareStatement') > 0:
            get_next_line = True