torproject / stem

Python controller library for Tor
https://stem.torproject.org/
GNU Lesser General Public License v3.0
273 stars 76 forks source link

Do not return generator when DocumentHandler is DOCUMENT #82

Closed jbrown299 closed 3 years ago

jbrown299 commented 3 years ago
    with open('cached-microdesc-consensus', 'rb') as consensus_file:
        network_status = parse_file(consensus_file,
                                    'network-status-microdesc-consensus-3 1.0',
                                    document_handler=DocumentHandler.DOCUMENT,
                                    validate=True)

So here is parse_file always return generator. In my opinion will be better if we parse as single document return object but not generator.

Or you mean it is possible to load several documents from one file?

atagar commented 3 years ago

Hi James. You're right that this is a common gotcha, please use next...

network_status = next(parse_file(...))

Some files contain a single descriptor, whereas others have multiple. Varying our return type based on the context would make this function even more confusing to use.