Skip to content

Commit 3402d38

Browse files
committed
leave the None
1 parent f9a1671 commit 3402d38

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Doc/library/calendar.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
245245
specifies the number of months per row.
246246

247247

248-
.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding='utf-8')
248+
.. method:: formatyearpage(theyear, width=3, css='calendar.css', encoding=None)
249249

250250
Return a year's calendar as a complete HTML page. *width* (defaulting to
251251
3) specifies the number of months per row. *css* is the name for the
@@ -254,7 +254,7 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
254254
output (defaulting to ``utf-8``).
255255

256256
.. versionchanged:: next
257-
The default value of the *encoding* has been changed to utf-8.
257+
If *encoding* is None, utf-8 is used by default.
258258

259259
.. method:: formatmonthname(theyear, themonth, withyear=True)
260260

@@ -653,10 +653,11 @@ The following options are accepted:
653653
.. option:: --encoding ENCODING, -e ENCODING
654654

655655
The encoding to use for output.
656-
Defaults to utf-8.
656+
:option:`--encoding` is required if :option:`--locale` is set.
657+
Defaults to None.
657658

658659
.. versionchanged:: next
659-
The default value has been changed to utf-8.
660+
If *encoding* is None, utf-8 is used by default.
660661

661662
.. option:: --type {text,html}, -t {text,html}
662663

Lib/calendar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def formatyear(self, theyear, width=3):
560560
a('</table>')
561561
return ''.join(v)
562562

563-
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding='utf-8'):
563+
def formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None):
564564
"""
565565
Return a formatted year as a complete HTML page.
566566
"""
@@ -845,7 +845,7 @@ def main(args=None):
845845
)
846846
parser.add_argument(
847847
"-e", "--encoding",
848-
default="utf-8",
848+
default=None,
849849
help="encoding to use for output (default utf-8)"
850850
)
851851
parser.add_argument(
@@ -872,6 +872,10 @@ def main(args=None):
872872

873873
options = parser.parse_args(args)
874874

875+
if options.locale and not options.encoding:
876+
parser.error("if --locale is specified --encoding is required")
877+
sys.exit(1)
878+
875879
locale = options.locale, options.encoding
876880
today = datetime.date.today()
877881

Lib/test/test_calendar.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import datetime
88
import io
99
import locale
10+
import os
1011
import sys
1112
import time
1213

@@ -928,7 +929,7 @@ def test_several_leapyears_in_range(self):
928929

929930

930931
def conv(s):
931-
return s.encode()
932+
return s.replace('\n', os.linesep).encode()
932933

933934
class CommandLineTestCase(unittest.TestCase):
934935
def setUp(self):
@@ -1034,6 +1035,7 @@ def test_option_encoding(self):
10341035
def test_option_locale(self):
10351036
self.assertFailure('-L')
10361037
self.assertFailure('--locale')
1038+
self.assertFailure('-L', 'en')
10371039

10381040
lang, enc = locale.getlocale()
10391041
lang = lang or 'C'
@@ -1067,7 +1069,7 @@ def test_option_lines(self):
10671069
self.assertFailure('-l', 'spam')
10681070
for run in self.runners:
10691071
output = run('--lines', '2', '2004')
1070-
self.assertRegex(output, br'December(\r\n|\n){2}Mo Tu We')
1072+
self.assertIn(conv('December\n\nMo Tu We'), output)
10711073

10721074
def test_option_spacing(self):
10731075
self.assertFailure('-s')
@@ -1083,7 +1085,7 @@ def test_option_months(self):
10831085
self.assertFailure('-m', 'spam')
10841086
for run in self.runners:
10851087
output = run('--months', '1', '2004')
1086-
self.assertRegex(output, br'(\r\n|\n)Mo Tu We Th Fr Sa Su(\r\n|\n)')
1088+
self.assertIn(conv('\nMo Tu We Th Fr Sa Su\n'), output)
10871089

10881090
def test_option_type(self):
10891091
self.assertFailure('-t')

0 commit comments

Comments
 (0)