本文整理汇总了Python中twistedcaldav.xmlutil.readXML函数的典型用法代码示例。如果您正苦于以下问题:Python readXML函数的具体用法?Python readXML怎么用?Python readXML使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readXML函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _doModifyInFile
def _doModifyInFile(self, xmlfile, records):
if not os.path.exists(xmlfile):
return
_ignore_etree, augments_node = readXML(xmlfile)
# Map uid->record for fast lookup
recordMap = dict([(record.uid, record) for record in records])
# Make sure UID is present
changed = False
for record_node in augments_node.getchildren():
if record_node.tag != xmlaugmentsparser.ELEMENT_RECORD:
continue
uid = record_node.find(xmlaugmentsparser.ELEMENT_UID).text
if uid in recordMap:
# Modify record
record = recordMap[uid]
del record_node.getchildren()[:]
addSubElement(record_node, xmlaugmentsparser.ELEMENT_UID, record.uid)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLE, "true" if record.enabled else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_HOSTEDAT, record.hostedAt)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if record.enabledForCalendaring else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true" if record.enabledForAddressBooks else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if record.autoSchedule else "false")
changed = True
# Modify xmlfile
if changed:
writeXML(xmlfile, augments_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:34,代码来源:augment.py
示例2: _doModifyInFile
def _doModifyInFile(self, xmlfile, records):
if not os.path.exists(xmlfile):
return
_ignore_etree, augments_node = readXML(xmlfile)
# Map uid->record for fast lookup
recordMap = dict([(record.uid, record) for record in records])
# Make sure UID is present
changed = False
for record_node in augments_node:
if record_node.tag != xmlaugmentsparser.ELEMENT_RECORD:
continue
uid = record_node.find(xmlaugmentsparser.ELEMENT_UID).text
if uid in recordMap:
# Modify record
record = recordMap[uid]
self._updateRecordInXMLDB(record, record_node)
changed = True
# Modify xmlfile
if changed:
writeXML(xmlfile, augments_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:27,代码来源:augment.py
示例3: __init__
def __init__(self, xmlFile):
self.servers = []
# Read in XML
_ignore_etree, servers_node = xmlutil.readXML(xmlFile.path, ELEMENT_SERVERS)
self._parseXML(servers_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:7,代码来源:remoteservers.py
示例4: parse
def parse(xmlFile, ignoreIPLookupFailures=False):
results = {}
# Read in XML
try:
_ignore_tree, servers_node = readXML(xmlFile, ELEMENT_SERVERS)
except ValueError, e:
raise RuntimeError("XML parse error for '{}' because: {}".format(xmlFile, e,))
开发者ID:nunb,项目名称:calendarserver,代码行数:9,代码来源:localservers.py
示例5: parse
def parse(xmlFile, ignoreIPLookupFailures=False):
results = {}
# Read in XML
try:
_ignore_tree, servers_node = readXML(xmlFile, ELEMENT_SERVERS)
except ValueError, e:
log.error("XML parse error for '%s' because: %s" % (xmlFile, e,), raiseException=RuntimeError)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:9,代码来源:localservers.py
示例6: __init__
def __init__(self, xmlFile):
self.items = []
self.xmlFile = fullServerPath(config.DataRoot, xmlFile)
# Read in XML
try:
_ignore_tree, proxies_node = readXML(self.xmlFile, ELEMENT_PROXIES)
except ValueError, e:
log.error("XML parse error for '%s' because: %s" % (self.xmlFile, e,), raiseException=RuntimeError)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:10,代码来源:calendaruserproxyloader.py
示例7: __init__
def __init__(self, xmlFile, items):
self.items = items
self.xmlFile = xmlFile
# Read in XML
try:
_ignore_tree, augments_node = readXML(self.xmlFile, ELEMENT_AUGMENTS)
except ValueError, e:
raise RuntimeError("XML parse error for '%s' because: %s" % (self.xmlFile, e,))
开发者ID:anemitz,项目名称:calendarserver,代码行数:10,代码来源:xmlaugmentsparser.py
示例8: uidsFromFile
def uidsFromFile(self, filename):
"""
Return all uids from the augments xml file
"""
_ignore_etree, augments_node = readXML(filename)
for record_node in augments_node:
if record_node.tag != xmlaugmentsparser.ELEMENT_RECORD:
continue
uid = record_node.find(xmlaugmentsparser.ELEMENT_UID).text
yield uid
开发者ID:nunb,项目名称:calendarserver,代码行数:11,代码来源:test_augment.py
示例9: readDatabase
def readDatabase(self):
"""
Read in XML data.
"""
_ignore, root = xmlutil.readXML(self.xmlfile, "timezones")
self.dtstamp = root.findtext("dtstamp")
for child in root:
if child.tag == "timezone":
tz = TimezoneInfo.readXML(child)
if tz:
self.timezones[tz.tzid] = tz
for alias in tz.aliases:
self.aliases[alias] = tz.tzid
开发者ID:anemitz,项目名称:calendarserver,代码行数:13,代码来源:timezonestdservice.py
示例10: __init__
def __init__(self, xmlFile):
self.items = []
self.xmlFile = fullServerPath(config.DataRoot, xmlFile)
# Read in XML
try:
_ignore_tree, proxies_node = readXML(self.xmlFile, ELEMENT_PROXIES)
except ValueError:
log.failure("XML parse error for proxy data file {xmlfile}", xmlfile=self.xmlFile)
# FIXME: RuntimeError is dumb.
self._parseXML(proxies_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:13,代码来源:calendaruserproxyloader.py
示例11: _doAddToFile
def _doAddToFile(self, xmlfile, records):
if not os.path.exists(xmlfile):
# File doesn't yet exist. Create it with items in self.db, and
# set file permissions.
_ignore_etree, augments_node = newElementTreeWithRoot(xmlaugmentsparser.ELEMENT_AUGMENTS)
for record in self.db.itervalues():
record_node = addSubElement(augments_node, xmlaugmentsparser.ELEMENT_RECORD)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_UID, record.uid)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLE, "true" if record.enabled else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_HOSTEDAT, record.hostedAt)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if record.enabledForCalendaring else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true" if record.enabledForAddressBooks else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if record.autoSchedule else "false")
writeXML(xmlfile, augments_node)
# Set permissions
uid = -1
if config.UserName:
try:
uid = pwd.getpwnam(config.UserName).pw_uid
except KeyError:
log.error("User not found: %s" % (config.UserName,))
gid = -1
if config.GroupName:
try:
gid = grp.getgrnam(config.GroupName).gr_gid
except KeyError:
log.error("Group not found: %s" % (config.GroupName,))
if uid != -1 and gid != -1:
os.chown(xmlfile, uid, gid)
_ignore_etree, augments_node = readXML(xmlfile)
# Create new record
for record in records:
record_node = addSubElement(augments_node, xmlaugmentsparser.ELEMENT_RECORD)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_UID, record.uid)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLE, "true" if record.enabled else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_HOSTEDAT, record.hostedAt)
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLECALENDAR, "true" if record.enabledForCalendaring else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_ENABLEADDRESSBOOK, "true" if record.enabledForAddressBooks else "false")
addSubElement(record_node, xmlaugmentsparser.ELEMENT_AUTOSCHEDULE, "true" if record.autoSchedule else "false")
# Modify xmlfile
writeXML(xmlfile, augments_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:51,代码来源:augment.py
示例12: _doRemoveFromFile
def _doRemoveFromFile(self, xmlfile, uids):
_ignore_etree, augments_node = readXML(xmlfile)
# Remove all UIDs present
changed = False
for child in augments_node:
if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
continue
if child.find(xmlaugmentsparser.ELEMENT_UID).text in uids:
augments_node.remove(child)
changed = True
# Modify xmlfile
if changed:
writeXML(xmlfile, augments_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:17,代码来源:augment.py
示例13: __init__
def __init__(self, xmlFile, externalUpdate=True):
if type(xmlFile) is str:
xmlFile = FilePath(xmlFile)
self.xmlFile = xmlFile
self.realm = None
self.items = {}
for recordType in RECORD_TYPES.values():
self.items[recordType] = {}
# Read in XML
try:
_ignore_tree, accounts_node = readXML(self.xmlFile.path, ELEMENT_ACCOUNTS)
except ValueError, e:
log.error("XML parse error for '%s' because: %s" % (self.xmlFile, e,), raiseException=RuntimeError)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:17,代码来源:xmlaccountsparser.py
示例14: _doRemoveFromFile
def _doRemoveFromFile(self, xmlfile, uids):
try:
_ignore_etree, augments_node = readXML(xmlfile)
except IOError:
# If the file is missing, then removal is a no-op
return
# Remove all UIDs present
changed = False
for child in augments_node:
if child.tag != xmlaugmentsparser.ELEMENT_RECORD:
continue
if child.find(xmlaugmentsparser.ELEMENT_UID).text in uids:
augments_node.remove(child)
changed = True
# Modify xmlfile
if changed:
writeXML(xmlfile, augments_node)
开发者ID:eventable,项目名称:CalendarServer,代码行数:21,代码来源:augment.py
示例15: _doAddToFile
def _doAddToFile(self, xmlfile, records):
if not os.path.exists(xmlfile):
# File doesn't yet exist. Create it with items in self.db, and
# set file permissions.
_ignore_etree, augments_node = newElementTreeWithRoot(xmlaugmentsparser.ELEMENT_AUGMENTS)
for record in self.db.itervalues():
self._addRecordToXMLDB(record, augments_node)
writeXML(xmlfile, augments_node)
# Set permissions
uid = -1
if config.UserName:
try:
uid = pwd.getpwnam(config.UserName).pw_uid
except KeyError:
log.error("User not found: %s" % (config.UserName,))
gid = -1
if config.GroupName:
try:
gid = grp.getgrnam(config.GroupName).gr_gid
except KeyError:
log.error("Group not found: %s" % (config.GroupName,))
if uid != -1 and gid != -1:
os.chown(xmlfile, uid, gid)
_ignore_etree, augments_node = readXML(xmlfile)
# Create new record
for record in records:
self._addRecordToXMLDB(record, augments_node)
# Modify xmlfile
writeXML(xmlfile, augments_node)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:39,代码来源:augment.py
示例16: test_readXML_verify_ok
def test_readXML_verify_ok(self):
io = StringIO(XMLUtil.data1)
etree, root = readXML(io, expectedRootTag="test")
self.assertEqual(etree.getroot(), root)
self.assertEqual(root.tag, "test")
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:6,代码来源:test_xmlutil.py
示例17: test_readXML_noverify
def test_readXML_noverify(self):
io = StringIO(XMLUtil.data1)
etree, root = readXML(io)
self.assertEqual(etree.getroot(), root)
self.assertEqual(root.tag, "test")
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:6,代码来源:test_xmlutil.py
示例18: test_changeElement_new
def test_changeElement_new(self):
io = StringIO(XMLUtil.data1)
_ignore_etree, root = readXML(io)
changeSubElementText(root, "new", "new text")
self._checkXML(root, XMLUtil.data6)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:6,代码来源:test_xmlutil.py
示例19: test_changeElement_existing
def test_changeElement_existing(self):
io = StringIO(XMLUtil.data1)
_ignore_etree, root = readXML(io)
changeSubElementText(root, "help", "changed text")
self._checkXML(root, XMLUtil.data5)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:6,代码来源:test_xmlutil.py
示例20: test_addElement
def test_addElement(self):
io = StringIO(XMLUtil.data1)
_ignore_etree, root = readXML(io)
addSubElement(root, "added", "added text")
self._checkXML(root, XMLUtil.data4)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:6,代码来源:test_xmlutil.py
注:本文中的twistedcaldav.xmlutil.readXML函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论