Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc7df344

Browse files
arihant2mathyouknowone
authored andcommitted
update calendar and test_calendar to 3.13.2
1 parent4094c5b commitc7df344

File tree

2 files changed

+238
-62
lines changed

2 files changed

+238
-62
lines changed

‎Lib/calendar.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
fromenumimportIntEnum,global_enum
1111
importlocaleas_locale
1212
fromitertoolsimportrepeat
13-
importwarnings
1413

1514
__all__= ["IllegalMonthError","IllegalWeekdayError","setfirstweekday",
1615
"firstweekday","isleap","leapdays","weekday","monthrange",
@@ -28,7 +27,9 @@
2827
error=ValueError
2928

3029
# Exceptions raised for bad input
31-
classIllegalMonthError(ValueError):
30+
# This is trick for backward compatibility. Since 3.13, we will raise IllegalMonthError instead of
31+
# IndexError for bad month number(out of 1-12). But we can't remove IndexError for backward compatibility.
32+
classIllegalMonthError(ValueError,IndexError):
3233
def__init__(self,month):
3334
self.month=month
3435
def__str__(self):
@@ -44,6 +45,7 @@ def __str__(self):
4445

4546
def__getattr__(name):
4647
ifnamein ('January','February'):
48+
importwarnings
4749
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
4850
DeprecationWarning,stacklevel=2)
4951
ifname=='January':
@@ -158,11 +160,14 @@ def weekday(year, month, day):
158160
returnDay(datetime.date(year,month,day).weekday())
159161

160162

161-
defmonthrange(year,month):
162-
"""Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for
163-
year, month."""
163+
def_validate_month(month):
164164
ifnot1<=month<=12:
165165
raiseIllegalMonthError(month)
166+
167+
defmonthrange(year,month):
168+
"""Return weekday of first day of month (0-6 ~ Mon-Sun)
169+
and number of days (28-31) for year, month."""
170+
_validate_month(month)
166171
day1=weekday(year,month,1)
167172
ndays=mdays[month]+ (month==FEBRUARYandisleap(year))
168173
returnday1,ndays
@@ -370,6 +375,8 @@ def formatmonthname(self, theyear, themonth, width, withyear=True):
370375
"""
371376
Return a formatted month name.
372377
"""
378+
_validate_month(themonth)
379+
373380
s=month_name[themonth]
374381
ifwithyear:
375382
s="%s %r"% (s,theyear)
@@ -500,6 +507,7 @@ def formatmonthname(self, theyear, themonth, withyear=True):
500507
"""
501508
Return a month name as a table row.
502509
"""
510+
_validate_month(themonth)
503511
ifwithyear:
504512
s='%s %s'% (month_name[themonth],theyear)
505513
else:
@@ -585,8 +593,6 @@ def __enter__(self):
585593
_locale.setlocale(_locale.LC_TIME,self.locale)
586594

587595
def__exit__(self,*args):
588-
ifself.oldlocaleisNone:
589-
return
590596
_locale.setlocale(_locale.LC_TIME,self.oldlocale)
591597

592598

@@ -690,7 +696,7 @@ def timegm(tuple):
690696
returnseconds
691697

692698

693-
defmain(args):
699+
defmain(args=None):
694700
importargparse
695701
parser=argparse.ArgumentParser()
696702
textgroup=parser.add_argument_group('text only arguments')
@@ -736,18 +742,23 @@ def main(args):
736742
choices=("text","html"),
737743
help="output type (text or html)"
738744
)
745+
parser.add_argument(
746+
"-f","--first-weekday",
747+
type=int,default=0,
748+
help="weekday (0 is Monday, 6 is Sunday) to start each week (default 0)"
749+
)
739750
parser.add_argument(
740751
"year",
741752
nargs='?',type=int,
742-
help="year number (1-9999)"
753+
help="year number"
743754
)
744755
parser.add_argument(
745756
"month",
746757
nargs='?',type=int,
747758
help="month number (1-12, text only)"
748759
)
749760

750-
options=parser.parse_args(args[1:])
761+
options=parser.parse_args(args)
751762

752763
ifoptions.localeandnotoptions.encoding:
753764
parser.error("if --locale is specified --encoding is required")
@@ -756,31 +767,35 @@ def main(args):
756767
locale=options.locale,options.encoding
757768

758769
ifoptions.type=="html":
770+
ifoptions.month:
771+
parser.error("incorrect number of arguments")
772+
sys.exit(1)
759773
ifoptions.locale:
760774
cal=LocaleHTMLCalendar(locale=locale)
761775
else:
762776
cal=HTMLCalendar()
777+
cal.setfirstweekday(options.first_weekday)
763778
encoding=options.encoding
764779
ifencodingisNone:
765780
encoding=sys.getdefaultencoding()
766781
optdict=dict(encoding=encoding,css=options.css)
767782
write=sys.stdout.buffer.write
768783
ifoptions.yearisNone:
769784
write(cal.formatyearpage(datetime.date.today().year,**optdict))
770-
elifoptions.monthisNone:
771-
write(cal.formatyearpage(options.year,**optdict))
772785
else:
773-
parser.error("incorrect number of arguments")
774-
sys.exit(1)
786+
write(cal.formatyearpage(options.year,**optdict))
775787
else:
776788
ifoptions.locale:
777789
cal=LocaleTextCalendar(locale=locale)
778790
else:
779791
cal=TextCalendar()
792+
cal.setfirstweekday(options.first_weekday)
780793
optdict=dict(w=options.width,l=options.lines)
781794
ifoptions.monthisNone:
782795
optdict["c"]=options.spacing
783796
optdict["m"]=options.months
797+
ifoptions.monthisnotNone:
798+
_validate_month(options.month)
784799
ifoptions.yearisNone:
785800
result=cal.formatyear(datetime.date.today().year,**optdict)
786801
elifoptions.monthisNone:
@@ -795,4 +810,4 @@ def main(args):
795810

796811

797812
if__name__=="__main__":
798-
main(sys.argv)
813+
main()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp