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

Skip to content

Commit db6888b

Browse files
committed
_make_boundary(): Fix for SF bug #745478, broken boundary calculation
in some locales. This code simplifies the boundary algorithm to use randint() which is what we wanted anyway. Bump package version to 2.5.3. Backport candidate for Python 2.2.3
1 parent 65f8ced commit db6888b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/email/Generator.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import re
8+
import sys
89
import time
910
import locale
1011
import random
@@ -356,11 +357,14 @@ def _dispatch(self, msg):
356357

357358

358359
# Helper
360+
_width = len(repr(sys.maxint-1))
361+
_fmt = '%%0%dd' % _width
362+
359363
def _make_boundary(text=None):
360364
# Craft a random boundary. If text is given, ensure that the chosen
361365
# boundary doesn't appear in the text.
362-
dp = locale.localeconv().get('decimal_point', '.')
363-
boundary = ('=' * 15) + repr(random.random()).split(dp)[1] + '=='
366+
token = random.randint(0, sys.maxint-1)
367+
boundary = ('=' * 15) + (_fmt % token) + '=='
364368
if text is None:
365369
return boundary
366370
b = boundary

Lib/email/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""A package for parsing, handling, and generating email messages.
55
"""
66

7-
__version__ = '2.5.2'
7+
__version__ = '2.5.3'
88

99
__all__ = [
1010
'base64MIME',

0 commit comments

Comments
 (0)