本文整理匯總了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
示例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