# Path: pybabe/sort.py
# def sort(stream, field, reverse=False):
#     buf = []
#     for elt in stream:
#         if isinstance(elt, StreamHeader):
#             yield elt
#         elif isinstance(elt, StreamFooter):
#             buf.sort(key=lambda obj: getattr(obj, field), reverse=reverse)
#             for row in buf:
#                 yield row
#             yield elt
#         else:
#             buf.append(elt)


from base import StreamHeader, BabeBase, StreamFooter
from pybabe.sort import sort


class Reducer(object):
    def __init__(self, f):
        self.f = f
        self.buf = []

    def begin_group(self, key):
        del self.buf[:]

# Path: pybabe/sort.py
# def sort(stream, field, reverse=False):
#     buf = []
#     for elt in stream:
#         if isinstance(elt, StreamHeader):
#             yield elt
#         elif isinstance(elt, StreamFooter):
#             buf.sort(key=lambda obj: getattr(obj, field), reverse=reverse)
#             for row in buf:
#                 yield row
#             yield elt
#         else:
#             buf.append(elt)


# Path: pybabe/group.py
from base import StreamHeader, BabeBase, StreamFooter
from pybabe.sort import sort



class Reducer(object):
    def __init__(self, f):
        self.f = f
        self.buf = []

    def begin_group(self, key):
        del self.buf[:]

        self.key = key