Did some more string format conversions.

Thu, 29 Jul 2010 17:25:00 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 29 Jul 2010 17:25:00 +0200
changeset 429
dcc623c99907
parent 428
58405c24aa09
child 431
96cc7d322f89

Did some more string format conversions.

QScintilla/Editor.py file | annotate | diff | comparison | revisions
QScintilla/Exporters/ExporterHTML.py file | annotate | diff | comparison | revisions
QScintilla/Exporters/ExporterPDF.py file | annotate | diff | comparison | revisions
QScintilla/Exporters/ExporterRTF.py file | annotate | diff | comparison | revisions
QScintilla/Exporters/ExporterTEX.py file | annotate | diff | comparison | revisions
--- a/QScintilla/Editor.py	Thu Jul 29 11:02:09 2010 +0200
+++ b/QScintilla/Editor.py	Thu Jul 29 17:25:00 2010 +0200
@@ -1246,7 +1246,7 @@
         @param act reference to the action that was triggered (QAction)
         """
         encoding = act.data()
-        self.__encodingChanged("%s-selected" % encoding)
+        self.__encodingChanged("{0}-selected".format(encoding))
         
     def __checkEncoding(self):
         """
@@ -1346,7 +1346,7 @@
             return
         
         if pyname:
-            self.apiLanguage = "Pygments|%s" % pyname
+            self.apiLanguage = "Pygments|{0}".format(pyname)
         else:
             self.apiLanguage = self.lexer_.language()
             if self.apiLanguage == "POV":
@@ -1358,7 +1358,7 @@
             self.connect(self, SIGNAL("SCN_STYLENEEDED(int)"), self.__styleNeeded)
         
         # get the font for style 0 and set it as the default font
-        key = 'Scintilla/%s/style0/font' % self.lexer_.language()
+        key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
         fdesc = Preferences.Prefs.settings.value(key)
         if fdesc is not None:
             font = QFont(fdesc[0], int(fdesc[1]))
@@ -2306,7 +2306,7 @@
         if createBackup:
             if os.path.islink(fn):
                 fn = os.path.realpath(fn)
-            bfn = '%s~' % fn
+            bfn = '{0}~'.format(fn)
             try:
                 permissions = os.stat(fn).st_mode
                 perms_valid = True
@@ -2551,7 +2551,7 @@
         if wc is None or not useWordChars:
             regExp = QRegExp('[^\w_]', cs)
         else:
-            regExp = QRegExp('[^%s]' % re.escape(wc), cs)
+            regExp = QRegExp('[^{0}]'.format(re.escape(wc)), cs)
         start = regExp.lastIndexIn(text, index) + 1
         end = regExp.indexIn(text, index)
         if start == end + 1 and index > 0:
@@ -3833,11 +3833,11 @@
                 basename = os.path.splitext(fn)[0]
                 tbasename = os.path.splitext(tfn)[0]
                 prEnable = prEnable or \
-                    os.path.isfile("%s.profile" % basename) or \
-                    os.path.isfile("%s.profile" % tbasename)
+                    os.path.isfile("{0}.profile".format(basename)) or \
+                    os.path.isfile("{0}.profile".format(tbasename))
                 coEnable = coEnable or \
-                    os.path.isfile("%s.coverage" % basename) or \
-                    os.path.isfile("%s.coverage" % tbasename)
+                    os.path.isfile("{0}.coverage".format(basename)) or \
+                    os.path.isfile("{0}.coverage".format(tbasename))
         
         # now check ourself
         fn = self.getFileName()
@@ -3846,11 +3846,11 @@
             basename = os.path.splitext(fn)[0]
             tbasename = os.path.splitext(tfn)[0]
             prEnable = prEnable or \
-                os.path.isfile("%s.profile" % basename) or \
-                os.path.isfile("%s.profile" % tbasename)
+                os.path.isfile("{0}.profile".format(basename)) or \
+                os.path.isfile("{0}.profile".format(tbasename))
             coEnable = coEnable or \
