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

Skip to content

Commit fd68087

Browse files
committed
#3059: Stop decoding Unicode in calendar module.
The strftime routines must know how to decode localized month/day names themselves.
1 parent f010bd5 commit fd68087

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

Lib/calendar.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -481,13 +481,13 @@ def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
481481
return ''.join(v).encode(encoding, "xmlcharrefreplace")
482482

483483

484-
class TimeEncoding:
484+
class different_locale:
485485
def __init__(self, locale):
486486
self.locale = locale
487487

488488
def __enter__(self):
489489
self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale)
490-
return _locale.getlocale(_locale.LC_TIME)[1]
490+
#return _locale.getlocale(_locale.LC_TIME)[1]
491491

492492
def __exit__(self, *args):
493493
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
@@ -508,21 +508,17 @@ def __init__(self, firstweekday=0, locale=None):
508508
self.locale = locale
509509

510510
def formatweekday(self, day, width):
511-
with TimeEncoding(self.locale) as encoding:
511+
with different_locale(self.locale):
512512
if width >= 9:
513513
names = day_name
514514
else:
515515
names = day_abbr
516516
name = names[day]
517-
if encoding is not None:
518-
name = name.decode(encoding)
519517
return name[:width].center(width)
520518

521519
def formatmonthname(self, theyear, themonth, width, withyear=True):
522-
with TimeEncoding(self.locale) as encoding:
520+
with different_locale(self.locale):
523521
s = month_name[themonth]
524-
if encoding is not None:
525-
s = s.decode(encoding)
526522
if withyear:
527523
s = "%s %r" % (s, theyear)
528524
return s.center(width)
@@ -542,17 +538,13 @@ def __init__(self, firstweekday=0, locale=None):
542538
self.locale = locale
543539

544540
def formatweekday(self, day):
545-
with TimeEncoding(self.locale) as encoding:
541+
with different_locale(self.locale):
546542
s = day_abbr[day]
547-
if encoding is not None:
548-
s = s.decode(encoding)
549543
return '<th class="%s">%s</th>' % (self.cssclasses[day], s)
550544

551545
def formatmonthname(self, theyear, themonth, withyear=True):
552-
with TimeEncoding(self.locale) as encoding:
546+
with different_locale(self.locale):
553547
s = month_name[themonth]
554-
if encoding is not None:
555-
s = s.decode(encoding)
556548
if withyear:
557549
s = '%s %s' % (s, theyear)
558550
return '<tr><th colspan="7" class="month">%s</th></tr>' % s

0 commit comments

Comments
 (0)