'Set clip rectangle. Calls self.pop() and self.push().'

def clip_cmd(self, cliprect, clippath):

    cmds = []
    while (((self._cliprect, self._clippath) != (cliprect, clippath)) and (self.parent is not None)):
        cmds.extend(self.pop())
    if (((self._cliprect, self._clippath) != (cliprect, clippath)) or (self.parent is None)):
        cmds.extend(self.push())
        if (self._cliprect != cliprect):
            cmds.extend([cliprect, Op.rectangle, Op.clip, Op.endpath])
        if (self._clippath != clippath):
            (path, affine) = clippath.get_transformed_path_and_affine()
            cmds.extend((PdfFile.pathOperations(path, affine, simplify=False) + [Op.clip, Op.endpath]))
    return cmds
