'Closes the specified stream.
:param str stream_id: id of the stream to be closed
:param stem.RelayEndReason reason: reason the stream is closing
:param str flag: not currently used
:raises:
* :class:`stem.InvalidArguments` if the stream or reason are not recognized
* :class:`stem.InvalidRequest` if the stream and/or reason are missing'

def close_stream(self, stream_id, reason=stem.RelayEndReason.MISC, flag=''):

    response = self.msg(('CLOSESTREAM    %s    %s    %s' % (stream_id, (stem.RelayEndReason.index_of(reason) + 1), flag)))
    stem.response.convert('SINGLELINE', response)
    if (not response.is_ok()):
        if (response.code in ('512', '552')):
            if response.message.startswith('Unknown    stream    '):
                raise stem.InvalidArguments(response.code, response.message, [stream_id])
            elif response.message.startswith('Unrecognized    reason    '):
                raise stem.InvalidArguments(response.code, response.message, [reason])
            raise stem.InvalidRequest(response.code, response.message)
        else:
            raise stem.ProtocolError(('CLOSESTREAM    returned    unexpected    response    code:    %s' % response.code))
