def unpack_from(cls, buf, offs, idmap = None):
if cython.compiled:
buf = _likebuffer(buf)
PyObject_GetBuffer(buf, cython.address(pybuf), PyBUF_SIMPLE) # lint:ok
pbuf = cython.cast(cython.p_uchar, pybuf.buf) # lint:ok
if offs >= pybuf.len:
PyBuffer_Release(cython.address(pybuf)) # lint
raise IndexError("Offset out of range")
else:
pbuf = buf
try:
if pbuf[offs] == 'm':
# inline bitmap
if cython.compiled and offs+7 >= pybuf.len:
raise IndexError("Object spans beyond buffer end")
rv = []
for i in xrange(7):
b = ord(pbuf[offs+1+i])
if b:
for j in xrange(8):
if b & (1<<j):
rv.append(i*8+j)
return frozenset(rv)
else:
# unpack a list, build a set from it
return frozenset(mapped_list.unpack_from(buf, offs, idmap))
finally:
if cython.compiled:
if type(buf) is buffer:
PyBuffer_Release(cython.address(pybuf)) # lint:ok
评论列表
文章目录