-                os.path.isfile("%s.coverage" % basename) or \
-                os.path.isfile("%s.coverage" % tbasename)
+                os.path.isfile("{0}.coverage".format(basename)) or \
+                os.path.isfile("{0}.coverage".format(tbasename))
         
         # now check for syntax errors
         if self.hasSyntaxErrors():
@@ -4111,8 +4111,8 @@
                 basename = os.path.splitext(fn)[0]
                 tbasename = os.path.splitext(tfn)[0]
                 
-                f = "%s.coverage" % basename
-                tf = "%s.coverage" % tbasename
+                f = "{0}.coverage".format(basename)
+                tf = "{0}.coverage".format(tbasename)
                 if os.path.isfile(f):
                     files.append(f)
                 if os.path.isfile(tf):
@@ -4125,8 +4125,8 @@
             basename = os.path.splitext(fn)[0]
             tbasename = os.path.splitext(tfn)[0]
             
-            f = "%s.coverage" % basename
-            tf = "%s.coverage" % tbasename
+            f = "{0}.coverage".format(basename)
+            tf = "{0}.coverage".format(tbasename)
             if os.path.isfile(f) and not f in files:
                 files.append(f)
             if os.path.isfile(tf) and not tf in files:
@@ -4249,8 +4249,8 @@
                 basename = os.path.splitext(fn)[0]
                 tbasename = os.path.splitext(tfn)[0]
                 
-                f = "%s.profile" % basename
-                tf = "%s.profile" % tbasename
+                f = "{0}.profile".format(basename)
+                tf = "{0}.profile".format(tbasename)
                 if os.path.isfile(f):
                     files.append(f)
                 if os.path.isfile(tf):
@@ -4263,8 +4263,8 @@
             basename = os.path.splitext(fn)[0]
             tbasename = os.path.splitext(tfn)[0]
             
-            f = "%s.profile" % basename
-            tf = "%s.profile" % tbasename
+            f = "{0}.profile".format(basename)
+            tf = "{0}.profile".format(tbasename)
             if os.path.isfile(f) and not f in files:
                 files.append(f)
             if os.path.isfile(tf) and not tf in files:
@@ -4626,7 +4626,7 @@
         
         try:
             f = open(fname, "w", encoding = "utf-8")
-            f.write("%s%s" % (name, "\n"))
+            f.write("{0}{1}".format(name, "\n"))
             f.write(self.macros[name].save())
             f.close()
         except IOError:
@@ -5230,7 +5230,8 @@
                         return
                     elif len(templateNames) > 1:
                         self.showUserList(TemplateCompletionListID, 
-                            ["%s?%d" % (t, self.TemplateImageID) for t in templateNames])
+                            ["{0}?{1:d}".format(t, self.TemplateImageID) \
+                             for t in templateNames])
                         return
         
         QsciScintillaCompat.editorCommand(self, cmd)
--- a/QScintilla/Exporters/ExporterHTML.py	Thu Jul 29 11:02:09 2010 +0200
+++ b/QScintilla/Exporters/ExporterHTML.py	Thu Jul 29 17:25:00 2010 +0200
@@ -83,10 +83,10 @@
                 f.write('''<html xmlns="http://www.w3.org/1999/xhtml">\n''')
                 f.write('''<head>\n''')
                 if titleFullPath:
-                    f.write('''<title>%s</title>\n''' % self.editor.getFileName())
+                    f.write('''<title>{0}</title>\n'''.format(self.editor.getFileName()))
                 else:
-                    f.write('''<title>%s</title>\n''' % \
-                        os.path.basename(self.editor.getFileName()))
+                    f.write('''<title>{0}</title>\n'''.format(
+                        os.path.basename(self.editor.getFileName())))
                 f.write('''<meta name="Generator" content="eric5" />\n''')
                 f.write('''<meta http-equiv="Content-Type" '''
                         '''content="text/html; charset=utf-8" />\n''')
@@ -140,22 +140,23 @@
                                 if istyle == QsciScintilla.STYLE_DEFAULT:
                                     f.write('''span {\n''')
                                 else:
-                                    f.write('''.S%d {\n''' % istyle)
+                                    f.write('''.S{0:d} {\n'''.format(istyle))
                                 if font.italic():
                                     f.write('''    font-style: italic;\n''')
                                 if font.bold():
                                     f.write('''    font-weight: bold;\n''')
                                 if wysiwyg:
-                                    f.write('''    font-family: '%s';\n''' % \
-                                            font.family())
-                                f.write('''    color: %s;\n''' % colour.name())
+                                    f.write('''    font-family: '{0}';\n'''.format(
+                                            font.family()))
+                                f.write('''    color: {0};\n'''.format(colour.name()))
                                 if istyle != QsciScintilla.STYLE_DEFAULT and \
                                    bgColour != paper.name():
-                                    f.write('''    background: %s;\n''' % paper.name())
+                                    f.write('''    background: {0};\n'''.format(
+                                            paper.name()))
                                     f.write('''    text-decoration: inherit;\n''')
                                 if wysiwyg:
-                                    f.write('''    font-size: %dpt;\n''' % \
-                                            QFontInfo(font).pointSize())
+                                    f.write('''    font-size: {0:d}pt;\n'''.format(
+                                            QFontInfo(font).pointSize()))
                                 f.write('''}\n''')
                             else:
                                 styleIsUsed[istyle] = False
@@ -170,19 +171,19 @@
                     if font.bold():
                         f.write('''    font-weight: bold;\n''')
                     if wysiwyg:
-                        f.write('''    font-family: '%s';\n''' % font.family())
-                    f.write('''    color: %s;\n''' % colour.name())
+                        f.write('''    font-family: '{0}';\n'''.format(font.family()))
+                    f.write('''    color: {0};\n'''.format(colour.name()))
                     if bgColour != paper.name():
-                        f.write('''    background: %s;\n''' % paper.name())
+                        f.write('''    background: {0};\n'''.format(paper.name()))
                         f.write('''    text-decoration: inherit;\n''')
                     if wysiwyg:
-                        f.write('''    font-size: %dpt;\n''' % \
-                                QFontInfo(font).pointSize())
+                        f.write('''    font-size: {0:d}pt;\n'''.format(
+                                QFontInfo(font).pointSize()))
                     f.write('''}\n''')
                 f.write('''</style>\n''')
                 f.write('''</head>\n''')
                 
-                f.write('''<body bgcolor="%s">\n''' % bgColour)
+                f.write('''<body bgcolor="{0}">\n'''.format(bgColour))
                 line = self.editor.lineAt(0)
                 level = self.editor.foldLevelAt(line) - QsciScintilla.SC_FOLDLEVELBASE
                 levelStack = [level]
@@ -198,15 +199,15 @@
                 if folding:
                     if self.editor.foldFlagsAt(line) & \
                        QsciScintilla.SC_FOLDLEVELHEADERFLAG:
