shithub: freetype+ttf2subf

Download patch

ref: 2af25ac0f9d5f298204422a2321895ce7c709f97
parent: 80bfeb1c3b1050273b2b87a4fd7de6b0cddc96d1
author: Werner Lemberg <[email protected]>
date: Tue Dec 2 03:38:57 EST 2014

[docmaker] Ensure Python 3 compatibility.

* src/tools/docmaker/content.py (ContentProcessor::set_section,
ContentProcessor::finish): Replace `has_key' function with `in'
keyword.

* src/tools/docmaker/formatter.py (Formatter::__init__): Replace
sorting function with a key generator.
(Formatter::add_identifier): Replace `has_key' function with `in'
keyword.

* src/tools/docmaker/tohtml.py (HtmlFormatter::html_source_quote):
Replace `has_key' function with `in' keyword.
(HtmlFormatter::index_exit, HtmlFormatter::section_enter): Use
integer division.
s/<>/>/.

* src/tools/docmaker/utils.py: Import `itertools'.
(index_sort): Replaced by...
(index_key): ... this new key generator (doing exactly the same).

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2014-12-02  Werner Lemberg  <[email protected]>
+
+	[docmaker] Ensure Python 3 compatibility.
+
+	* src/tools/docmaker/content.py (ContentProcessor::set_section,
+	ContentProcessor::finish): Replace `has_key' function with `in'
+	keyword.
+
+	* src/tools/docmaker/formatter.py (Formatter::__init__): Replace
+	sorting function with a key generator.
+	(Formatter::add_identifier): Replace `has_key' function with `in'
+	keyword.
+
+	* src/tools/docmaker/tohtml.py (HtmlFormatter::html_source_quote):
+	Replace `has_key' function with `in' keyword.
+	(HtmlFormatter::index_exit, HtmlFormatter::section_enter): Use
+	integer division.
+	s/<>/>/.
+
+	* src/tools/docmaker/utils.py: Import `itertools'.
+	(index_sort): Replaced by...
+	(index_key): ... this new key generator (doing exactly the same).
+
 2014-11-29  Werner Lemberg  <[email protected]>
 
 	[docmaker] Don't output a block multiple times.
--- a/src/tools/docmaker/content.py
+++ b/src/tools/docmaker/content.py
@@ -395,7 +395,7 @@
 
     def  set_section( self, section_name ):
         """Set current section during parsing."""
-        if not self.sections.has_key( section_name ):
+        if not section_name in self.sections:
             section = DocSection( section_name )
             self.sections[section_name] = section
             self.section                = section
@@ -488,7 +488,7 @@
         # listed there
         for chap in self.chapters:
             for sec in chap.order:
-                if self.sections.has_key( sec ):
+                if sec in self.sections:
                     section = self.sections[sec]
                     section.chapter = chap
                     section.reorder()
--- a/src/tools/docmaker/formatter.py
+++ b/src/tools/docmaker/formatter.py
@@ -54,10 +54,10 @@
                             self.add_identifier( field.name, block )
 
         self.block_index = self.identifiers.keys()
-        self.block_index.sort( index_sort )
+        self.block_index.sort( key = index_key )
 
     def  add_identifier( self, name, block ):
-        if self.identifiers.has_key( name ):
+        if name in self.identifiers:
             # duplicate name!
             sys.stderr.write( "WARNING: duplicate definition for"
                               + " '" + name + "' "
--- a/src/tools/docmaker/tohtml.py
+++ b/src/tools/docmaker/tohtml.py
@@ -411,7 +411,7 @@
                     # this is a C keyword
                     result = ( result + prefix
                                + keyword_prefix + name + keyword_suffix )
-                elif self.identifiers.has_key( name ):
+                elif name in self.identifiers:
                     # this is a known identifier
                     block = self.identifiers[name]
                     id = block.name
@@ -480,7 +480,7 @@
     def  index_exit( self ):
         # `block_index' already contains the sorted list of index names
         count = len( self.block_index )
-        rows  = ( count + self.columns - 1 ) / self.columns
+        rows  = ( count + self.columns - 1 ) // self.columns
 
         print '<table class="index">'
         for r in range( rows ):
@@ -572,17 +572,17 @@
                 maxwidth = len( b.name )
 
         width = 70  # XXX magic number
-        if maxwidth <> 0:
+        if maxwidth > 0:
             # print section synopsis
             print section_synopsis_header
             print '<table class="synopsis">'
 
-            columns = width / maxwidth
+            columns = width // maxwidth
             if columns < 1:
                 columns = 1
 
             count = len( section.block_names )
-            rows  = ( count + columns - 1 ) / columns
+            rows  = ( count + columns - 1 ) // columns
 
             for r in range( rows ):
                 line = "<tr>"
--- a/src/tools/docmaker/utils.py
+++ b/src/tools/docmaker/utils.py
@@ -13,7 +13,7 @@
 #  understand and accept it fully.
 
 
-import string, sys, os, glob
+import string, sys, os, glob, itertools
 
 
 # current output directory
@@ -21,38 +21,19 @@
 output_dir = None
 
 
-# A function to sort the index.  It is a simple lexicographical sort, except
-# that it places capital letters before lowercase ones.
+# A function that generates a sorting key.  We want lexicographical order
+# (primary key) except that capital letters are sorted before lowercase
+# ones (secondary key).
 #
-def  index_sort( s1, s2 ):
-    if not s1:
-        return -1
-
-    if not s2:
-        return 1
-
-    l1 = len( s1 )
-    l2 = len( s2 )
-    m1 = string.lower( s1 )
-    m2 = string.lower( s2 )
-
-    for i in range( l1 ):
-        if i >= l2 or m1[i] > m2[i]:
-            return 1
-
-        if m1[i] < m2[i]:
-            return -1
-
-        if s1[i] < s2[i]:
-            return -1
-
-        if s1[i] > s2[i]:
-            return 1
-
-    if l2 > l1:
-        return -1
-
-    return 0
+# The primary key is implemented by lowercasing the input.  The secondary
+# key is simply the original data appended, character by character.  For
+# example, the sort key for `FT_x' is `fFtT__xx', while the sort key for
+# `ft_X' is `fftt__xX'.  Since ASCII codes of uppercase letters are
+# numerically smaller than the codes of lowercase letters, `fFtT__xx' gets
+# sorted before `fftt__xX'.
+#
+def  index_key( s ):
+    return string.join( itertools.chain( *zip( s.lower(), s ) ) )
 
 
 # Sort `input_list', placing the elements of `order_list' in front.