Did some more string format conversions.

Tue, 27 Jul 2010 09:26:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 27 Jul 2010 09:26:24 +0200
changeset 412
569efd7f2716
parent 411
99409cddaaa9
child 413
3d82e6eb3516

Did some more string format conversions.

E5XML/TasksWriter.py file | annotate | diff | comparison | revisions
E5XML/TemplatesWriter.py file | annotate | diff | comparison | revisions
E5XML/UserProjectWriter.py file | annotate | diff | comparison | revisions
E5XML/XMLEntityResolver.py file | annotate | diff | comparison | revisions
E5XML/XMLWriterBase.py file | annotate | diff | comparison | revisions
--- a/E5XML/TasksWriter.py	Tue Jul 27 09:10:10 2010 +0200
+++ b/E5XML/TasksWriter.py	Tue Jul 27 09:26:24 2010 +0200
@@ -40,19 +40,21 @@
         """
         XMLWriterBase.writeXML(self)
         
-        self._write('<!DOCTYPE Tasks SYSTEM "Tasks-%s.dtd">' % tasksFileFormatVersion)
+        self._write('<!DOCTYPE Tasks SYSTEM "Tasks-{0}.dtd">'.format(
+            tasksFileFormatVersion))
         
         # add some generation comments
         if self.forProject:
-            self._write("<!-- eric5 tasks file for project %s -->" % self.name)
+            self._write("<!-- eric5 tasks file for project {0} -->".format(self.name))
             if Preferences.getProject("XMLTimestamp"):
-                self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
+                self._write("<!-- Saved: {0} -->".format(
+                    time.strftime('%Y-%m-%d, %H:%M:%S')))
         else:
             self._write("<!-- eric5 tasks file -->")
-            self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
+            self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
         
         # add the main tag
-        self._write('<Tasks version="%s">' % tasksFileFormatVersion)
+        self._write('<Tasks version="{0}">'.format(tasksFileFormatVersion))
         
         # do the tasks
         if self.forProject:
@@ -60,19 +62,19 @@
         else:
             tasks = e5App().getObject("TaskViewer").getGlobalTasks()
         for task in tasks:
-            self._write('  <Task priority="%d" completed="%s" bugfix="%s">' % \
-                        (task.priority, task.completed, task.isBugfixTask))
-            self._write('    <Summary>%s</Summary>' % \
-                        self.escape("%s" % task.description.strip()))
-            self._write('    <Description>%s</Description>' % \
-                        self.escape(self.encodedNewLines(task.longtext.strip())))
-            self._write('    <Created>%s</Created>' % \
-                        time.strftime("%Y-%m-%d, %H:%M:%S", time.localtime(task.created)))
+            self._write('  <Task priority="{0:d}" completed="{1}" bugfix="{2}">'\
+                .format(task.priority, task.completed, task.isBugfixTask))
+            self._write('    <Summary>{0}</Summary>'.format(
+                self.escape("{0}".format(task.description.strip()))))
+            self._write('    <Description>{0}</Description>'.format(
+                self.escape(self.encodedNewLines(task.longtext.strip()))))
+            self._write('    <Created>{0}</Created>'.format(
+                time.strftime("%Y-%m-%d, %H:%M:%S", time.localtime(task.created))))
             if task.filename:
                 self._write('    <Resource>')
-                self._write('      <Filename>%s</Filename>' % \
-                    Utilities.fromNativeSeparators(task.filename))
-                self._write('      <Linenumber>%d</Linenumber>' % task.lineno)
+                self._write('      <Filename>{0}</Filename>'.format(
+                    Utilities.fromNativeSeparators(task.filename)))
+                self._write('      <Linenumber>{0:d}</Linenumber>'.format(task.lineno))
                 self._write('    </Resource>')
             self._write('  </Task>')
         
--- a/E5XML/TemplatesWriter.py	Tue Jul 27 09:10:10 2010 +0200
+++ b/E5XML/TemplatesWriter.py	Tue Jul 27 09:26:24 2010 +0200
@@ -32,30 +32,30 @@
         """
         XMLWriterBase.writeXML(self)
         
-        self._write('<!DOCTYPE Templates SYSTEM "Templates-%s.dtd">' % \
-            templatesFileFormatVersion)
+        self._write('<!DOCTYPE Templates SYSTEM "Templates-{0}.dtd">'.format(
+            templatesFileFormatVersion))
         
         # add some generation comments
         self._write("<!-- eric5 templates file -->")
-        self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
+        self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
         
         # add the main tag
-        self._write('<Templates version="%s">' % templatesFileFormatVersion)
+        self._write('<Templates version="{0}">'.format(templatesFileFormatVersion))
         
         # do the template groups
         groups = self.templatesViewer.getAllGroups()
         for group in groups:
-            self._write('  <TemplateGroup name="%s" language="%s">' % \
-                        (group.getName(), group.getLanguage()))
+            self._write('  <TemplateGroup name="{0}" language="{1}">'.format(
+                        group.getName(), group.getLanguage()))
             # do the templates
             templates = group.getAllEntries()
             for template in templates:
