Commit 4df2d42b authored by Mike Frysinger's avatar Mike Frysinger Committed by Commit Bot

grit: replace types module with six

Python 3 has dropped the types module, so switch to six for the types
that still make sense.  For basic types (like tuple), we can just use
the builtin instead.

Bug: 983071
Test: `./grit/test_suite_all.py` passes

Change-Id: I9d1fffdcf38c5550dffb9e946bf5890930399280
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1700507Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686513}
parent e40146ed
...@@ -9,7 +9,8 @@ collections of cliques (uber-cliques). ...@@ -9,7 +9,8 @@ collections of cliques (uber-cliques).
from __future__ import print_function from __future__ import print_function
import re import re
import types
import six
from grit import constants from grit import constants
from grit import exception from grit import exception
...@@ -271,7 +272,7 @@ class CustomType(object): ...@@ -271,7 +272,7 @@ class CustomType(object):
''' '''
contents = translation.GetContent() contents = translation.GetContent()
for ix in range(len(contents)): for ix in range(len(contents)):
if (isinstance(contents[ix], types.StringTypes)): if (isinstance(contents[ix], six.string_types)):
contents[ix] = self.ModifyTextPart(lang, contents[ix]) contents[ix] = self.ModifyTextPart(lang, contents[ix])
......
...@@ -9,7 +9,8 @@ from __future__ import print_function ...@@ -9,7 +9,8 @@ from __future__ import print_function
import os import os
import re import re
import types
import six
from grit import util from grit import util
...@@ -35,7 +36,7 @@ def _FormatHeader(root, output_dir): ...@@ -35,7 +36,7 @@ def _FormatHeader(root, output_dir):
def Format(root, lang='en', output_dir='.'): def Format(root, lang='en', output_dir='.'):
"""Outputs a C switch statement representing the string table.""" """Outputs a C switch statement representing the string table."""
from grit.node import message from grit.node import message
assert isinstance(lang, types.StringTypes) assert isinstance(lang, six.string_types)
yield _FormatHeader(root, output_dir) yield _FormatHeader(root, output_dir)
......
...@@ -8,10 +8,11 @@ ...@@ -8,10 +8,11 @@
from __future__ import print_function from __future__ import print_function
import os import os
import types
import re import re
from functools import partial from functools import partial
import six
from grit import util from grit import util
from grit.node import misc from grit.node import misc
...@@ -315,7 +316,7 @@ def RcSubstitutions(substituter, lang): ...@@ -315,7 +316,7 @@ def RcSubstitutions(substituter, lang):
def _FormatHeader(root, lang, output_dir): def _FormatHeader(root, lang, output_dir):
'''Returns the required preamble for RC files.''' '''Returns the required preamble for RC files.'''
assert isinstance(lang, types.StringTypes) assert isinstance(lang, six.string_types)
assert isinstance(root, misc.GritNode) assert isinstance(root, misc.GritNode)
# Find the location of the resource header file, so that we can include # Find the location of the resource header file, so that we can include
# it. # it.
...@@ -373,7 +374,7 @@ def FormatMessage(item, lang): ...@@ -373,7 +374,7 @@ def FormatMessage(item, lang):
def _FormatSection(item, lang, output_dir): def _FormatSection(item, lang, output_dir):
'''Writes out an .rc file section.''' '''Writes out an .rc file section.'''
assert isinstance(lang, types.StringTypes) assert isinstance(lang, six.string_types)
from grit.node import structure from grit.node import structure
assert isinstance(item, structure.StructureNode) assert isinstance(item, structure.StructureNode)
...@@ -402,7 +403,7 @@ def FormatInclude(item, lang, output_dir, type=None, process_html=False): ...@@ -402,7 +403,7 @@ def FormatInclude(item, lang, output_dir, type=None, process_html=False):
StructureNode) StructureNode)
process_html: False/True (ignored unless item is a StructureNode) process_html: False/True (ignored unless item is a StructureNode)
''' '''
assert isinstance(lang, types.StringTypes) assert isinstance(lang, six.string_types)
from grit.node import structure from grit.node import structure
from grit.node import include from grit.node import include
assert isinstance(item, (structure.StructureNode, include.IncludeNode)) assert isinstance(item, (structure.StructureNode, include.IncludeNode))
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
from __future__ import print_function from __future__ import print_function
import os.path import os.path
import types
import six
from grit import clique from grit import clique
from grit import util from grit import util
...@@ -161,7 +162,7 @@ class GathererBase(object): ...@@ -161,7 +162,7 @@ class GathererBase(object):
'''A convenience function for subclasses that loads the contents of the '''A convenience function for subclasses that loads the contents of the
input file. input file.
''' '''
if isinstance(self.rc_file, types.StringTypes): if isinstance(self.rc_file, six.string_types):
path = self.GetInputPath() path = self.GetInputPath()
# Hack: some unit tests supply an absolute path and no root node. # Hack: some unit tests supply an absolute path and no root node.
if not os.path.isabs(path): if not os.path.isabs(path):
......
...@@ -8,7 +8,7 @@ list. ...@@ -8,7 +8,7 @@ list.
from __future__ import print_function from __future__ import print_function
import types import six
from grit.gather import interface from grit.gather import interface
from grit import clique from grit import clique
...@@ -78,17 +78,17 @@ class SkeletonGatherer(interface.GathererBase): ...@@ -78,17 +78,17 @@ class SkeletonGatherer(interface.GathererBase):
out = [] out = []
for ix in range(len(self.skeleton_)): for ix in range(len(self.skeleton_)):
if isinstance(self.skeleton_[ix], types.StringTypes): if isinstance(self.skeleton_[ix], six.string_types):
if skeleton_gatherer: if skeleton_gatherer:
# Make sure the skeleton is like the original # Make sure the skeleton is like the original
assert(isinstance(skeleton_gatherer.skeleton_[ix], types.StringTypes)) assert(isinstance(skeleton_gatherer.skeleton_[ix], six.string_types))
out.append(skeleton_gatherer.skeleton_[ix]) out.append(skeleton_gatherer.skeleton_[ix])
else: else:
out.append(self.skeleton_[ix]) out.append(self.skeleton_[ix])
else: else:
if skeleton_gatherer: # Make sure the skeleton is like the original if skeleton_gatherer: # Make sure the skeleton is like the original
assert(not isinstance(skeleton_gatherer.skeleton_[ix], assert(not isinstance(skeleton_gatherer.skeleton_[ix],
types.StringTypes)) six.string_types))
msg = self.skeleton_[ix].MessageForLanguage(lang, msg = self.skeleton_[ix].MessageForLanguage(lang,
pseudo_if_not_available, pseudo_if_not_available,
fallback_to_english) fallback_to_english)
......
...@@ -52,7 +52,8 @@ extern.tclib.api.handlers.html.TCHTMLParser. ...@@ -52,7 +52,8 @@ extern.tclib.api.handlers.html.TCHTMLParser.
from __future__ import print_function from __future__ import print_function
import re import re
import types
import six
from grit import clique from grit import clique
from grit import exception from grit import exception
...@@ -573,7 +574,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''): ...@@ -573,7 +574,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''):
current += m.end() current += m.end()
continue continue
if len(parts) and isinstance(parts[-1], types.StringTypes): if len(parts) and isinstance(parts[-1], six.string_types):
parts[-1] += html[current] parts[-1] += html[current]
else: else:
parts.append(html[current]) parts.append(html[current])
...@@ -582,7 +583,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''): ...@@ -582,7 +583,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''):
msg_text = '' msg_text = ''
placeholders = [] placeholders = []
for part in parts: for part in parts:
if isinstance(part, types.TupleType): if isinstance(part, tuple):
final_name = part[0]() final_name = part[0]()
original = part[1] original = part[1]
msg_text += final_name msg_text += final_name
...@@ -594,7 +595,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''): ...@@ -594,7 +595,7 @@ def HtmlToMessage(html, include_block_tags=False, description=''):
description=description) description=description)
content = msg.GetContent() content = msg.GetContent()
for ix in range(len(content)): for ix in range(len(content)):
if isinstance(content[ix], types.StringTypes): if isinstance(content[ix], six.string_types):
content[ix] = util.UnescapeHtml(content[ix], replace_nbsp=False) content[ix] = util.UnescapeHtml(content[ix], replace_nbsp=False)
return msg return msg
...@@ -658,7 +659,7 @@ class TrHtml(interface.GathererBase): ...@@ -658,7 +659,7 @@ class TrHtml(interface.GathererBase):
out = [] out = []
for item in self.skeleton_: for item in self.skeleton_:
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
out.append(item) out.append(item)
else: else:
msg = item.MessageForLanguage(lang, msg = item.MessageForLanguage(lang,
...@@ -718,8 +719,8 @@ class TrHtml(interface.GathererBase): ...@@ -718,8 +719,8 @@ class TrHtml(interface.GathererBase):
if isinstance(self.skeleton_[ix], clique.MessageClique): if isinstance(self.skeleton_[ix], clique.MessageClique):
msg = self.skeleton_[ix].GetMessage() msg = self.skeleton_[ix].GetMessage()
for item in msg.GetContent(): for item in msg.GetContent():
if (isinstance(item, types.StringTypes) and _NON_WHITESPACE.search(item) if (isinstance(item, six.string_types)
and item != '&nbsp;'): and _NON_WHITESPACE.search(item) and item != '&nbsp;'):
got_text = True got_text = True
break break
if not got_text: if not got_text:
......
...@@ -12,9 +12,9 @@ import sys ...@@ -12,9 +12,9 @@ import sys
if __name__ == '__main__': if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '../..')) sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
import types
import unittest import unittest
import six
from six import StringIO from six import StringIO
from grit.gather import tr_html from grit.gather import tr_html
...@@ -369,7 +369,7 @@ bla ...@@ -369,7 +369,7 @@ bla
# For manual results inspection only... # For manual results inspection only...
list = [] list = []
for item in html.skeleton_: for item in html.skeleton_:
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
list.append(item) list.append(item)
else: else:
list.append(item.GetMessage().GetPresentableContent()) list.append(item.GetMessage().GetPresentableContent())
......
...@@ -10,10 +10,11 @@ from __future__ import print_function ...@@ -10,10 +10,11 @@ from __future__ import print_function
import os.path import os.path
import sys import sys
import types
import xml.sax import xml.sax
import xml.sax.handler import xml.sax.handler
import six
from grit import exception from grit import exception
from grit import util from grit import util
from grit.node import mapping from grit.node import mapping
...@@ -187,7 +188,7 @@ def Parse(filename_or_stream, dir=None, stop_after=None, first_ids_file=None, ...@@ -187,7 +188,7 @@ def Parse(filename_or_stream, dir=None, stop_after=None, first_ids_file=None,
grit.exception.Parsing grit.exception.Parsing
''' '''
if isinstance(filename_or_stream, types.StringType): if isinstance(filename_or_stream, six.string_types):
source = filename_or_stream source = filename_or_stream
if dir is None: if dir is None:
dir = util.dirname(filename_or_stream) dir = util.dirname(filename_or_stream)
......
...@@ -11,9 +11,10 @@ import ast ...@@ -11,9 +11,10 @@ import ast
import os import os
import struct import struct
import sys import sys
import types
from xml.sax import saxutils from xml.sax import saxutils
import six
from grit import constants from grit import constants
from grit import clique from grit import clique
from grit import exception from grit import exception
...@@ -112,7 +113,7 @@ class Node(object): ...@@ -112,7 +113,7 @@ class Node(object):
name: u'elementname' name: u'elementname'
parent: grit.node.base.Node or subclass or None parent: grit.node.base.Node or subclass or None
''' '''
assert isinstance(name, types.StringTypes) assert isinstance(name, six.string_types)
assert not parent or isinstance(parent, Node) assert not parent or isinstance(parent, Node)
self.name = name self.name = name
self.parent = parent self.parent = parent
...@@ -155,7 +156,7 @@ class Node(object): ...@@ -155,7 +156,7 @@ class Node(object):
Return: Return:
None None
''' '''
assert isinstance(content, types.StringTypes) assert isinstance(content, six.string_types)
if self._ContentType() != self._CONTENT_TYPE_NONE: if self._ContentType() != self._CONTENT_TYPE_NONE:
self.mixed_content.append(content) self.mixed_content.append(content)
elif content.strip() != '': elif content.strip() != '':
...@@ -172,8 +173,8 @@ class Node(object): ...@@ -172,8 +173,8 @@ class Node(object):
Return: Return:
None None
''' '''
assert isinstance(attrib, types.StringTypes) assert isinstance(attrib, six.string_types)
assert isinstance(value, types.StringTypes) assert isinstance(value, six.string_types)
if self._IsValidAttribute(attrib, value): if self._IsValidAttribute(attrib, value):
self.attrs[attrib] = value self.attrs[attrib] = value
else: else:
...@@ -184,34 +185,34 @@ class Node(object): ...@@ -184,34 +185,34 @@ class Node(object):
# TODO(joi) Rewrite this, it's extremely ugly! # TODO(joi) Rewrite this, it's extremely ugly!
if len(self.mixed_content): if len(self.mixed_content):
if isinstance(self.mixed_content[0], types.StringTypes): if isinstance(self.mixed_content[0], six.string_types):
# Remove leading and trailing chunks of pure whitespace. # Remove leading and trailing chunks of pure whitespace.
while (len(self.mixed_content) and while (len(self.mixed_content) and
isinstance(self.mixed_content[0], types.StringTypes) and isinstance(self.mixed_content[0], six.string_types) and
self.mixed_content[0].strip() == ''): self.mixed_content[0].strip() == ''):
self.mixed_content = self.mixed_content[1:] self.mixed_content = self.mixed_content[1:]
# Strip leading and trailing whitespace from mixed content chunks # Strip leading and trailing whitespace from mixed content chunks
# at front and back. # at front and back.
if (len(self.mixed_content) and if (len(self.mixed_content) and
isinstance(self.mixed_content[0], types.StringTypes)): isinstance(self.mixed_content[0], six.string_types)):
self.mixed_content[0] = self.mixed_content[0].lstrip() self.mixed_content[0] = self.mixed_content[0].lstrip()
# Remove leading and trailing ''' (used to demarcate whitespace) # Remove leading and trailing ''' (used to demarcate whitespace)
if (len(self.mixed_content) and if (len(self.mixed_content) and
isinstance(self.mixed_content[0], types.StringTypes)): isinstance(self.mixed_content[0], six.string_types)):
if self.mixed_content[0].startswith("'''"): if self.mixed_content[0].startswith("'''"):
self.mixed_content[0] = self.mixed_content[0][3:] self.mixed_content[0] = self.mixed_content[0][3:]
if len(self.mixed_content): if len(self.mixed_content):
if isinstance(self.mixed_content[-1], types.StringTypes): if isinstance(self.mixed_content[-1], six.string_types):
# Same stuff all over again for the tail end. # Same stuff all over again for the tail end.
while (len(self.mixed_content) and while (len(self.mixed_content) and
isinstance(self.mixed_content[-1], types.StringTypes) and isinstance(self.mixed_content[-1], six.string_types) and
self.mixed_content[-1].strip() == ''): self.mixed_content[-1].strip() == ''):
self.mixed_content = self.mixed_content[:-1] self.mixed_content = self.mixed_content[:-1]
if (len(self.mixed_content) and if (len(self.mixed_content) and
isinstance(self.mixed_content[-1], types.StringTypes)): isinstance(self.mixed_content[-1], six.string_types)):
self.mixed_content[-1] = self.mixed_content[-1].rstrip() self.mixed_content[-1] = self.mixed_content[-1].rstrip()
if (len(self.mixed_content) and if (len(self.mixed_content) and
isinstance(self.mixed_content[-1], types.StringTypes)): isinstance(self.mixed_content[-1], six.string_types)):
if self.mixed_content[-1].endswith("'''"): if self.mixed_content[-1].endswith("'''"):
self.mixed_content[-1] = self.mixed_content[-1][:-3] self.mixed_content[-1] = self.mixed_content[-1][:-3]
...@@ -244,7 +245,7 @@ class Node(object): ...@@ -244,7 +245,7 @@ class Node(object):
'''Returns all CDATA of this element, concatenated into a single '''Returns all CDATA of this element, concatenated into a single
string. Note that this ignores any elements embedded in CDATA.''' string. Note that this ignores any elements embedded in CDATA.'''
return ''.join([c for c in self.mixed_content return ''.join([c for c in self.mixed_content
if isinstance(c, types.StringTypes)]) if isinstance(c, six.string_types)])
def __unicode__(self): def __unicode__(self):
'''Returns this node and all nodes below it as an XML document in a Unicode '''Returns this node and all nodes below it as an XML document in a Unicode
...@@ -259,7 +260,7 @@ class Node(object): ...@@ -259,7 +260,7 @@ class Node(object):
children and CDATA are layed out in a way that preserves internal children and CDATA are layed out in a way that preserves internal
whitespace. whitespace.
''' '''
assert isinstance(indent, types.StringTypes) assert isinstance(indent, six.string_types)
content_one_line = (one_line or content_one_line = (one_line or
self._ContentType() == self._CONTENT_TYPE_MIXED) self._ContentType() == self._CONTENT_TYPE_MIXED)
...@@ -293,7 +294,7 @@ class Node(object): ...@@ -293,7 +294,7 @@ class Node(object):
def ContentsAsXml(self, indent, one_line): def ContentsAsXml(self, indent, one_line):
'''Returns the contents of this node (CDATA and child elements) in XML '''Returns the contents of this node (CDATA and child elements) in XML
format. If 'one_line' is true, the content will be laid out on one line.''' format. If 'one_line' is true, the content will be laid out on one line.'''
assert isinstance(indent, types.StringTypes) assert isinstance(indent, six.string_types)
# Build the contents of the element. # Build the contents of the element.
inside_parts = [] inside_parts = []
...@@ -319,7 +320,7 @@ class Node(object): ...@@ -319,7 +320,7 @@ class Node(object):
# If the last item is a string (not a node) and ends with whitespace, # If the last item is a string (not a node) and ends with whitespace,
# we need to add the ''' delimiter. # we need to add the ''' delimiter.
if (isinstance(last_item, types.StringTypes) and if (isinstance(last_item, six.string_types) and
last_item.rstrip() != last_item): last_item.rstrip() != last_item):
inside_parts[-1] = inside_parts[-1] + u"'''" inside_parts[-1] = inside_parts[-1] + u"'''"
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
from __future__ import print_function from __future__ import print_function
import re import re
import types
import six
from grit.node import base from grit.node import base
...@@ -166,7 +167,7 @@ class MessageNode(base.ContentNode): ...@@ -166,7 +167,7 @@ class MessageNode(base.ContentNode):
placeholders = [] placeholders = []
for item in self.mixed_content: for item in self.mixed_content:
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
# Not a <ph> element: fail if any <ph> formatters are detected. # Not a <ph> element: fail if any <ph> formatters are detected.
if _FORMATTERS.search(item): if _FORMATTERS.search(item):
print(_BAD_PLACEHOLDER_MSG % (item, self.source)) print(_BAD_PLACEHOLDER_MSG % (item, self.source))
...@@ -303,7 +304,7 @@ class MessageNode(base.ContentNode): ...@@ -303,7 +304,7 @@ class MessageNode(base.ContentNode):
items = message.GetContent() items = message.GetContent()
for ix, item in enumerate(items): for ix, item in enumerate(items):
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
# Ensure whitespace at front and back of message is correctly handled. # Ensure whitespace at front and back of message is correctly handled.
if ix == 0: if ix == 0:
item = "'''" + item item = "'''" + item
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
from __future__ import print_function from __future__ import print_function
import re import re
import types
import six
from grit import exception from grit import exception
from grit import lazy_re from grit import lazy_re
...@@ -83,7 +84,7 @@ class BaseMessage(object): ...@@ -83,7 +84,7 @@ class BaseMessage(object):
''' '''
bits = [] bits = []
for item in self.parts: for item in self.parts:
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
bits.append(escaping_function(item)) bits.append(escaping_function(item))
else: else:
bits.append(item.GetOriginal()) bits.append(item.GetOriginal())
...@@ -112,7 +113,7 @@ class BaseMessage(object): ...@@ -112,7 +113,7 @@ class BaseMessage(object):
self.dirty = True self.dirty = True
def AppendText(self, text): def AppendText(self, text):
assert isinstance(text, types.StringTypes) assert isinstance(text, six.string_types)
assert text != '' assert text != ''
self.parts.append(text) self.parts.append(text)
......
...@@ -12,9 +12,10 @@ import os.path ...@@ -12,9 +12,10 @@ import os.path
if __name__ == '__main__': if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import types
import unittest import unittest
import six
from grit import tclib from grit import tclib
from grit import exception from grit import exception
...@@ -26,14 +27,14 @@ class TclibUnittest(unittest.TestCase): ...@@ -26,14 +27,14 @@ class TclibUnittest(unittest.TestCase):
msg = tclib.Message(text=u'Hello Earthlings', msg = tclib.Message(text=u'Hello Earthlings',
description='Greetings\n\t message') description='Greetings\n\t message')
self.failUnlessEqual(msg.GetPresentableContent(), 'Hello Earthlings') self.failUnlessEqual(msg.GetPresentableContent(), 'Hello Earthlings')
self.failUnless(isinstance(msg.GetPresentableContent(), types.StringTypes)) self.failUnless(isinstance(msg.GetPresentableContent(), six.string_types))
self.failUnlessEqual(msg.GetDescription(), 'Greetings message') self.failUnlessEqual(msg.GetDescription(), 'Greetings message')
def testGetAttr(self): def testGetAttr(self):
msg = tclib.Message() msg = tclib.Message()
msg.AppendText(u'Hello') # Tests __getattr__ msg.AppendText(u'Hello') # Tests __getattr__
self.failUnless(msg.GetPresentableContent() == 'Hello') self.failUnless(msg.GetPresentableContent() == 'Hello')
self.failUnless(isinstance(msg.GetPresentableContent(), types.StringTypes)) self.failUnless(isinstance(msg.GetPresentableContent(), six.string_types))
def testAll(self): def testAll(self):
text = u'Howdie USERNAME' text = u'Howdie USERNAME'
...@@ -43,7 +44,7 @@ class TclibUnittest(unittest.TestCase): ...@@ -43,7 +44,7 @@ class TclibUnittest(unittest.TestCase):
trans = tclib.Translation(text=text, placeholders=phs) trans = tclib.Translation(text=text, placeholders=phs)
self.failUnless(trans.GetPresentableContent() == 'Howdie USERNAME') self.failUnless(trans.GetPresentableContent() == 'Howdie USERNAME')
self.failUnless(isinstance(trans.GetPresentableContent(), types.StringTypes)) self.failUnless(isinstance(trans.GetPresentableContent(), six.string_types))
def testUnicodeReturn(self): def testUnicodeReturn(self):
text = u'\u00fe' text = u'\u00fe'
...@@ -65,7 +66,7 @@ class TclibUnittest(unittest.TestCase): ...@@ -65,7 +66,7 @@ class TclibUnittest(unittest.TestCase):
transl = tclib.Translation(text=msg.GetPresentableContent(), transl = tclib.Translation(text=msg.GetPresentableContent(),
placeholders=msg.GetPlaceholders()) placeholders=msg.GetPlaceholders())
content = transl.GetContent() content = transl.GetContent()
self.failUnless(isinstance(content[3], types.UnicodeType)) self.failUnless(isinstance(content[3], six.string_types))
def testFingerprint(self): def testFingerprint(self):
# This has Windows line endings. That is on purpose. # This has Windows line endings. That is on purpose.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
from __future__ import print_function from __future__ import print_function
import types import six
from grit import grd_reader from grit import grd_reader
from grit import util from grit import util
...@@ -61,7 +61,7 @@ to being one message for the whole menu.''' ...@@ -61,7 +61,7 @@ to being one message for the whole menu.'''
contents = message.GetContent() contents = message.GetContent()
for part in contents: for part in contents:
if isinstance(part, types.StringTypes): if isinstance(part, six.string_types):
id = grit.extern.tclib.GenerateMessageId(part) id = grit.extern.tclib.GenerateMessageId(part)
if id not in xtb: if id not in xtb:
print("WARNING didn't find all translations for menu %s" % print("WARNING didn't find all translations for menu %s" %
......
...@@ -10,8 +10,8 @@ import os.path ...@@ -10,8 +10,8 @@ import os.path
import getopt import getopt
import re import re
import sys import sys
import types
import six
from six import StringIO from six import StringIO
import grit.node.empty import grit.node.empty
...@@ -341,7 +341,7 @@ C preprocessor on the .rc file or manually edit it before using this tool. ...@@ -341,7 +341,7 @@ C preprocessor on the .rc file or manually edit it before using this tool.
# Messages that contain only placeholders do not need translation. # Messages that contain only placeholders do not need translation.
is_translateable = False is_translateable = False
for item in msg_obj.GetContent(): for item in msg_obj.GetContent():
if isinstance(item, types.StringTypes): if isinstance(item, six.string_types):
if not _WHITESPACE_ONLY.match(item): if not _WHITESPACE_ONLY.match(item):
is_translateable = True is_translateable = True
...@@ -389,7 +389,7 @@ C preprocessor on the .rc file or manually edit it before using this tool. ...@@ -389,7 +389,7 @@ C preprocessor on the .rc file or manually edit it before using this tool.
# TODO(joi) Allow use of non-TotalRecall flavors of HTML placeholderizing # TODO(joi) Allow use of non-TotalRecall flavors of HTML placeholderizing
msg = tr_html.HtmlToMessage(text, True) msg = tr_html.HtmlToMessage(text, True)
for item in msg.GetContent(): for item in msg.GetContent():
if not isinstance(item, types.StringTypes): if not isinstance(item, six.string_types):
return msg # Contained at least one placeholder, so we're done return msg # Contained at least one placeholder, so we're done
# HTML placeholderization didn't do anything, so try to find printf or # HTML placeholderization didn't do anything, so try to find printf or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment