Skip to content

Commit 3675b88

Browse files
Kannan Goundanbraincore
authored andcommitted
More Py3 string fixes.
Reviewed By: guido
1 parent 0bad75d commit 3675b88

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

babelapi/babel/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class BabelParser(object):
201201
tokens = BabelLexer.tokens
202202

203203
# Ply feature: Starting grammar rule
204-
start = 'spec'
204+
start = str('spec') # PLY wants a 'str' instance; this makes it work in Python 2 and 3
205205

206206
def __init__(self, debug=False):
207207
self.debug = debug

babelapi/generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def emit(self, s=''):
128128
output buffer. If s is an empty string (default) then an empty line is
129129
created with no indentation.
130130
"""
131-
assert isinstance(s, six.text_type), 's must be a string type'
131+
assert isinstance(s, six.text_type), 's must be a unicode string'
132132
assert '\n' not in s, \
133133
'String to emit cannot contain newline strings.'
134134
if s:
@@ -243,7 +243,7 @@ def generate_multiline_list(self, items, before='', after='',
243243
should have a trailing separator. Ignored when compact is true.
244244
"""
245245
assert len(delim) == 2 and isinstance(delim[0], six.text_type) and \
246-
isinstance(delim[1], six.text_type), 'delim must be a tuple of two strings.'
246+
isinstance(delim[1], six.text_type), 'delim must be a tuple of two unicode strings.'
247247

248248
if len(items) == 0:
249249
self.emit(before + delim[0] + delim[1] + after)
@@ -301,7 +301,7 @@ def block(self, before='', after='', delim=('{','}'), dent=None):
301301
indentation increment is used (four spaces or one tab).
302302
"""
303303
assert len(delim) == 2 and isinstance(delim[0], six.text_type) and \
304-
isinstance(delim[1], six.text_type), 'delim must be a tuple of two strings.'
304+
isinstance(delim[1], six.text_type), 'delim must be a tuple of two unicode strings.'
305305

306306
if before:
307307
self.emit('{} {}'.format(before, delim[0]))

example/generator/unbabel/unbabel.babelg.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
- Aliases are lost (they are expanded in-line)
88
- Docstrings are reformatted
99
"""
10+
from __future__ import absolute_import, division, print_function, unicode_literals
11+
12+
import six
1013

1114
from babelapi.babel.parser import BabelTypeRef
1215
from babelapi.data_type import DataType, _BoundedInteger, _BoundedFloat
@@ -132,10 +135,10 @@ def format_data_type(self, data_type):
132135

133136
def format_value(self, val):
134137
"""Helper function to format a value."""
135-
if isinstance(val, str):
138+
if isinstance(val, six.text_type):
136139
return self.format_string(val)
137140
else:
138-
return str(val)
141+
return six.text_type(val)
139142

140143
def format_string(self, val):
141144
"""Helper function to format a string."""

generator/python/python.babelg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Code generator for Python.
33
"""
44

5+
from __future__ import absolute_import, division, print_function, unicode_literals
6+
57
import os
68
import re
79
import shutil

generator/python/test_python_gen.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import absolute_import, division, print_function, unicode_literals
2+
13
import base64
24
import datetime
35
import imp

generator/swift/swift.babelg.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from __future__ import absolute_import, division, print_function, unicode_literals
2+
13
import os
24
import shutil
5+
import six
36

47
from contextlib import contextmanager
58

@@ -103,7 +106,7 @@ def class_block(self, thing, protocols=None):
103106
name = self.class_data_type(thing)
104107
if thing.supertype:
105108
extensions.append(self.class_data_type(thing.supertype))
106-
elif isinstance(thing, basestring):
109+
elif isinstance(thing, six.text_type):
107110
name = thing
108111
else:
109112
raise TypeError("trying to generate class block for unknown type %r" % thing)

0 commit comments

Comments
 (0)