def METHOD_NAME(orient_client, time_range, writer, output):
    query_factory = _PortEventsQueryFactory(time_range)
    stream = _orient_stream(orient_client, query_factory)
    stream = (mapper.port_event_of_orient(x) for x in stream)
    writer.writerow(mapper.type_tag_to_dump(model.PORT_EVENT_TAG))
    for port_event in stream:
        output.flush()
        writer.writerow(mapper.port_event_to_dump(port_event))
        output.record_port_event()