-                        f.write('''<span id="hd%d" onclick="toggle('%d')">''' % \
-                                (line, line + 1))
-                        f.write('''<span id="bt%d">- </span>''' % line)
+                        f.write('''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''\
+                                .format(line, line + 1))
+                        f.write('''<span id="bt{0:d}">- </span>'''.format(line))
                         inFoldSpan = True
                     else:
                         f.write('''&nbsp; ''')
                 
                 if styleIsUsed[styleCurrent]:
-                    f.write('''<span class="S%0d">''' % styleCurrent)
+                    f.write('''<span class="S{0:0d}">'''.format(styleCurrent))
                     inStyleSpan = True
                 
                 column = 0
@@ -224,7 +225,7 @@
                             inStyleSpan = False
                         if ch not in [b'\r', b'\n']: # no need of a span for the EOL
                             if styleIsUsed[style]:
-                                f.write('''<span class="S%d">''' % style)
+                                f.write('''<span class="S{0:d}">'''.format(style))
                                 inStyleSpan = True
                             styleCurrent = style
                     
@@ -284,13 +285,14 @@
                                     levelStack.pop()
                             f.write('\n') # here to get clean code
                             if newLevel > level:
-                                f.write('''<span id="ln%d">''' % line)
+                                f.write('''<span id="ln{0:d}">'''.format(line))
                                 levelStack.append(newLevel)
                             if self.editor.foldFlagsAt(line) & \
                                QsciScintilla.SC_FOLDLEVELHEADERFLAG:
-                                f.write('''<span id="hd%d" onclick="toggle('%d')">''' % \
-                                        (line, line + 1))
-                                f.write('''<span id="bt%d">- </span>''' % line)
+                                f.write(
+                                    '''<span id="hd{0:d}" onclick="toggle('{1:d}')">'''\
+                                    .format(line, line + 1))
+                                f.write('''<span id="bt{0:d}">- </span>'''.format(line))
                                 inFoldSpan = True
                             else:
                                 f.write('''&nbsp; ''')
@@ -302,7 +304,7 @@
                            self.editor.byteAt(pos + 1) not in [b'\r', b'\n']:
                             # We know it's the correct next style,
                             # but no (empty) span for an empty line
-                            f.write('''<span class="S%0d">''' % styleCurrent)
+                            f.write('''<span class="S{0:0d}">'''.format(styleCurrent))
                             inStyleSpan = True
                     else:
                         if ch == b'<':
--- a/QScintilla/Exporters/ExporterPDF.py	Thu Jul 29 11:02:09 2010 +0200
+++ b/QScintilla/Exporters/ExporterPDF.py	Thu Jul 29 17:25:00 2010 +0200
@@ -74,7 +74,7 @@
         @param objectData data to be written (integer or string)
         """
         if isinstance(objectData, int):
-            self.file.write("%d" % objectData)
+            self.file.write("{0:d}".format(objectData))
         else:
             self.file.write(objectData)
         
@@ -108,7 +108,7 @@
         self.write("\n0000000000 65535 f \n")
         ind = 0
         while ind < len(self.offsetList):
-            self.write("%010d 00000 n \n" % self.offsetList[ind])
+            self.write("{0:010d} 00000 n \n".format(self.offsetList[ind]))
             ind += 1
         return xrefStart
 
@@ -170,10 +170,11 @@
         if styleNext != self.styleCurrent or style_ == -1:
             if self.style[self.styleCurrent].font != self.style[styleNext].font or \
                style_ == -1:
-                buf += "/F%d %d Tf " % (self.style[styleNext].font + 1, self.fontSize)
+                buf += "/F{0:d} {1:d} Tf ".format(self.style[styleNext].font + 1, 
+                                                  self.fontSize)
             if self.style[self.styleCurrent].fore != self.style[styleNext].fore or \
                style_ == -1:
-                buf += "%srg " % self.style[styleNext].fore
+                buf += "{0}rg ".format(self.style[styleNext].fore)
         return buf
         
     def startPDF(self):
@@ -206,8 +207,8 @@
         # to be inserted (PDF1.4Ref(p317))
         for i in range(4):
             buffer = \
-                "<</Type/Font/Subtype/Type1/Name/F%d/BaseFont/%s/Encoding/%s>>\n" % \
-                (i + 1, PDFfontNames[self.fontSet * 4 + i], PDF_ENCODING)
+                "<</Type/Font/Subtype/Type1/Name/F{0:d}/BaseFont/{1}/Encoding/{2}>>\n"\
+                .format(i + 1, PDFfontNames[self.fontSet * 4 + i], PDF_ENCODING)
             self.oT.add(buffer)
         
         self.pageContentStart = self.oT.index
@@ -229,31 +230,31 @@
         pageObjectStart = self.oT.index
         pagesRef = pageObjectStart + self.pageCount
         for i in range(self.pageCount):
-            buffer = "<</Type/Page/Parent %d 0 R\n" \
-                     "/MediaBox[ 0 0 %d %d]\n" \
-                     "/Contents %d 0 R\n" \
-                     "/Resources %d 0 R\n>>\n" % \
-                     (pagesRef, self.pageWidth, self.pageHeight, 
-                      self.pageContentStart + i, resourceRef)
+            buffer = "<</Type/Page/Parent {0:d} 0 R\n" \
+                     "/MediaBox[ 0 0 {1:d} {2:d}]\n" \
+                     "/Contents {3:d} 0 R\n" \
+                     "/Resources {4:d} 0 R\n>>\n".format(
+                     pagesRef, self.pageWidth, self.pageHeight, 
+                     self.pageContentStart + i, resourceRef)
             self.oT.add(buffer)
         
         # create page tree object (PDF1.4Ref(p86))
         self.pageData = "<</Type/Pages/Kids[\n"
         for i in range(self.pageCount):
-            self.pageData += "%d 0 R\n" % (pageObjectStart + i)
-        self.pageData += "]/Count %d\n>>\n" % self.pageCount
+            self.pageData += "{0:d} 0 R\n".format(pageObjectStart + i)
+        self.pageData += "]/Count {0:d}\n>>\n".format(self.pageCount)
         self.oT.add(self.pageData)
         
         # create catalog object (PDF1.4Ref(p83))
-        buffer = "<</Type/Catalog/Pages %d 0 R >>\n" % pagesRef
+        buffer = "<</Type/Catalog/Pages {0:d} 0 R >>\n".format(pagesRef)
         catalogRef = self.oT.add(buffer)
         
         # append the cross reference table (PDF1.4Ref(p64))
         xref = self.oT.xref()
         
         # end the file with the trailer (PDF1.4Ref(p67))
-        buffer = "trailer\n<< /Size %d /Root %d 0 R\n>>\nstartxref\n%d\n%%%%EOF\n" % \
-                 (self.oT.index, catalogRef, xref)
+        buffer = "trailer\n<< /Size {0:d} /Root {1:d} 0 R\n>>\nstartxref\n{2:d}\n%%EOF\n"\
+                 .format(self.oT.index, catalogRef, xref)
         self.oT.write(buffer)
         
     def add(self, ch, style_):
@@ -299,7 +300,7 @@
                 self.styleCurrent = self.stylePrev
             else:
                 self.pageData += self.segStyle
-            self.pageData += "(%s)Tj\n" % self.segment
+            self.pageData += "({0})Tj\n".format(self.segment)
             self.segment = ""
             self.segStyle = ""
             self.justWhiteSpace = True
@@ -315,7 +316,8 @@
         self.yPos = self.pageHeight - self.pageMargins["top"] - fontAscender
         
         # start a new page
-        buffer = "BT 1 0 0 1 %d %d Tm\n" % (self.pageMargins["left"], int(self.yPos))
+        buffer = "BT 1 0 0 1 {0:d} {1:d} Tm\n".format(
+            self.pageMargins["left"], int(self.yPos))
         
         # force setting of initial font, colour
         self.segStyle = self.setStyle(-1)
@@ -334,8 +336,8 @@
         
         # build actual text object; +3 is for "ET\n"
         # PDF1.4Ref(p38) EOL marker preceding endstream not counted
-        textObj = "<</Length %d>>\nstream\n%sET\nendstream\n" % \
-                  (len(self.pageData) - 1 + 3, self.pageData)
+        textObj = "<</Length {0:d}>>\nstream\n{1}ET\nendstream\n".format(
+                  len(self.pageData) - 1 + 3, self.pageData)
         self.oT.add(textObj)
         
     def nextLine(self):
@@ -359,7 +361,7 @@
         if self.firstLine:
             # avoid breakage due to locale setting
             f = int(self.leading * 10 + 0.5)
-            buffer = "0 -%d.%d TD\n" % (f // 10, f % 10)
+            buffer = "0 -{0:d}.{1:d} TD\n".format(f // 10, f % 10)
             self.firstLine = False
         else:
             buffer = "T*\n"
@@ -389,9 +391,9 @@
         for component in [color.red(), color.green(), color.blue()]:
             c = (component * 1000 + 127) // 255
             if c == 0 or c == 1000:
-                pdfColor += "%d " % (c // 1000)
+                pdfColor += "{0:d} ".format(c // 1000)
             else:
-                pdfColor += "0.%03d " % c
+                pdfColor += "0.{0:03d} ".format(c)
         return pdfColor
         
     def exportSource(self):
--- a/QScintilla/Exporters/ExporterRTF.py	Thu Jul 29 11:02:09 2010 +0200
+++ b/QScintilla/Exporters/ExporterRTF.py	Thu Jul 29 17:25:00 2010 +0200
@@ -27,10 +27,10 @@
     RTF_HEADEROPEN = "{\\rtf1\\ansi\\deff0\\deftab720"
     RTF_HEADERCLOSE = "\n"
     RTF_FONTDEFOPEN = "{\\fonttbl"
-    RTF_FONTDEF = "{\\f%d\\fnil\\fcharset%u %s;}"
+    RTF_FONTDEF = "{\\f{0:d}\\fnil\\fcharset{1:d} {2};}"
     RTF_FONTDEFCLOSE = "}"
     RTF_COLORDEFOPEN = "{\\colortbl"
-    RTF_COLORDEF = "\\red%d\\green%d\\blue%d;"
+    RTF_COLORDEF = "\\red{0:d}\\green{1:d}\\blue{2:d};"
     RTF_COLORDEFCLOSE = "}"
     RTF_INFOOPEN = "{\\info "
     RTF_INFOCLOSE = "}"
@@ -155,7 +155,7 @@
                 f.write(self.RTF_HEADEROPEN + self.RTF_FONTDEFOPEN)
                 fonts[0] = fontface
                 fontCount = 1
-                f.write(self.RTF_FONTDEF % (0, characterset, fontface))
+                f.write(self.RTF_FONTDEF.format(0, characterset, fontface))
                 colors[0] = fgColour
                 colors[1] = bgColour
                 colorCount = 2
@@ -175,20 +175,22 @@
                                             break
                                     if fontKey is None:
                                         fonts[fontCount] = font.family()
-                                        f.write(self.RTF_FONTDEF % \
-                                            (fontCount, characterset, font.family()))
+                                        f.write(self.RTF_FONTDEF.format(
+                                            fontCount, characterset, font.family()))
                                         fontKey = fontCount
                                         fontCount += 1
-                                    lastStyle = self.RTF_SETFONTFACE + "%d" % fontKey
+                                    lastStyle = self.RTF_SETFONTFACE + "{0:d}".format(
+                                        fontKey)
                                 else:
                                     lastStyle = self.RTF_SETFONTFACE + "0"
                                 
                                 if wysiwyg and QFontInfo(font).pointSize():
                                     lastStyle += self.RTF_SETFONTSIZE + \
-                                                 "%d" % (QFontInfo(font).pointSize() << 1)
+                                                 "{0:d}".format(
+                                                 QFontInfo(font).pointSize() << 1)
                                 else:
                                     lastStyle += self.RTF_SETFONTSIZE + \
-                                                 "%d" % fontsize
+                                                 "{0:d}".format(fontsize)
                                 
                                 sColour = lex.color(istyle)
                                 sColourKey = None
@@ -200,7 +202,8 @@
                                     colors[colorCount] = sColour
                                     sColourKey = colorCount
                                     colorCount += 1
-                                lastStyle += self.RTF_SETCOLOR + "%d" % sColourKey
+                                lastStyle += self.RTF_SETCOLOR + \
+                                             "{0:d}".format(sColourKey)
                                 
                                 sColour = lex.paper(istyle)
                                 sColourKey = None
@@ -212,7 +215,8 @@
                                     colors[colorCount] = sColour
                                     sColourKey = colorCount
                                     colorCount += 1
-                                lastStyle += self.RTF_SETBACKGROUND + "%d" % sColourKey
+                                lastStyle += self.RTF_SETBACKGROUND + \
+                                             "{0:d}".format(sColourKey)
                                 
                                 if font.bold():
                                     lastStyle += self.RTF_BOLD_ON
@@ -226,7 +230,7 @@
                             else:
                                 styles[istyle] = self.RTF_SETFONTFACE + "0" + \
                                                  self.RTF_SETFONTSIZE + \
-                                                 "%d" % fontsize + \
+                                                 "{0:d}".format(fontsize) + \
                                                  self.RTF_SETCOLOR + "0" + \
                                                  self.RTF_SETBACKGROUND + "1" + \
                                                  self.RTF_BOLD_OFF + self.RTF_ITALIC_OFF
@@ -234,25 +238,25 @@
                         istyle += 1
                 else:
                     styles[0] = self.RTF_SETFONTFACE + "0" + \
-                                self.RTF_SETFONTSIZE + "%d" % fontsize + \
+                                self.RTF_SETFONTSIZE + "{0:d}".format(fontsize) + \
                                 self.RTF_SETCOLOR + "0" + \
                                 self.RTF_SETBACKGROUND + "1" + \
                                 self.RTF_BOLD_OFF + self.RTF_ITALIC_OFF
                 
                 f.write(self.RTF_FONTDEFCLOSE + self.RTF_COLORDEFOPEN)
                 for value in list(colors.values()):
-                    f.write(self.RTF_COLORDEF % \
-                            (value.red(), value.green(), value.blue()))
+                    f.write(self.RTF_COLORDEF.format(
+                            value.red(), value.green(), value.blue()))
                 f.write(self.RTF_COLORDEFCLOSE)
                 f.write(self.RTF_INFOOPEN + self.RTF_COMMENT)
                 f.write(time.strftime(self.RTF_CREATED))
                 f.write(self.RTF_INFOCLOSE)
                 f.write(self.RTF_HEADERCLOSE + \
                         self.RTF_BODYOPEN + self.RTF_SETFONTFACE + "0" + \
-                        self.RTF_SETFONTSIZE + "%d" % fontsize + \
+                        self.RTF_SETFONTSIZE + "{0:d}".format(fontsize) + \
                         self.RTF_SETCOLOR + "0 ")
                 lastStyle = self.RTF_SETFONTFACE + "0" + \
-                            self.RTF_SETFONTSIZE + "%d" % fontsize + \
+                            self.RTF_SETFONTSIZE + "{0:d}".format(fontsize) + \
                             self.RTF_SETCOLOR + "0" + \
                             self.RTF_SETBACKGROUND + "1" + \
                             self.RTF_BOLD_OFF + self.RTF_ITALIC_OFF
@@ -311,9 +315,10 @@
                             elif len(utf8Ch) == utf8Len:
                                 ch = utf8Ch.decode('utf8')
                                 if ord(ch) <= 0xff:
-                                    f.write("\\'%x" % ord(ch))
+                                    f.write("\\'{0:x}".format(ord(ch)))
                                 else:
-                                    f.write("\\u%d\\'%x" % (ord(ch), ord(ch) & 0xFF))
+                                    f.write("\\u{0:d}\\'{1:x}".format(
+                                            ord(ch), ord(ch) & 0xFF))
                                 utf8Ch = b""
                                 utf8Len = 0
                             else:
--- a/QScintilla/Exporters/ExporterTEX.py	Thu Jul 29 11:02:09 2010 +0200
+++ b/QScintilla/Exporters/ExporterTEX.py	Thu Jul 29 17:25:00 2010 +0200
@@ -52,7 +52,8 @@
         g = int(gf * 10 + 0.5)
         b = int(bf * 10 + 0.5)
         
-        return "%d.%d, %d.%d, %d.%d" % (r // 10, r % 10, g // 10, g % 10, b // 10, b % 10)
+        return "{0:d}.{1:d}, {2:d}.{3:d}, {4:d}.{5:d}".format(
+               r // 10, r % 10, g // 10, g % 10, b // 10, b % 10)
     
     def __texStyle(self, style):
         """
@@ -81,8 +82,8 @@
         @param istyle style number (integer)
         """
         closing_brackets = 3
-        file.write("\\newcommand{\\eric%s}[1]{\\noindent{\\ttfamily{" % \
-                   self.__texStyle(istyle))
+        file.write("\\newcommand{{\\eric{0}}}[1]{{\\noindent{{\\ttfamily{{".format(
+                   self.__texStyle(istyle)))
         if font.italic():
             file.write("\\textit{")
             closing_brackets += 1
@@ -90,12 +91,12 @@
             file.write("\\textbf{")
             closing_brackets += 1
         if color != self.defaultColor:
-            file.write("\\textcolor[rgb]{%s}{" % self.__getTexRGB(color))
+            file.write("\\textcolor[rgb]{{{0}}}{{".format(self.__getTexRGB(color)))
             closing_brackets += 1
         if paper != self.defaultPaper:
-            file.write("\\colorbox[rgb]{%s}{" % self.__getTexRGB(paper))
+            file.write("\\colorbox[rgb]{{{0}}}{{".format(self.__getTexRGB(paper)))
             closing_brackets += 1
-        file.write("#1%s\n" % ('}' * closing_brackets))
+        file.write("#1{0}\n".format('}' * closing_brackets))
     
     def exportSource(self):
         """
@@ -186,10 +187,10 @@
                     title = self.editor.getFileName()
                 else:
                     title = os.path.basename(self.editor.getFileName())
-                f.write("Source File: %s\n\n\\noindent\n\\tiny{\n" % title)
+                f.write("Source File: {0}\n\n\\noindent\n\\tiny{{\n".format(title))
                 
                 styleCurrent = self.editor.styleAt(0)
-                f.write("\\eric%s{" % self.__texStyle(styleCurrent))
+                f.write("\\eric{0}{{".format(self.__texStyle(styleCurrent)))
                 
                 lineIdx = 0
                 pos = 0
@@ -202,25 +203,26 @@
                     style = self.editor.styleAt(pos)
                     if style != styleCurrent:
                         # new style
-                        f.write("}\n\\eric%s{" % self.__texStyle(style))
+                        f.write("}\n\\eric{0}{{".format(self.__texStyle(style)))
                         styleCurrent = style
                     
                     if ch == b'\t':
                         ts = tabSize - (lineIdx % tabSize)
                         lineIdx += ts - 1
-                        f.write("\\hspace*{%dem}" % ts)
+                        f.write("\\hspace*{{{0:d}em}}".format(ts))
                     elif ch == b'\\':
                         f.write("{\\textbackslash}")
                     elif ch in [b'>', b'<', b'@']:
-                        f.write("$%c$" % ch[0])
+                        f.write("${0}$".format(ch[0]))
                     elif ch in [b'{', b'}', b'^', b'_', b'&', b'$', b'#', b'%', b'~']:
-                        f.write("\\%c" % ch[0])
+                        f.write("\\{0}".format(ch[0]))
                     elif ch in [b'\r', b'\n']:
                         lineIdx = -1    # because incremented below
                         if ch == b'\r' and self.editor.byteAt(pos + 1) == b'\n':
                             pos += 1    # skip the LF
                         styleCurrent = self.editor.styleAt(pos + 1)
-                        f.write("} \\\\\n\\eric%s{" % self.__texStyle(styleCurrent))
+                        f.write("}} \\\\\n\\eric{0}{{".format(
+                                self.__texStyle(styleCurrent)))
                     elif ch == b' ':
                         if self.editor.byteAt(pos + 1) == b' ':
                             f.write("{\\hspace*{1em}}")

eric ide

mercurial