I have a pdf file that was made into a booklet format. It is meant to print on A4 paper in landscape orientation; here are two pages in the pdf, which should correspond to four pages in the actual book.
 -------------------------------
|              |                |
|              |                |
|              |                |
|    (1)       |      (3)       |
|              |                |
|              |                |
|              |                |
 ------------------------------- 
 -------------------------------
|              |                |
|              |                |
|              |                |
|    (4)       |      (2)       |
|              |                |
|              |                |
|              |                |
 -------------------------------
The bracketed numbers correspond to the order of the individual pages.
I know that there are all sorts of commands (pdfbook, pdfnup, etc.) on linux (which was probably used to make this booklet in the first place). How do I 'unbook' it---that is, I'd like to make a pdf document from this where each individual page of the final product is an individual page of the pdf, ordered in the usual way.
Edit
Thanks to Gilles, I managed to use the following code:
import copy, sys
from pyPdf import PdfFileWriter, PdfFileReader
input = PdfFileReader(sys.stdin)
output = PdfFileWriter()
second_half = []
for i in range(0,input.getNumPages()):
    p = input.getPage(i)
    q = copy.copy(p)
    print >> sys.stderr, 'splitting page',i
    print >> sys.stderr, '\tlowerLeft:',p.mediaBox.lowerLeft
    print >> sys.stderr, '\tupperRight:',p.mediaBox.upperRight
    p.mediaBox.upperRight = (ur[0], (bl[1]+ur[1])/2)
    p.mediaBox.lowerLeft = bl
    q.mediaBox.upperRight = ur
    q.mediaBox.lowerLeft = (bl[0], (bl[1]+ur[1])/2)
    if i % 2 == 0:
        output.addPage(p)
        qold = q
    else:
        output.addPage(q)
        output.addPage(qold)
        output.addPage(p)
output.write(sys.stdout)
