Skip to content

Commit ae69fd4

Browse files
author
loewis
committed
Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled - check for Py_USING_UNICODE in all places that use Unicode functions - disables unicode literals, and the builtin functions - add the types.StringTypes list - remove Unicode literals from most tests. git-svn-id: http://svn.python.org/projects/python/trunk@22551 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b953d76 commit ae69fd4

42 files changed

Lines changed: 465 additions & 185 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Include/intobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ extern DL_IMPORT(PyTypeObject) PyInt_Type;
3030
#define PyInt_Check(op) ((op)->ob_type == &PyInt_Type)
3131

3232
extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int);
33+
#ifdef Py_USING_UNICODE
3334
extern DL_IMPORT(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int);
35+
#endif
3436
extern DL_IMPORT(PyObject *) PyInt_FromLong(long);
3537
extern DL_IMPORT(long) PyInt_AsLong(PyObject *);
3638
extern DL_IMPORT(long) PyInt_GetMax(void);

Include/longobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ extern DL_IMPORT(unsigned LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
4242
#endif /* HAVE_LONG_LONG */
4343

4444
DL_IMPORT(PyObject *) PyLong_FromString(char *, char **, int);
45+
#ifdef Py_USING_UNICODE
4546
DL_IMPORT(PyObject *) PyLong_FromUnicode(Py_UNICODE*, int, int);
47+
#endif
4648

4749
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
4850
base 256, and return a Python long with the same numeric value.

Include/object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int);
320320
extern DL_IMPORT(void) _PyObject_Dump(PyObject *);
321321
extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *);
322322
extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *);
323+
#ifdef Py_USING_UNICODE
323324
extern DL_IMPORT(PyObject *) PyObject_Unicode(PyObject *);
325+
#endif
324326
extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *);
325327
extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
326328
extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);

Include/unicodeobject.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ Copyright (c) Corporation for National Research Initiatives.
5858

5959
/* --- Internal Unicode Format -------------------------------------------- */
6060

61+
#ifndef Py_USING_UNICODE
62+
63+
#define PyUnicode_Check(op) 0
64+
65+
#else
66+
6167
/* FIXME: MvL's new implementation assumes that Py_UNICODE_SIZE is
6268
properly set, but the default rules below doesn't set it. I'll
6369
sort this out some other day -- fredrik@pythonware.com */
@@ -1087,4 +1093,5 @@ extern DL_IMPORT(int) _PyUnicode_IsAlpha(
10871093
#ifdef __cplusplus
10881094
}
10891095
#endif
1096+
#endif /* Py_USING_UNICODE */
10901097
#endif /* !Py_UNICODEOBJECT_H */

Lib/ConfigParser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
write the configuration state in .ini format
8383
"""
8484

85-
import string
85+
import string, types
8686
import re
8787

8888
__all__ = ["NoSectionError","DuplicateSectionError","NoOptionError",
@@ -222,7 +222,7 @@ def read(self, filenames):
222222
configuration files in the list will be read. A single
223223
filename may also be given.
224224
"""
225-
if type(filenames) in [type(''), type(u'')]:
225+
if type(filenames) in types.StringTypes:
226226
filenames = [filenames]
227227
for filename in filenames:
228228
try:

Lib/copy.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ def _copy_atomic(x):
9191
d[types.LongType] = _copy_atomic
9292
d[types.FloatType] = _copy_atomic
9393
d[types.StringType] = _copy_atomic
94-
d[types.UnicodeType] = _copy_atomic
94+
try:
95+
d[types.UnicodeType] = _copy_atomic
96+
except AttributeError:
97+
pass
9598
try:
9699
d[types.CodeType] = _copy_atomic
97100
except AttributeError:
@@ -170,7 +173,10 @@ def _deepcopy_atomic(x, memo):
170173
d[types.LongType] = _deepcopy_atomic
171174
d[types.FloatType] = _deepcopy_atomic
172175
d[types.StringType] = _deepcopy_atomic
173-
d[types.UnicodeType] = _deepcopy_atomic
176+
try:
177+
d[types.UnicodeType] = _deepcopy_atomic
178+
except AttributeError:
179+
pass
174180
d[types.CodeType] = _deepcopy_atomic
175181
d[types.TypeType] = _deepcopy_atomic
176182
d[types.XRangeType] = _deepcopy_atomic

Lib/site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,8 @@ def __call__(self, *args, **kwds):
305305
encoding = "undefined"
306306

307307
if encoding != "ascii":
308-
sys.setdefaultencoding(encoding)
308+
# On Non-Unicode builds this will raise an AttributeError...
309+
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
309310

310311
#
311312
# Run custom site specific code, if available.

Lib/test/pickletester.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# test_pickle and test_cpickle both use this.
22

