def METHOD_NAME(spec):
    sort_spec = namedtuple(
        '_sort_spec',
        ['field', 'direction', 'nullsfirst', 'nullslast']
    )(
        field=spec['field'],
        direction=spec['direction'],
        nullsfirst=spec.get('nullsfirst', False),
        nullslast=spec.get('nullslast', False)
    )
    # Since it's not valid to have both nullsfirst and nullslast.
    assert not sort_spec.nullsfirst or not sort_spec.nullslast
    return sort_spec