本文整理汇总了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