[fix] check attribute existence before using it

bpython uses a FakeStream object which has no fileno attribute