'Handles opening of new incoming stream. Used internally.'

def StreamOpenHandler(self, conn, stanza):

    "\n<iq    type='set'    \n                from='romeo@montague.net/orchard'\n                to='juliet@capulet.com/balcony'\n                id='inband_1'>\n        <open    sid='mySID'    \n                                block-size='4096'\n                                xmlns='http://jabber.org/protocol/ibb'/>\n</iq>\n"
    err = None
    (sid, blocksize) = (stanza.getTagAttr('open', 'sid'), stanza.getTagAttr('open', 'block-size'))
    self.DEBUG(('StreamOpenHandler    called    sid->%s    blocksize->%s' % (sid, blocksize)), 'info')
    try:
        blocksize = int(blocksize)
    except:
        err = ERR_BAD_REQUEST
    if ((not sid) or (not blocksize)):
        err = ERR_BAD_REQUEST
    elif (sid in self._streams.keys()):
        err = ERR_UNEXPECTED_REQUEST
    if err:
        rep = Error(stanza, err)
    else:
        self.DEBUG(('Opening    stream:    id    %s,    block-size    %s' % (sid, blocksize)), 'info')
        rep = Protocol('iq', stanza.getFrom(), 'result', stanza.getTo(), {'id': stanza.getID()})
        self._streams[sid] = {'direction': ('<' + str(stanza.getFrom())), 'block-size': blocksize, 'fp': open(('/tmp/xmpp_file_' + sid), 'w'), 'seq': 0, 'syn_id': stanza.getID()}
    conn.send(rep)
