<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_valid_sid_for_chain(pid, sid):
 """Return True if ``sid`` can be assigned to the single object ``pid`` or to the chain to which ``pid`` belongs. - If the chain does not have a SID, the new SID must be previously unused. - If the chain already has a SID, the new SID must match the existing SID. All known PIDs are associated with a chain. Preconditions: - ``pid`` is verified to exist. E.g., with d1_gmn.app.views.asserts.is_existing_object(). - ``sid`` is None or verified to be a SID """

    if _is_unused_did(sid):
        return True
    existing_sid = d1_gmn.app.revision.get_sid_by_pid(pid)
    if existing_sid is None:
        return False
    return existing_sid == sid