(xform, interface)
Context manager that locks a form and checks/prepares for duplicates

    The lock is acquired on context manager enter and released on exit.

    Historically this locked both the new (possibly duplicate) form ID
    as well as any new ID generated in the process of handling a
    duplicate form ID. The submitted form ID is still locked, but the
    newly generated ID is not since it should be globally unique.
Context manager that locks a form and checks/prepares for duplicates
Context manager that locks a form and checks / prepares for duplicates
def locked_form(xform, interface):
    """Context manager that locks a form and checks/prepares for duplicates

    The lock is acquired on context manager enter and released on exit.

    Historically this locked both the new (possibly duplicate) form ID
    as well as any new ID generated in the process of handling a
    duplicate form ID. The submitted form ID is still locked, but the
    newly generated ID is not since it should be globally unique.
    """
    context = [xform]
    lock = interface.acquire_lock_for_xform(xform.form_id)
    try:
        if interface.is_duplicate(xform.form_id):
            new_form, dup_form = _handle_id_conflict(xform, xform.domain)
            if dup_form:
                assert dup_form.form_id != new_form.form_id, (new_form, dup_form)
                context = [new_form, dup_form]
            else:
                assert new_form is xform, (new_form, xform)
        yield context
    finally:
        release_lock(lock, degrade_gracefully=True)
def locked_form ( xform , interface ) : context = [ xform ] lock = interface . acquire_lock_for_xform ( xform . form_id ) try : if interface . is_duplicate ( xform . form_id ) : new_form , dup_form = _handle_id_conflict ( xform , xform . domain ) if dup_form : assert dup_form . form_id != new_form . form_id , ( new_form , dup_form ) context = [ new_form , dup_form ] else : assert new_form is xform , ( new_form , xform ) yield context finally : release_lock ( lock , degrade_gracefully = True )