def get_object_definition(urn_or_oid, version):
    urn = urn_or_oid.strip()
    if urn.startswith('urn:oma:lwm2m:'):
        oid = int(urn.split(':')[(- 1)])
    else:
        oid = int(urn)
    try:
        registry = Lwm2mObjectRegistry()
        objects = registry.objects[oid]
        available_versions_message = ('Available versions for object with ID %d: %s' % (oid, ', '.join((str(obj.Ver) for obj in objects))))
        if (version is None):
            if (len(objects) > 1):
                logging.info(('%s; defaulting to maximum available version: %s' % (available_versions_message, max(objects).Ver)))
            object_ddf_url = max(objects).DDF
        else:
            object_ddf_url = next((obj for obj in objects if (obj.Ver == version))).DDF
        if (not object_ddf_url):
            raise ValueError(("Object with ID = %d doesn't have attached XML definition" % oid))
        if (not object_ddf_url.startswith('http')):
            object_ddf_url = ((registry.repo_url + '/') + object_ddf_url)
        return _read_url(object_ddf_url).decode('utf-8-sig')
    except KeyError:
        raise ValueError(('Object with ID = %d not found' % oid))
    except StopIteration:
        raise ValueError(available_versions_message)
def get_object_definition(urn_or_oid, version):
    urn = urn_or_oid.strip()
    if urn.startswith('urn:oma:lwm2m:'):
        oid = int(urn.split(':')[(- 1)])
    else:
        oid = int(urn)
    try:
        registry = Lwm2mObjectRegistry()
        objects = registry.objects[oid]
        available_versions_message = ('Available versions for object with ID %d: %s' % (oid, ', '.join((str(obj.Ver) for obj in objects))))
        if (version is None):
            if (len(objects) > 1):
                logging.info(('%s; defaulting to maximum available version: %s' % (available_versions_message, max(objects).Ver)))
            object_ddf_url = max(objects).DDF
        else:
            object_ddf_url = next((obj for obj in objects if (obj.Ver == version))).DDF
        if (not object_ddf_url):
            raise ValueError(("Object with ID = %d doesn't have attached XML definition" % oid))
        if (not object_ddf_url.startswith('http')):
            object_ddf_url = ((registry.repo_url + '/') + object_ddf_url)
        return _read_url(object_ddf_url).decode('utf-8-sig')
    except KeyError:
        raise ValueError(('Object with ID = %d not found' % oid))
    except StopIteration:
        raise ValueError(available_versions_message)