def features(entrystream, type=None, traverse=False):
for feature in entry_type_filter(entrystream, tag.Feature):<EOL><INDENT>if traverse:<EOL><INDENT>if type is None:<EOL><INDENT>message = '<STR_LIT>'<EOL>raise ValueError(message)<EOL><DEDENT>if type == feature.type:<EOL><INDENT>yield feature<EOL><DEDENT>else:<EOL><INDENT>for subfeature in feature:<EOL><INDENT>if type == subfeature.type:<EOL><INDENT>yield subfeature<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if not type or type == feature.type:<EOL><INDENT>yield feature<EOL><DEDENT><DEDENT><DEDENT>
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