code: def split(self, bitindex):
          
          if bitindex < 0:
              raise ValueError("bitindex must be larger or equal to 0.")
          if bitindex == 0:
              return None, self
  
          lastend = 0
          split_promise = False
          for splitindex, p in enumerate(self._promises):
              if bitindex in range(lastend, p._bitstart):
                  split_promise = False
                  break
              if bitindex in range(p._bitstart, p._bitend):
                  if bitindex-p._bitstart == 0:
                      split_promise = False
                  else:
                      split_promise = True
                  break
              lastend = p._bitend
          else:
              raise Exception("Should be impossible")
  
          processed_left = TDOPromiseCollection(self._chain)
          processed_right = TDOPromiseCollection(self._chain)
  
          if split_promise:
              left, right = p.split(bitindex-p._bitstart)
  
              for i in range(splitindex):
                  processed_left.add(self._promises[i], 0)
              processed_left.add(left, 0)
  
              processed_right.add(right, 0)
              for tmpprim in self._promises[splitindex+1:]:
                  processed_right.add(tmpprim, -bitindex)
              return processed_left, processed_right
          else:
              for i in range(splitindex):
                  processed_left.add(self._promises[i], 0)
  
              for i in range(splitindex, len(self._promises)):
                  processed_right.add(self._promises[i], -bitindex)
  
              return processed_left, processed_right
docs: Split a promise into two promises. A tail bit, and the 'rest'.
  
          Same operation as the one on TDOPromise, except this works
          with a collection of promises and splits the appropriate one.
  
          Returns:
              The 'Rest' and the 'Tail'.
              The 'Rest' is TDOPromiseCollection containing the first
                chunk of the original TDOPromiseCollection.
              The 'Tail' is a single bit sub promise for the final bit
                in the operation
  
              If the 'Rest' would have a length of 0, None is returned