code: def deblock(f):
      
  
      row = int(f.read(12))
      size = int(f.read(12))
      if not (0 <= size <= 6000):
          raise Error('block has invalid size; not a Plan 9 image file?')
  
      # Since each block is at most 6000 bytes we may as well read it all in
      # one go.
      d = f.read(size)
      i = 0
      o = []
  
      while i < size:
          x = ord(d[i])
          i += 1
          if x & 0x80:
              x = (x & 0x7f) + 1
              lit = d[i: i + x]
              i += x
              o.extend(lit)
              continue
          # x's high-order bit is 0
          length = (x >> 2) + 3
          # Offset is made from bottom 2 bits of x and all 8 bits of next
          # byte.  http://plan9.bell-labs.com/magic/man2html/6/image doesn't
          # say whether x's 2 bits are most significant or least significant.
          # But it is clear from inspecting a random file,
          # http://plan9.bell-labs.com/sources/plan9/sys/games/lib/sokoban/images/cargo.bit
          # that x's 2 bits are most significant.
          offset = (x & 3) << 8
          offset |= ord(d[i])
          i += 1
          # Note: complement operator neatly maps (0 to 1023) to (-1 to
          # -1024).  Adding len(o) gives a (non-negative) offset into o from
          # which to start indexing.
          offset = ~offset + len(o)
          if offset < 0:
              raise Error('byte offset indexes off the begininning of '
                          'the output buffer; not a Plan 9 image file?')
          for j in range(length):
              o.append(o[offset + j])
      return row, ''.join(o)
docs: Decompress a single block from a compressed Plan 9 image file.
      Each block starts with 2 decimal strings of 12 bytes each.  Yields a
      sequence of (row, data) pairs where row is the total number of rows
      processed according to the file format and data is the decompressed
      data for a set of rows.