Opened 11 months ago

Closed 7 weeks ago

#23859 closed defect (fixed)

stem parse_file doesn't handle stdin

Reported by: teor Owned by: atagar
Priority: Medium Milestone:
Component: Core Tor/Stem Version:
Severity: Normal Keywords: descriptor easy
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

The code looks like:

from sys import stdin

from stem.descriptor import parse_file

new_micro_digests = set()

for desc in parse_file(stdin, validate = True):
    new_micro_digests.add(desc.digest)

The stack trace looks like:

$ cat 2017-10-14-17-05-00-micro | ./get_micro_fp.py
Traceback (most recent call last):
  File "./get_micro_fp.py", line 9, in <module>
    for desc in parse_file(stdin, validate = True):
  File "/Users/dev/stem/stem/descriptor/__init__.py", line 196, in parse_file
    initial_position = descriptor_file.tell()
IOError: [Errno 29] Illegal seek

Child Tickets

Change History (2)

comment:1 Changed 4 months ago by atagar

Keywords: descriptor easy added

comment:2 Changed 7 weeks ago by atagar

Resolution: fixed
Status: newclosed

Thanks teor. Looked into this for a while but seems we can't safely convert non-seekable streams like stdin into buffered streams. Adjusted the exception to hopefully provide a more helpful message. See the commit message for all the details.

https://gitweb.torproject.org/stem.git/commit/?id=8ec17d8

Feel free to reopen if there's a better way for us to handle this.

Note: See TracTickets for help on using tickets.