Can drivers span more than one line?
Although the expression is one line you can call a complex function in that line, you have to define and add this function to the driver's namespace before using it.

here's an example function and how it's added to the Driver's namespace ( from the DOC ) :

import bpy

def driverFunc(val):

    return val * val    # return val squared

bpy.app.driver_namespace['driverFunc'] = driverFunc    # add function to driver_namespace


To see the already availabe functions and properties type bpy.app.driver_namespace[' in the python console and hit Ctrl+space 

DOC link for more info