本文整理汇总了Python中zoundry.base.zdom.dom.ZDom.save方法的典型用法代码示例。如果您正苦于以下问题:Python ZDom.save方法的具体用法?Python ZDom.save怎么用?Python ZDom.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zoundry.base.zdom.dom.ZDom
的用法示例。
在下文中一共展示了ZDom.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _serializeResponseInfo
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
def _serializeResponseInfo(self, metaFile, connectionRespInfo, dataFilename):
dom = ZDom()
dom.loadXML(u"""<http-connection-response />""") #$NON-NLS-1$
rootElem = dom.documentElement
urlElem = dom.createElement(u"url") #$NON-NLS-1$
urlElem.setText(connectionRespInfo.getURL())
rootElem.appendChild(urlElem)
dataFileElem = dom.createElement(u"data-file") #$NON-NLS-1$
dataFileElem.setText(dataFilename)
rootElem.appendChild(dataFileElem)
respCodeElem = dom.createElement(u"response-code") #$NON-NLS-1$
respCodeElem.setText(unicode(connectionRespInfo.getCode()))
rootElem.appendChild(respCodeElem)
respMsgElem = dom.createElement(u"response-message") #$NON-NLS-1$
respMsgElem.setText(unicode(connectionRespInfo.getMessage()))
rootElem.appendChild(respMsgElem)
headersElem = dom.createElement(u"response-headers") #$NON-NLS-1$
rootElem.appendChild(headersElem)
for headerName in connectionRespInfo.getHeaders():
headerVal = connectionRespInfo.getHeader(headerName)
headerElem = dom.createElement(u"header") #$NON-NLS-1$
headerElem.setAttribute(u"name", headerName) #$NON-NLS-1$
headerElem.setText(headerVal)
headersElem.appendChild(headerElem)
dom.save(metaFile, True)
示例2: __init__
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
class ZSystemProperties:
u"""Use this class to get and set System Properties.""" #$NON-NLS-1$
def __init__(self, sysPropsFileName):
# create a lock for thread synchronization
self.lock = ZMutex(u"ZSystemProperties") #$NON-NLS-1$
self.listeners = ZListenerSet()
self.sysPropsFileName = sysPropsFileName
self.sysPropsDoc = ZDom()
self.reloadProperties()
# end __init__()
def addListener(self, listener):
self.listeners.append(listener)
# end addListener()
def removeListener(self, listener):
self.listeners.remove(listener)
# end removeListener
def _fireEvent(self, key, value):
for listener in self.listeners:
listener.onSystemPropertyChange(key, value)
# end _fireEvent()
def reloadProperties(self):
self.lock.acquire()
try:
# Open and parse the system properties file
self.sysPropsDoc.load(self.sysPropsFileName)
finally:
self.lock.release()
# end reloadProperties()
# Public method - call this to save the system properties.
def save(self):
u"Public method - call this to save the system properties." #$NON-NLS-1$
self.lock.acquire()
self.saveProperties()
self.lock.release()
self._fireEvent(None, None)
# end save()
# Note that locking is required prior to calling saveProperties()
def saveProperties(self):
try:
tempSysPropsFileName = self.sysPropsFileName + u".t" #$NON-NLS-1$
self.sysPropsDoc.save(tempSysPropsFileName, True)
deleteFile(self.sysPropsFileName)
renameFile(tempSysPropsFileName, self.sysPropsFileName)
except Exception, e:
raise ZException(_extstr(u"sysprops.ErrorSavingPropsFile") % self.sysPropsFileName, e) #$NON-NLS-1$
示例3: serialize
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
def serialize(self, spellChecker, path):
u"""serialize(ZSpellChecker, string) -> None
Serializes a spell checker to a string. The path is a directory.""" #$NON-NLS-1$
dom = ZDom()
dom.loadXML(u"""<spellchecker xmlns="%s" />""" % IZAppNamespaces.RAVEN_SPELLCHECKER_NAMESPACE) #$NON-NLS-1$
spellCheckerElem = dom.documentElement
self._serializeDictionaryLanguage(spellCheckerElem, spellChecker.dictionaryLang)
self._serializeProvider(spellCheckerElem, spellChecker.provider)
self._serializePersonalDictionary(spellCheckerElem, spellChecker.personalWordList)
self._serializeAutoCorrections(spellCheckerElem, spellChecker.autoCorrections)
if not os.path.isdir(path):
os.makedirs(path)
filePath = os.path.join(path, u"spellchecker.xml") #$NON-NLS-1$
dom.save(filePath, True)
示例4: _save
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
def _save(self):
if not self.registryFile:
return
mediaStorageDir = os.path.basename(self.registryFile)
dom = ZDom()
dom.loadXML(u"<registry/>") #$NON-NLS-1$
registryElem = dom.documentElement
for fileName in self.fileMap:
(size, timestamp, uploadResponse) = self.fileMap[fileName]
relativeFileName = makeRelativePath(mediaStorageDir, fileName)
url = uploadResponse.getUrl()
embedFragment = uploadResponse.getEmbedFragment()
metaData = uploadResponse.getMetaData()
entryElem = dom.createElement(u"entry") #$NON-NLS-1$
entryElem.setAttribute(u"size", unicode(size)) #$NON-NLS-1$
entryElem.setAttribute(u"timestamp", unicode(timestamp)) #$NON-NLS-1$
fileElem = dom.createElement(u"file") #$NON-NLS-1$
urlElem = dom.createElement(u"url") #$NON-NLS-1$
embedElem = dom.createElement(u"embed") #$NON-NLS-1$
metaDataElem = dom.createElement(u"metaData") #$NON-NLS-1$
# When in portable mode, save the file paths as relative (which will
# only happen when the image is on the same drive as the app).
if isPortableEnabled():
fileElem.setText(relativeFileName)
else:
fileElem.setText(fileName)
entryElem.appendChild(fileElem)
if url:
urlElem.setText(unicode(url))
entryElem.appendChild(urlElem)
if embedFragment is not None:
embedElem.appendChild(dom.importNode(embedFragment, True))
entryElem.appendChild(embedElem)
if metaData is not None:
metaDataElem.appendChild(dom.importNode(metaData, True))
entryElem.appendChild(metaDataElem)
registryElem.appendChild(entryElem)
dom.save(self.registryFile, True)
示例5: importPersonalDictionary
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
def importPersonalDictionary(self):
joeyConfigDom = self._getJoeyUserConfigDom()
if not joeyConfigDom:
return
try:
node = joeyConfigDom.selectSingleNode(u"/joey/user-config/spell-check/language") #$NON-NLS-1$
if not node:
return
spellcheckLang = getNoneString( node.getText())
if not spellcheckLang:
return
# FIXME (EPW) we could support other languages...
if not spellcheckLang == u"en_US": #$NON-NLS-1$
return
# 1) read all words from ZBW personal-dictionary.xml file
# 2) create new spellchecker.xml DOM
# 3) save new Raven spellchecker file to 'PROFILE\LANG\spellchecker.xml'
joeyDictFile = os.path.join(self.pathToJoeyProfile, u"spelling/personal-dictionary.xml") #$NON-NLS-1$
dom = ZDom()
dom.load(joeyDictFile)
dom.setNamespaceMap(ZBW_PERSONAL_DICTIONARY_NSS_MAP)
wordNodeList = dom.selectNodes(u"/pd:personal-dictionary/pd:word") #$NON-NLS-1$
newDom = ZDom()
newDom.loadXML(ZBlogWriterDictionaryImporter.SPELLCHECK_TEMPLATE)
newDom.setNamespaceMap(RAVEN_SPELLCHECK_NSS_MAP)
personalDictElem = newDom.selectSingleNode(u"/spl:spellchecker/spl:personal-dictionary") #$NON-NLS-1$
for wordNode in wordNodeList:
word = wordNode.getText()
newWordElem = newDom.createElement(u"word", IZBlogAppNamespaces.RAVEN_SPELLCHECKER_NAMESPACE) #$NON-NLS-1$
newWordElem.setText(word)
personalDictElem.appendChild(newWordElem)
outputDir = os.path.join(self.pathToRavenProfile, u"spellcheck/en_US") #$NON-NLS-1$
os.makedirs(outputDir)
outputFile = os.path.join(outputDir, u"spellchecker.xml") #$NON-NLS-1$
newDom.save(outputFile, True)
except ZException, ze:
# FIXME (EPW) need to report errors in some way
ze.printStackTrace()
示例6: save
# 需要导入模块: from zoundry.base.zdom.dom import ZDom [as 别名]
# 或者: from zoundry.base.zdom.dom.ZDom import save [as 别名]
def save(self, defaultTranslation):
self._journal(u"--save--") #$NON-NLS-1$
localeStr = self.locale.toString()
baseFileName = os.path.join(self.bundleDirectory, u"zoundry.base_%s.xml" % localeStr) #$NON-NLS-1$
appFrameworkFileName = os.path.join(self.bundleDirectory, u"zoundry.appframework_%s.xml" % localeStr) #$NON-NLS-1$
blogAppFileName = os.path.join(self.bundleDirectory, u"zoundry.blogapp_%s.xml" % localeStr) #$NON-NLS-1$
if DEBUG:
outputLogFileName = os.path.join(self.bundleDirectory, u"debug_save_%s.log" % localeStr) #$NON-NLS-1$
outputLog = open(outputLogFileName, u"w") #$NON-NLS-1$
self.debug(outputLog, u"Saving translation") #$NON-NLS-1$
try:
baseDom = ZDom()
baseDom.loadXML(BUNDLE_TEMPLATE % localeStr)
baseDom.documentElement.addTextNode(u"\n") #$NON-NLS-1$
self.debug(outputLog, u"baseDom created") #$NON-NLS-1$
appFrameworkDom = ZDom()
appFrameworkDom.loadXML(BUNDLE_TEMPLATE % localeStr)
appFrameworkDom.documentElement.addTextNode(u"\n") #$NON-NLS-1$
self.debug(outputLog, u"appFrameworkDom created") #$NON-NLS-1$
blogAppDom = ZDom()
blogAppDom.loadXML(BUNDLE_TEMPLATE % localeStr)
blogAppDom.documentElement.addTextNode(u"\n") #$NON-NLS-1$
self.debug(outputLog, u"blogAppDom created") #$NON-NLS-1$
bundleStrings = self.getBundleStrings()
keys = bundleStrings.keys()
keys.sort()
for key in keys:
self.debug(outputLog, u"Writing key: %s" % key) #$NON-NLS-1$
try:
value = bundleStrings[key]
dom = None
if key in defaultTranslation.getBaseKeys():
dom = baseDom
elif key in defaultTranslation.getAppFrameworkKeys():
dom = appFrameworkDom
elif key in defaultTranslation.getBlogAppKeys():
dom = blogAppDom
elem = dom.documentElement
stringElem = dom.createElement(u"zb:string", BUNDLE_NS) #$NON-NLS-1$
stringElem.setAttribute(u"name", key) #$NON-NLS-1$
stringElem.setText(value)
elem.addTextNode(u" ") #$NON-NLS-1$
elem.appendChild(stringElem)
elem.addTextNode(u"\n") #$NON-NLS-1$
except Exception, e:
getLoggerService().exception(e)
self.debug(outputLog, u"Done writing key: %s" % key) #$NON-NLS-1$
self.debug(outputLog, u"Done writing all keys.") #$NON-NLS-1$
self.debug(outputLog, u"Backing up old translations.") #$NON-NLS-1$
backup_baseFileName = os.path.join(self.bundleDirectory, u"BACKUP_zoundry.base_%s.xml" % self.locale.toString()) #$NON-NLS-1$
backup_appFrameworkFileName = os.path.join(self.bundleDirectory, u"BACKUP_zoundry.appframework_%s.xml" % self.locale.toString()) #$NON-NLS-1$
backup_blogAppFileName = os.path.join(self.bundleDirectory, u"BACKUP_zoundry.blogapp_%s.xml" % self.locale.toString()) #$NON-NLS-1$
if os.path.exists(baseFileName):
shutil.copy2(baseFileName, backup_baseFileName)
if os.path.exists(appFrameworkFileName):
shutil.copy2(appFrameworkFileName, backup_appFrameworkFileName)
if os.path.exists(blogAppFileName):
shutil.copy2(blogAppFileName, backup_blogAppFileName)
self.debug(outputLog, u"Saving DOMs") #$NON-NLS-1$
baseDom.save(baseFileName)
self.debug(outputLog, u"Successfully saved baseDom") #$NON-NLS-1$
appFrameworkDom.save(appFrameworkFileName)
self.debug(outputLog, u"Successfully saved appFrameworkDom") #$NON-NLS-1$
blogAppDom.save(blogAppFileName)
self.debug(outputLog, u"Successfully saved blogAppDom") #$NON-NLS-1$
deleteFile(backup_baseFileName)
deleteFile(backup_appFrameworkFileName)
deleteFile(backup_blogAppFileName)
self.debug(outputLog, u"Deleted backup files.") #$NON-NLS-1$