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


Python Autoload.get_by_regexp方法代碼示例

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


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

示例1: get_by_regexp

# 需要導入模塊: from Pyblio import Autoload [as 別名]
# 或者: from Pyblio.Autoload import get_by_regexp [as 別名]
def get_by_regexp (entity, method):
    ''' returns a specific field of the given entity '''

    meth = Autoload.get_by_regexp ("format", entity)

    if meth and meth.data.has_key (method):
	return meth.data [method]

    return None
開發者ID:GNOME,項目名稱:pybliographer,代碼行數:11,代碼來源:Open.py

示例2: bibopen

# 需要導入模塊: from Pyblio import Autoload [as 別名]
# 或者: from Pyblio.Autoload import get_by_regexp [as 別名]
def bibopen (entity, how = None):
    ''' Generic function to open a bibliographic database '''

    def simple_try (url, how):
	# url is Fields.URL instance, only to be passed to opener
	base = None

	if how == None:
	    listedmethods = Autoload.available ("format")

	    for method in listedmethods:
		opener = get_by_name (method, 'open')
		if opener:
		    base = opener (url, 1)
		    if base is not None:
			return base
	    return None

	opener = get_by_name (how, 'open')

	if opener:
	    base = opener (url, 0)
	else:
	    raise Exceptions.FormatError (_(u"method “%s” provides no opener") % how)

	return base

    # Consider the reference as an URL: url is an Fields.URL instance
    url = Fields.URL (entity)

    if url.url [0] == 'file' and not os.path.exists (url.url [2]):
	raise Exceptions.FileError (_(u"File “%s” does not exist") % url.get_url ())

    # eventually load a new module
    if how is None:
	handler = Autoload.get_by_regexp ("format", url.get_url ())
	if handler:
	    how = handler.name

    base = simple_try (url, how)

    if base is None:
	raise Exceptions.FormatError (_(u"don’t know how to open “%s”") % entity)

    return base
開發者ID:GNOME,項目名稱:pybliographer,代碼行數:47,代碼來源:Open.py


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