3-
from test_support import TestFailed
3+
from test_support import TestFailed, have_unicode
44
import sys
55

66
# break into multiple strings to please font-lock-mode
@@ -191,7 +191,11 @@ def dotest(pickle):
191191
print "accepted insecure string: %s" % repr(buf)
192192

193193
# Test some Unicode end cases
194-
endcases = [u'', u'<\\u>', u'<\\\u1234>', u'<\n>', u'<\\>']
194+
if have_unicode:
195+
endcases = [unicode(''), unicode('<\\u>'), unicode('<\\\u1234>'),
196+
unicode('<\n>'), unicode('<\\>')]
197+
else:
198+
endcases = []
195199
for u in endcases:
196200
try:
197201
u2 = pickle.loads(pickle.dumps(u))

Lib/test/string_tests.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Common tests shared by test_string and test_userstring"""
22

33
import string
4-
from test_support import verify, verbose, TestFailed
4+
from test_support import verify, verbose, TestFailed, have_unicode
55

66
transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
77

@@ -125,11 +125,12 @@ def run_method_tests(test):
125125
test('join', ' ', 'w x y z', Sequence())
126126
test('join', 'a', 'abc', ('abc',))
127127
test('join', 'a', 'z', UserList(['z']))
128-
test('join', u'.', u'a.b.c', ['a', 'b', 'c'])
129-
test('join', '.', u'a.b.c', [u'a', 'b', 'c'])
130-
test('join', '.', u'a.b.c', ['a', u'b', 'c'])
131-
test('join', '.', u'a.b.c', ['a', 'b', u'c'])
132-
test('join', '.', TypeError, ['a', u'b', 3])
128+
if have_unicode:
129+
test('join', unicode('.'), unicode('a.b.c'), ['a', 'b', 'c'])
130+
test('join', '.', unicode('a.b.c'), [unicode('a'), 'b', 'c'])
131+
test('join', '.', unicode('a.b.c'), ['a', unicode('b'), 'c'])
132+
test('join', '.', unicode('a.b.c'), ['a', 'b', unicode('c')])
133+
test('join', '.', TypeError, ['a', unicode('b'), 3])
133134
for i in [5, 25, 125]:
134135
test('join', '-', ((('a' * i) + '-') * i)[:-1],
135136
['a' * i] * i)

Lib/test/test_b1.py

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def __call__(self): pass
119119
if complex(0j, 3.14) != 3.14j: raise TestFailed, 'complex(0j, 3.14)'
120120
if complex(0.0, 3.14) != 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
121121
if complex(" 3.14+J ") != 3.14+1j: raise TestFailed, 'complex(" 3.14+J )"'
122-
if complex(u" 3.14+J ") != 3.14+1j: raise TestFailed, 'complex(u" 3.14+J )"'
122+
if have_unicode:
123+
if complex(unicode(" 3.14+J ")) != 3.14+1j:
124+
raise TestFailed, 'complex(u" 3.14+J )"'
123125
class Z:
124126
def __complex__(self): return 3.14j
125127
z = Z()
@@ -174,18 +176,20 @@ def __complex__(self): return 3.14j
174176
raise TestFailed, "eval(3)"
175177
if eval('c', globals, locals) != 300:
176178
raise TestFailed, "eval(4)"
177-
if eval(u'1+1') != 2: raise TestFailed, 'eval(u\'1+1\')'
178-
if eval(u' 1+1\n') != 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
179+
if have_unicode:
180+
if eval(unicode('1+1')) != 2: raise TestFailed, 'eval(u\'1+1\')'
181+
if eval(unicode(' 1+1\n')) != 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
179182
globals = {'a': 1, 'b': 2}
180183
locals = {'b': 200, 'c': 300}
181-
if eval(u'a', globals) != 1:
182-
raise TestFailed, "eval(1) == %s" % eval(u'a', globals)
183-
if eval(u'a', globals, locals) != 1:
184-
raise TestFailed, "eval(2)"
185-
if eval(u'b', globals, locals) != 200:
186-
raise TestFailed, "eval(3)"
187-
if eval(u'c', globals, locals) != 300:
188-
raise TestFailed, "eval(4)"
184+
if have_unicode:
185+
if eval(unicode('a'), globals) != 1:
186+
raise TestFailed, "eval(1) == %s" % eval(unicode('a'), globals)
187+
if eval(unicode('a'), globals, locals) != 1:
188+
raise TestFailed, "eval(2)"
189+
if eval(unicode('b'), globals, locals) != 200:
190+
raise TestFailed, "eval(3)"
191+
if eval(unicode('c'), globals, locals) != 300:
192+
raise TestFailed, "eval(4)"
189193

190194
print 'execfile'
191195
z = 0
@@ -249,9 +253,11 @@ def identity(item):
249253
if float(314) != 314.0: raise TestFailed, 'float(314)'
250254
if float(314L) != 314.0: raise TestFailed, 'float(314L)'
251255
if float(" 3.14 ") != 3.14: raise TestFailed, 'float(" 3.14 ")'
252-
if float(u" 3.14 ") != 3.14: raise TestFailed, 'float(u" 3.14 ")'
253-
if float(u" \u0663.\u0661\u0664 ") != 3.14:
254-
raise TestFailed, 'float(u" \u0663.\u0661\u0664 ")'
256+
if have_unicode:
257+
if float(unicode(" 3.14 ")) != 3.14:
258+
raise TestFailed, 'float(u" 3.14 ")'
259+
if float(unicode(" \u0663.\u0661\u0664 ")) != 3.14:
260+
raise TestFailed, 'float(u" \u0663.\u0661\u0664 ")'
255261

256262
print 'getattr'
257263
import sys
@@ -324,7 +330,9 @@ def f(): pass
324330
if int(-3.5) != -3: raise TestFailed, 'int(-3.5)'
325331
# Different base:
326332
if int("10",16) != 16L: raise TestFailed, 'int("10",16)'
327-
if int(u"10",16) != 16L: raise TestFailed, 'int(u"10",16)'
333+
if have_unicode:
334+
if int(unicode("10"),16) != 16L:
335+
raise TestFailed, 'int(u"10",16)'
328336
# Test conversion from strings and various anomalies
329337
L = [
330338
('0', 0),
@@ -343,23 +351,26 @@ def f(): pass
343351
(' 1\02 ', ValueError),
344352
('', ValueError),
345353
(' ', ValueError),
346-
(' \t\t ', ValueError),
347-
(u'0', 0),
348-
(u'1', 1),
349-
(u'9', 9),
350-
(u'10', 10),
351-
(u'99', 99),
352-
(u'100', 100),
353-
(u'314', 314),
354-
(u' 314', 314),
355-
(u'\u0663\u0661\u0664 ', 314),
356-
(u' \t\t 314 \t\t ', 314),
357-
(u' 1x', ValueError),
358-
(u' 1 ', 1),
359-
(u' 1\02 ', ValueError),
360-
(u'', ValueError),
361-
(u' ', ValueError),
362-
(u' \t\t ', ValueError),
354+
(' \t\t ', ValueError)
355+
]
356+
if have_unicode:
357+
L += [
358+
(unicode('0'), 0),
359+
(unicode('1'), 1),
360+
(unicode('9'), 9),
361+
(unicode('10'), 10),
362+
(unicode('99'), 99),
363+
(unicode('100'), 100),
364+
(unicode('314'), 314),
365+
(unicode(' 314'), 314),
366+
(unicode('\u0663\u0661\u0664 '), 314),
367+
(unicode(' \t\t 314 \t\t '), 314),
368+
(unicode(' 1x'), ValueError),
369+
(unicode(' 1 '), 1),
370+
(unicode(' 1\02 '), ValueError),
371+
(unicode(''), ValueError),
372+
(unicode(' '), ValueError),
373+
(unicode(' \t\t '), ValueError),
363374
]
364375
for s, v in L:
365376
for sign in "", "+", "-":
@@ -460,16 +471,23 @@ class E:
460471
if long(3.5) != 3L: raise TestFailed, 'long(3.5)'
461472
if long(-3.5) != -3L: raise TestFailed, 'long(-3.5)'
462473
if long("-3") != -3L: raise TestFailed, 'long("-3")'
463-
if long(u"-3") != -3L: raise TestFailed, 'long(u"-3")'
474+
if have_unicode:
475+
if long(unicode("-3")) != -3L:
476+
raise TestFailed, 'long(u"-3")'
464477
# Different base:
465478
if long("10",16) != 16L: raise TestFailed, 'long("10",16)'
466-
if long(u"10",16) != 16L: raise TestFailed, 'long(u"10",16)'
479+
if have_unicode:
480+
if long(unicode("10"),16) != 16L:
481+
raise TestFailed, 'long(u"10",16)'
467482
# Check conversions from string (same test set as for int(), and then some)
468483
LL = [
469484
('1' + '0'*20, 10L**20),
470-
('1' + '0'*100, 10L**100),
471-
(u'1' + u'0'*20, 10L**20),
472-
(u'1' + u'0'*100, 10L**100),
485+
('1' + '0'*100, 10L**100)
486+
]
487+
if have_unicode:
488+
L+=[
489+
(unicode('1') + unicode('0')*20, 10L**20),
490+
(unicode('1') + unicode('0')*100, 10L**100),
473491
]
474492
for s, v in L + LL:
475493
for sign in "", "+", "-":

0 commit comments

Comments
 (0)