Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b28de0d

Browse files
committed
Patch to make _codecs a builtin module. This is necessary since
Python 2.3 will support source code encodings which rely on the builtin codecs being available to the parser. Remove struct dependency from codecs.py
1 parent b69bb3d commit b28de0d

4 files changed

Lines changed: 17 additions & 9 deletions

File tree

Lib/codecs.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
"""#"
99

10-
import struct, __builtin__
10+
import __builtin__, sys
1111

1212
### Registry and builtin stateless codec functions
1313

@@ -48,11 +48,21 @@
4848
# UTF-32, big endian
4949
BOM_UTF32_BE = '\x00\x00\xfe\xff'
5050

51-
# UTF-16, native endianness
52-
BOM = BOM_UTF16 = struct.pack('=H', 0xFEFF)
51+
if sys.byteorder == 'little':
5352

54-
# UTF-32, native endianness
55-
BOM_UTF32 = struct.pack('=L', 0x0000FEFF)
53+
# UTF-16, native endianness
54+
BOM = BOM_UTF16 = BOM_UTF16_LE
55+
56+
# UTF-32, native endianness
57+
BOM_UTF32 = BOM_UTF32_LE
58+
59+
else:
60+
61+
# UTF-16, native endianness
62+
BOM = BOM_UTF16 = BOM_UTF16_BE
63+
64+
# UTF-32, native endianness
65+
BOM_UTF32 = BOM_UTF32_BE
5666

5767
# Old broken names (don't use in new code)
5868
BOM32_LE = BOM_UTF16_LE

Modules/Setup.config.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
@USE_SIGNAL_MODULE@signal signalmodule.c
1111

1212
# The rest of the modules previously listed in this file are built
13-
# by the setup.py script in Python 2.1.
13+
# by the setup.py script in Python 2.1 and later.

Modules/Setup.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ PYTHONPATH=$(COREPYTHONPATH)
111111
posix posixmodule.c # posix (UNIX) system calls
112112
errno errnomodule.c # posix (UNIX) errno values
113113
_sre _sre.c # Fredrik Lundh's new regular expressions
114+
_codecs _codecsmodule.c # access to the builtin codecs and codec registry
114115

115116
# The rest of the modules listed in this file are all commented out by
116117
# default. Usually they can be detected and built as dynamically
@@ -163,7 +164,6 @@ GLHACK=-Dclear=__GLclear
163164
#time timemodule.c # -lm # time operations and variables
164165
#operator operator.c # operator.add() and similar goodies
165166
#_weakref _weakref.c # basic weak reference support
166-
#_codecs _codecsmodule.c # access to the builtin codecs and codec registry
167167
#_testcapi _testcapimodule.c # Python C API test module
168168

169169
#unicodedata unicodedata.c # static Unicode character database

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ def detect_modules(self):
313313
libraries=math_libs) )
314314
# operator.add() and similar goodies
315315
exts.append( Extension('operator', ['operator.c']) )
316-
# access to the builtin codecs and codec registry
317-
exts.append( Extension('_codecs', ['_codecsmodule.c']) )
318316
# Python C API test module
319317
exts.append( Extension('_testcapi', ['_testcapimodule.c']) )
320318
# static Unicode character database

0 commit comments

Comments
 (0)