コード例 #1
0
ファイル: amf0.py プロジェクト: DxCx/twimp
def _decode_so_update(s):
    obj_name = _decode_string(s)
    version = _s_ulong.unpack(s.read(4))[0]
    flags = s.read(8)[0]
    events = []
    while True:
        event = {}
        try:
            event['type'] = _decode_marker(s)
        except VecBufEOB:
            break # We are good.

        so_body_size = _s_ulong.unpack(s.read(4))[0]
        event['data'] = ''
        if so_body_size:
            event['data'] = VecBuf(s.read(so_body_size))
        events.append(event)

    return {'obj_name': obj_name, 'version': version, 'flags': flags, 'events': events}
コード例 #2
0
ファイル: chunks.py プロジェクト: davibe/twimp
    def gen_handler(self):
        s = ''

        while 1:
            if len(s) < 1:
                s = yield 1     # need 1 byte to read "basic header"

            htype, csid = read_header_head(s)
            a = csid
            csid_sel = min(csid, 2)
            head_size = _sizes_1[csid_sel] + _sizes_2[htype]

            if len(s) < head_size:
                s = yield head_size # bytes to read the rest of the header

            if csid == 0:
                csid = _s_uchar.unpack(s.read(1))[0] + 64
            elif csid == 1:
                csid = _s_ushort_l.unpack(s.read(2))[0] + 64

            m_time, m_size, m_type, m_msid = None, None, None, None
            c_h, h_base, accbody, to_read = None, None, None, None
            m_time_ext = False
            h_absolute = (htype == 0)

            # check csid in the message and chunk stream caches
            if csid in self.chstr_map:
                c_h, accbody, to_read = self.chstr_map[csid]
                m_time_ext = (c_h.time >= 0x00ffffff)
            elif not h_absolute and csid in self.msg_map:
                h_base = self.msg_map[csid]
                m_time_ext = (h_base.time >= 0x00ffffff)
            else:
                # TODO: check/warn header is absolute here
                pass

            if htype == 3:
                pass
            elif htype == 2:
                _time_1, m_time = _s_time.unpack(s.read(3))
                m_time += _time_1 << 8
            else:
                (_time_1, m_time, _size_1,
                 m_size, m_type) = _s_time_size_type.unpack(s.read(7))
                bla = m_time
                bla1 = m_size
                m_time += _time_1 << 8
                m_size += _size_1 << 8
                if htype == 0:
                    m_msid, = _s_ulong_l.unpack(s.read(4))

            if m_time == 0x00ffffff or m_time is None and m_time_ext:
                print 'F*****G EXTENDED mt:%s ext:%s size:%s a:%s csid:%s '\
                        'htype:%s hs:%s' % (m_time, m_time_ext,
                        m_size, a, csid, htype, head_size)
#                import pdb; pdb.set_trace()
                if len(s) < 4:
                    s = yield 4 # 4 bytes of "extended timestamp"
                m_time, = _s_ulong_b.unpack(s.read(4))
#                if m_size is not None:
#                    m_size += 4
                m_time = None

            h = Header(csid, m_time, m_size, m_type, m_msid)


            # fill header if cached entry was found earlier
            if c_h:
                # TODO: check/warn header consistency (with the cached
                # first one)
                h = c_h
            elif h_base:
                h = absolutize(h, h_base)
                to_read = h.size
            else:
                to_read = h.size

            need_bytes = min(to_read, self.chunk_size)
            if need_bytes > 0:
                if len(s) < need_bytes:
                    s = yield need_bytes

                if accbody is None:
                    accbody = s.read_seq(need_bytes)
                else:
                    accbody += s.read_seq(need_bytes)
            else:
                if accbody is None:
                    accbody = []

            if to_read > self.chunk_size:
                self.chstr_map[h.cs_id] = (h, accbody,
                                           to_read - self.chunk_size)
            else:
                self.chstr_map.pop(h.cs_id, None)
                self.msg_map[h.cs_id] = h

                if h.cs_id == 2 and 0 < h.type < 8 and h.ms_id == 0:
                    self.controlMessageReceived(h, vecbuf.VecBuf(accbody))
                else:
                    self.protocol.messageReceived(h, vecbuf.VecBuf(accbody))
コード例 #3
0
ファイル: amf0.py プロジェクト: DxCx/twimp
def _decode_strict_array(s):
    length, = _s_ulong.unpack(s.read(4))
    return [_decode_single(s) for _ in xrange(length)]
コード例 #4
0
ファイル: chunks.py プロジェクト: DxCx/twimp
    def gen_handler(self):
        s = ''

        while 1:
            if len(s) < 1:
                s = yield 1  # need 1 byte to read "basic header"

            htype, csid = read_header_head(s)
            a = csid
            csid_sel = min(csid, 2)
            head_size = _sizes_1[csid_sel] + _sizes_2[htype]

            if len(s) < head_size:
                s = yield head_size  # bytes to read the rest of the header

            if csid == 0:
                csid = _s_uchar.unpack(s.read(1))[0] + 64
            elif csid == 1:
                csid = _s_ushort_l.unpack(s.read(2))[0] + 64

            m_time, m_size, m_type, m_msid = None, None, None, None
            c_h, h_base, accbody, to_read = None, None, None, None
            m_time_ext = False
            h_absolute = (htype == 0)

            # check csid in the message and chunk stream caches
            if csid in self.chstr_map:
                c_h, accbody, to_read = self.chstr_map[csid]
                m_time_ext = (c_h.time >= 0x00ffffff)
            elif not h_absolute and csid in self.msg_map:
                h_base = self.msg_map[csid]
                m_time_ext = (h_base.time >= 0x00ffffff)
            else:
                # TODO: check/warn header is absolute here
                pass

            if htype == 3:
                pass
            elif htype == 2:
                _time_1, m_time = _s_time.unpack(s.read(3))
                m_time += _time_1 << 8
            else:
                (_time_1, m_time, _size_1, m_size,
                 m_type) = _s_time_size_type.unpack(s.read(7))
                bla = m_time
                bla1 = m_size
                m_time += _time_1 << 8
                m_size += _size_1 << 8
                if htype == 0:
                    m_msid, = _s_ulong_l.unpack(s.read(4))

            if m_time == 0x00ffffff or m_time is None and m_time_ext:
                if len(s) < 4:
                    s = yield 4  # 4 bytes of "extended timestamp"
                m_time, = _s_ulong_b.unpack(s.read(4))

            h = Header(csid, m_time, m_size, m_type, m_msid)

            # fill header if cached entry was found earlier
            if c_h:
                # TODO: check/warn header consistency (with the cached
                # first one)
                h = c_h
            elif h_base:
                h = absolutize(h, h_base)
                to_read = h.size
            else:
                to_read = h.size

            need_bytes = min(to_read, self.chunk_size)
            if need_bytes > 0:
                if len(s) < need_bytes:
                    s = yield need_bytes

                if accbody is None:
                    accbody = s.read_seq(need_bytes)
                else:
                    accbody += s.read_seq(need_bytes)
            else:
                if accbody is None:
                    accbody = []

            if to_read > self.chunk_size:
                self.chstr_map[h.cs_id] = (h, accbody,
                                           to_read - self.chunk_size)
            else:
                self.chstr_map.pop(h.cs_id, None)
                self.msg_map[h.cs_id] = h

                if h.cs_id == 2 and 0 < h.type < 8 and h.ms_id == 0:
                    self.controlMessageReceived(h, vecbuf.VecBuf(accbody))
                else:
                    self.protocol.messageReceived(h, vecbuf.VecBuf(accbody))