本文整理汇总了Python中twistedcaldav.vcard.Component.fromStream方法的典型用法代码示例。如果您正苦于以下问题:Python Component.fromStream方法的具体用法?Python Component.fromStream怎么用?Python Component.fromStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twistedcaldav.vcard.Component
的用法示例。
在下文中一共展示了Component.fromStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _db_recreate
# 需要导入模块: from twistedcaldav.vcard import Component [as 别名]
# 或者: from twistedcaldav.vcard.Component import fromStream [as 别名]
def _db_recreate(self, do_commit=True):
"""
Re-create the database tables from existing address book data.
"""
#
# Populate the DB with data from already existing resources.
# This allows for index recovery if the DB file gets
# deleted.
#
fp = self.resource.fp
for name in fp.listdir():
if name.startswith("."):
continue
try:
stream = fp.child(name).open()
except (IOError, OSError), e:
log.error("Unable to open resource %s: %s" % (name, e))
continue
try:
# FIXME: This is blocking I/O
try:
vcard = Component.fromStream(stream)
vcard.validVCardData()
vcard.validForCardDAV()
except ValueError:
log.error("Non-addressbook resource: %s" % (name,))
else:
#log.info("Indexing resource: %s" % (name,))
self.addResource(name, vcard, True)
finally:
stream.close()