-                self._write('    <Template name="%s">' % \
-                    self.escape(template.getName(), True))
-                self._write('      <TemplateDescription>%s</TemplateDescription>' % \
-                    self.escape("%s" % template.getDescription()))
-                self._write('      <TemplateText>%s</TemplateText>' % \
-                    self.escape("%s" % template.getTemplateText()))
+                self._write('    <Template name="{0}">'.format(
+                    self.escape(template.getName(), True)))
+                self._write('      <TemplateDescription>{0}</TemplateDescription>'.format(
+                    self.escape("{0}".format(template.getDescription()))))
+                self._write('      <TemplateText>{0}</TemplateText>'.format(
+                    self.escape("{0}".format(template.getTemplateText()))))
                 self._write('    </Template>')
             self._write('  </TemplateGroup>')
         
--- a/E5XML/UserProjectWriter.py	Tue Jul 27 09:10:10 2010 +0200
+++ b/E5XML/UserProjectWriter.py	Tue Jul 27 09:26:24 2010 +0200
@@ -39,26 +39,26 @@
         """
         XMLWriterBase.writeXML(self)
         
-        self._write('<!DOCTYPE UserProject SYSTEM "UserProject-%s.dtd">' % \
-            userProjectFileFormatVersion)
+        self._write('<!DOCTYPE UserProject SYSTEM "UserProject-{0}.dtd">'.format(
+            userProjectFileFormatVersion))
         
         # add some generation comments
-        self._write("<!-- eric5 user project file for project %s -->" % self.name)
+        self._write("<!-- eric5 user project file for project {0} -->".format(self.name))
         if Preferences.getProject("XMLTimestamp"):
-            self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
-            self._write("<!-- Copyright (C) %s %s, %s -->" % \
-                    (time.strftime('%Y'), 
-                     self.escape(self.pdata["AUTHOR"][0]), 
-                     self.escape(self.pdata["EMAIL"][0])))
+            self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
+            self._write("<!-- Copyright (C) {0} {1}, {2} -->".format(
+                    time.strftime('%Y'), 
+                    self.escape(self.pdata["AUTHOR"][0]), 
+                    self.escape(self.pdata["EMAIL"][0])))
         
         # add the main tag
-        self._write('<UserProject version="%s">' % userProjectFileFormatVersion)
+        self._write('<UserProject version="{0}">'.format(userProjectFileFormatVersion))
         
         # do the vcs override stuff
         if self.pudata["VCSOVERRIDE"]:
-            self._write("  <VcsType>%s</VcsType>" % self.pudata["VCSOVERRIDE"][0])
+            self._write("  <VcsType>{0}</VcsType>".format(self.pudata["VCSOVERRIDE"][0]))
         if self.pudata["VCSSTATUSMONITORINTERVAL"]:
-            self._write('  <VcsStatusMonitorInterval value="%d" />' % \
-                self.pudata["VCSSTATUSMONITORINTERVAL"][0])
+            self._write('  <VcsStatusMonitorInterval value="{0:d}" />'.format(
+                self.pudata["VCSSTATUSMONITORINTERVAL"][0]))
         
-        self._write("</UserProject>", newline = False)
\ No newline at end of file
+        self._write("</UserProject>", newline = False)
--- a/E5XML/XMLEntityResolver.py	Tue Jul 27 09:10:10 2010 +0200
+++ b/E5XML/XMLEntityResolver.py	Tue Jul 27 09:26:24 2010 +0200
@@ -39,7 +39,7 @@
             if not os.path.exists(sId):
                 ind = sId.rfind('-')
                 if ind != -1:
-                    sId = "%s.dtd" % sId[:ind]
+                    sId = "{0}.dtd".format(sId[:ind])
                 if not os.path.exists(sId):
                     sId = ""
         
--- a/E5XML/XMLWriterBase.py	Tue Jul 27 09:10:10 2010 +0200
+++ b/E5XML/XMLWriterBase.py	Tue Jul 27 09:26:24 2010 +0200
@@ -48,7 +48,7 @@
         @param s string to be written to the XML file
         @param newline flag indicating a linebreak
         """
