# Path: cjktools/common.py
# class _NullContextWrapper(object):
#     """
#     Class for wrapping contexts so that they are passed through in a
#     with statement.
#     """
#     def __init__(self, context):
#         self.context = context
# 
#     def __enter__(self):
#         return self.context
# 
#     def __exit__(*args, **kwargs):
#         pass
# 
# Path: cjktools/resources/auto_format.py
# def iter_entries(istream):
#     """
#     Iterates over dictionary entries, without storing them all in memory
#     at once.
#     """
#     lines = iter(istream)
#     header = next(lines)
#     return detect_format(header).iter_entries(lines)


import re
import six
from collections import defaultdict
from cjktools.common import _NullContextWrapper as NullContextWrapper
from .auto_format import iter_entries
        coded_dict = defaultdict(dict)
        for entry in iter_entries(file_or_stream):
            word = entry.word

            # Merge any word entries with the same graphical form.
            if word in word_to_entry:
                e = word_to_entry[word]
                e.update(entry)
                entry = e
            else:
                word_to_entry[word] = entry

            codes = set()
            for sense in entry.senses:
                codes.update(get_codes(sense))

            # Create a subset of the dictionary for each code.
            for code in codes:
                # Note that overwriting is ok, since we already merged any
                # coincidental forms.
                coded_dict[code][word] = entry

    return coded_dict


def iter_coded_entries(filename):
    """
    Returns an iterator over dictionary entries in the filename, with their
    parsed codes, in (entry, code_list) pairs.
    """

# Path: cjktools/common.py
# class _NullContextWrapper(object):
#     """
#     Class for wrapping contexts so that they are passed through in a
#     with statement.
#     """
#     def __init__(self, context):
#         self.context = context
# 
#     def __enter__(self):
#         return self.context
# 
#     def __exit__(*args, **kwargs):
#         pass
# 
# Path: cjktools/resources/auto_format.py
# def iter_entries(istream):
#     """
#     Iterates over dictionary entries, without storing them all in memory
#     at once.
#     """
#     lines = iter(istream)
#     header = next(lines)
#     return detect_format(header).iter_entries(lines)


# Path: cjktools/resources/split_by_codes.py
import re
import six
from collections import defaultdict
from cjktools.common import _NullContextWrapper as NullContextWrapper
from .auto_format import iter_entries

        coded_dict = defaultdict(dict)
        for entry in iter_entries(file_or_stream):
            word = entry.word

            # Merge any word entries with the same graphical form.
            if word in word_to_entry:
                e = word_to_entry[word]
                e.update(entry)
                entry = e
            else:
                word_to_entry[word] = entry

            codes = set()
            for sense in entry.senses:
                codes.update(get_codes(sense))

            # Create a subset of the dictionary for each code.
            for code in codes:
                # Note that overwriting is ok, since we already merged any
                # coincidental forms.
                coded_dict[code][word] = entry

    return coded_dict


def iter_coded_entries(filename):
    """
    Returns an iterator over dictionary entries in the filename, with their
    parsed codes, in (entry, code_list) pairs.
    """

    for entry in iter_entries(filename):