def features(entrystream, type=None, traverse=False):
    """
    Pull features out of the specified entry stream.

    :param entrystream: a stream of entries
    :param type: retrieve only features of the specified type; set to
                 :code:`None` to retrieve all features
    :param traverse: by default, only top-level features are selected; set
                     to :code:`True` to search each feature graph for the
                     specified feature type
    """
    for feature in entry_type_filter(entrystream, tag.Feature):
        if traverse:
            if type is None:
                message = 'cannot traverse without a specific feature type'
                raise ValueError(message)
            if type == feature.type:
                yield feature
            else:
                for subfeature in feature:
                    if type == subfeature.type:
                        yield subfeature
        else:
            if not type or type == feature.type:
                yield feature
Pull features out of the specified entry stream.

    :param entrystream: a stream of entries
    :param type: retrieve only features of the specified type; set to
                 :code:`None` to retrieve all features
    :param traverse: by default, only top-level features are selected; set
                     to :code:`True` to search each feature graph for the
                     specified feature type