-        self.pf.write("%s%s" % (s, 
+        self.pf.write("{0}{1}".format(s, 
             newline and "\n" or ""))
         
     def writeXML(self):
@@ -104,7 +104,7 @@
         @param value value to be dumped (None) (ignored)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<none />' % ("  " * indent))
+        self._write('{0}<none />'.format("  " * indent))
         
     def _write_int(self, value, indent):
         """
@@ -113,7 +113,7 @@
         @param value value to be dumped (integer)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<int>%s</int>' % ("  " * indent, value))
+        self._write('{0}<int>{1}</int>'.format("  " * indent, value))
         
     def _write_bool(self, value, indent):
         """
@@ -122,7 +122,7 @@
         @param value value to be dumped (boolean)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<bool>%s</bool>' % ("  " * indent, value))
+        self._write('{0}<bool>{1}</bool>'.format("  " * indent, value))
         
     def _write_float(self, value, indent):
         """
@@ -131,7 +131,7 @@
         @param value value to be dumped (float)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<float>%s</float>' % ("  " * indent, value))
+        self._write('{0}<float>{1}</float>'.format("  " * indent, value))
         
     def _write_complex(self, value, indent):
         """
@@ -140,8 +140,8 @@
         @param value value to be dumped (complex)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<complex>%s %s</complex>' % \
-            ("  " * indent, value.real, value.imag))
+        self._write('{0}<complex>{1} {2}</complex>'.format(
+            "  " * indent, value.real, value.imag))
         
     def _write_string(self, value, indent):
         """
@@ -150,7 +150,7 @@
         @param value value to be dumped (string)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<string>%s</string>' % ("  " * indent, self.escape(value)))
+        self._write('{0}<string>{1}</string>'.format("  " * indent, self.escape(value)))
         
     def _write_bytes(self, value, indent):
         """
@@ -159,8 +159,8 @@
         @param value value to be dumped (bytes)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<bytes>%s</bytes>' % (
-            " " * indent, ",".join(["%d" % b for b in value])))
+        self._write('{0}<bytes>{1}</bytes>'.format(
+            " " * indent, ",".join(["{0:d}".format(b) for b in value])))
         
     def _write_bytearray(self, value, indent):
         """
@@ -169,8 +169,8 @@
         @param value value to be dumped (bytearray)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<bytearray>%s</bytearray>' % (
-            " " * indent, ",".join(["%d" % b for b in value])))
+        self._write('{0}<bytearray>{1}</bytearray>'.format(
+            " " * indent, ",".join(["{0:d}".format(b) for b in value])))
         
     def _write_tuple(self, value, indent):
         """
@@ -179,11 +179,11 @@
         @param value value to be dumped (tuple)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<tuple>' % ("  " * indent))
+        self._write('{0}<tuple>'.format("  " * indent))
         nindent = indent + 1
         for elem in value:
             self._writeBasics(elem, nindent)
-        self._write('%s</tuple>' % ("  " * indent))
+        self._write('{0}</tuple>'.format("  " * indent))
         
     def _write_list(self, value, indent):
         """
@@ -192,11 +192,11 @@
         @param value value to be dumped (list)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<list>' % ("  " * indent))
+        self._write('{0}<list>'.format("  " * indent))
         nindent = indent + 1
         for elem in value:
             self._writeBasics(elem, nindent)
-        self._write('%s</list>' % ("  " * indent))
+        self._write('{0}</list>'.format("  " * indent))
         
     def _write_dictionary(self, value, indent):
         """
@@ -205,18 +205,18 @@
         @param value value to be dumped (dictionary)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<dict>' % ("  " * indent))
+        self._write('{0}<dict>'.format("  " * indent))
         nindent1 = indent + 1
         nindent2 = indent + 2
         keys = sorted(list(value.keys()))
         for key in keys:
-            self._write('%s<key>' % ("  " * nindent1))
+            self._write('{0}<key>'.format("  " * nindent1))
             self._writeBasics(key, nindent2)
-            self._write('%s</key>' % ("  " * nindent1))
-            self._write('%s<value>' % ("  " * nindent1))
+            self._write('{0}</key>'.format("  " * nindent1))
+            self._write('{0}<value>'.format("  " * nindent1))
             self._writeBasics(value[key], nindent2)
-            self._write('%s</value>' % ("  " * nindent1))
-        self._write('%s</dict>' % ("  " * indent))
+            self._write('{0}</value>'.format("  " * nindent1))
+        self._write('{0}</dict>'.format("  " * indent))
         
     def _write_set(self, value, indent):
         """
@@ -225,11 +225,11 @@
         @param value value to be dumped (set)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<set>' % ("  " * indent))
+        self._write('{0}<set>'.format("  " * indent))
         nindent = indent + 1
         for elem in value:
             self._writeBasics(elem, nindent)
-        self._write('%s</set>' % ("  " * indent))
+        self._write('{0}</set>'.format("  " * indent))
         
     def _write_frozenset(self, value, indent):
         """
@@ -238,11 +238,11 @@
         @param value value to be dumped (frozenset)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<frozenset>' % ("  " * indent))
+        self._write('{0}<frozenset>'.format("  " * indent))
         nindent = indent + 1
         for elem in value:
             self._writeBasics(elem, nindent)
-        self._write('%s</frozenset>' % ("  " * indent))
+        self._write('{0}</frozenset>'.format("  " * indent))
         
     def _write_unimplemented(self, value, indent):
         """
@@ -251,5 +251,5 @@
         @param value value to be dumped (any pickleable object)
         @param indent indentation level for prettier output (integer)
         """
-        self._write('%s<pickle method="pickle" encoding="base64">%s</pickle>' % \
-            ("  " * indent, str(base64.b64encode(pickle.dumps(value)), "ASCII")))
+        self._write('{0}<pickle method="pickle" encoding="base64">{1}</pickle>'.format(
+            "  " * indent, str(base64.b64encode(pickle.dumps(value)), "ASCII")))

eric ide

mercurial