當前位置: 首頁>>代碼示例>>Python>>正文


Python X.resumptionToken方法代碼示例

本文整理匯總了Python中invenio.utils.html.X.resumptionToken方法的典型用法代碼示例。如果您正苦於以下問題:Python X.resumptionToken方法的具體用法?Python X.resumptionToken怎麽用?Python X.resumptionToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在invenio.utils.html.X的用法示例。


在下文中一共展示了X.resumptionToken方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: oai_list_records_or_identifiers

# 需要導入模塊: from invenio.utils.html import X [as 別名]
# 或者: from invenio.utils.html.X import resumptionToken [as 別名]
def oai_list_records_or_identifiers(req, argd):
    """Generates response to oai_list_records verb."""

    verb = argd['verb']
    resumption_token_was_specified = False

    # check if the resumption_token did not expire
    if argd.get('resumptionToken'):
        resumption_token_was_specified = True
        try:
            cache = oai_cache_load(argd['resumptionToken'])
            last_recid = cache['last_recid']
            argd = cache['argd']
            complete_list = cache['complete_list']
            complete_list = filter_out_based_on_date_range(complete_list, argd.get('from', ''), argd.get('until', ''))
        except Exception:
            register_exception(alert_admin=True)
            req.write(oai_error(argd, [("badResumptionToken", "ResumptionToken expired or invalid: %s" % argd['resumptionToken'])]))
            return
    else:
        last_recid = 0
        complete_list = oai_get_recid_list(argd.get('set', ""), argd.get('from', ""), argd.get('until', ""))

        if not complete_list: # noRecordsMatch error
            req.write(oai_error(argd, [("noRecordsMatch", "no records correspond to the request")]))
            return

    cursor = 0
    for cursor, recid in enumerate(complete_list):
        ## Let's fast-forward the cursor to point after the last recid that was
        ## disseminated successfully
        if recid > last_recid:
            break

    set_last_updated = get_set_last_update(argd.get('set', ""))

    req.write(oai_header(argd, verb))
    for recid in list(complete_list)[cursor:cursor+CFG_OAI_LOAD]:
        req.write(print_record(recid, argd['metadataPrefix'], verb=verb, set_spec=argd.get('set'), set_last_updated=set_last_updated))

    if list(complete_list)[cursor+CFG_OAI_LOAD:]:
        resumption_token = oai_generate_resumption_token(argd.get('set', ''))
        cache = {
            'argd': argd,
            'last_recid': recid,
            'complete_list': complete_list.fastdump(),
        }
        oai_cache_dump(resumption_token, cache)
        expdate = oai_get_response_date(CFG_OAI_EXPIRE)
        req.write(X.resumptionToken(expirationDate=expdate, cursor=cursor, completeListSize=len(complete_list))(resumption_token))
    elif resumption_token_was_specified:
        ## Since a resumptionToken was used we shall put a last empty resumptionToken
        req.write(X.resumptionToken(cursor=cursor, completeListSize=len(complete_list))(""))
    req.write(oai_footer(verb))
    oai_cache_gc()
開發者ID:mhellmic,項目名稱:b2share,代碼行數:57,代碼來源:server.py

示例2: list

# 需要導入模塊: from invenio.utils.html import X [as 別名]
# 或者: from invenio.utils.html.X import resumptionToken [as 別名]
        )

    if list(complete_list)[cursor + CFG_OAI_LOAD :]:
        resumption_token = oai_generate_resumption_token(argd.get("set", ""))
        cache = {
            "argd": argd,
            "last_recid": recid,
            # FIXME introduce IP check if you use fireroles for guests
            "id_user": current_user.get_id(),
            "complete_list": complete_list.fastdump(),
        }
        oai_cache_dump(resumption_token, cache)
        expdate = oai_get_response_date(CFG_OAI_EXPIRE)
        req.write(
            X.resumptionToken(expirationDate=expdate, cursor=cursor, completeListSize=len(complete_list))(
                resumption_token
            )
        )
    elif resumption_token_was_specified:
        ## Since a resumptionToken was used we shall put a last empty resumptionToken
        req.write(X.resumptionToken(cursor=cursor, completeListSize=len(complete_list))(""))
    req.write(oai_footer(verb))
    oai_cache_gc()


def oai_list_sets(argd):
    """
    Lists available sets for OAI metadata harvesting.
    """

    out = ""
開發者ID:CharlotteIrisC,項目名稱:invenio,代碼行數:33,代碼來源:server.py


注:本文中的invenio.utils.html.X.resumptionToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。