<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def create_or_update(sysmeta_pyxb, sciobj_url=None):
 """Create or update database representation of a System Metadata object and closely related internal state. - If ``sciobj_url`` is not passed on create, storage in the internal sciobj store is assumed - If ``sciobj_url`` is passed on create, it can reference a location in the internal sciobj store, or an arbitrary location on disk, or a remote web server. See the sciobj_store module for more information - if ``sciobj_url`` is not passed on update, the sciobj location remains unchanged - If ``sciobj_url`` is passed on update, the sciobj location is updated Preconditions: - All values in ``sysmeta_pyxb`` must be valid for the operation being performed """

    # TODO: Make sure that old sections are removed if not included in update.

    pid = d1_common.xml.get_req_val(sysmeta_pyxb.identifier)

    if sciobj_url is None:
        sciobj_url = d1_gmn.app.sciobj_store.get_rel_sciobj_file_url_by_pid(pid)

    try:
        sci_model = d1_gmn.app.model_util.get_sci_model(pid)
    except d1_gmn.app.models.ScienceObject.DoesNotExist:
        sci_model = d1_gmn.app.models.ScienceObject()
        sci_model.pid = d1_gmn.app.did.get_or_create_did(pid)
        sci_model.url = sciobj_url
        sci_model.serial_version = sysmeta_pyxb.serialVersion
        sci_model.uploaded_timestamp = d1_common.date_time.normalize_datetime_to_utc(
            sysmeta_pyxb.dateUploaded
        )

    _base_pyxb_to_model(sci_model, sysmeta_pyxb)

    sci_model.save()

    if _has_media_type_pyxb(sysmeta_pyxb):
        _media_type_pyxb_to_model(sci_model, sysmeta_pyxb)

    _access_policy_pyxb_to_model(sci_model, sysmeta_pyxb)

    if _has_replication_policy_pyxb(sysmeta_pyxb):
        _replication_policy_pyxb_to_model(sci_model, sysmeta_pyxb)

    replica_pyxb_to_model(sci_model, sysmeta_pyxb)
    revision_pyxb_to_model(sci_model, sysmeta_pyxb, pid)

    sci_model.save()

    return sci_model