human
Complete the below
def geom_output(func, argtypes, offset=None):

    ''''Generates a function that returns a Geometry either by reference
    or directly (if the return_geom keyword is set to True).'
    '''

=====
Write me a the Python code you requested?
assistant
#Here is the Python code you requested.
    func.argtypes = argtypes
    if (not offset):
        func.restype = c_void_p
        func.errcheck = check_geom
    else:
        func.restype = c_int
        def geomerrcheck(result, func, cargs):
            return check_geom_offset(result, func, cargs, offset)
        func.errcheck = geomerrcheck
    return func