Qf`ctdZddlZddlZddlmZmZddlZddlm Z ddl Z gdZ e Z Gdde ZGdd e Zd ZeGd d eZeGd deZgdZGddZGddZedZedZedZedZdZdZdZdZdZdZdZ Gdd e!Z"Gd!d"e"Z#Gd#d$e"Z$Gd%d&Z%d'Z&Gd(d)e#Z'Gd*d+e$Z(e#Z)e)jTZ+d,Z,e)jZZ.e)j^Z/e)j`Z1e)jdZ3e)jhZ4e)jjZ6e)jnZ8e)jrZ:d-Z;d.Zd1Z?eje?d2d2jZBd3ZCd4ZDeEd5k(reDejyy)6a$Calendar printing functions Note when comparing these calendars to the ones printed by cal(1): By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention). Use setfirstweekday() to set the first day of the week (0=Monday, 6=Sunday).N)IntEnum global_enum)repeat)-IllegalMonthErrorIllegalWeekdayErrorsetfirstweekday firstweekdayisleapleapdaysweekday monthrange monthcalendarprmonthmonthprcalcalendartimegm month_name month_abbrday_nameday_abbrCalendar TextCalendar HTMLCalendarLocaleTextCalendarLocaleHTMLCalendar weekheaderDayMonthJANUARYFEBRUARYMARCHAPRILMAYJUNEJULYAUGUST SEPTEMBEROCTOBERNOVEMBERDECEMBERMONDAYTUESDAY WEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAYceZdZdZdZy)rc||_yNr)selfrs //opt/alt/python312/lib64/python3.12/calendar.py__init__zIllegalMonthError.__init__ s  c d|jzS)Nz!bad month number %r; must be 1-12r6r7s r8__str__zIllegalMonthError.__str__"s2TZZ??r:N__name__ __module__ __qualname__r9r=r:r8rrs @r:rceZdZdZdZy)rc||_yr5r )r7r s r8r9zIllegalWeekdayError.__init__'s  r:c d|jzS)Nz7bad weekday number %r; must be 0 (Monday) to 6 (Sunday)rEr<s r8r=zIllegalWeekdayError.__str__)sH4<<WWr:Nr>rBr:r8rr&s Xr:rc|dvr8tjd|d|jdtd|dk(ryyt d t d |d ) N)JanuaryFebruaryzThe 'z ' attribute is deprecated, use 'z ' instead) stacklevelrHzmodule 'z' has no attribute '')warningswarnupperDeprecationWarningAttributeErrorr?)names r8 __getattr__rT-s^ && dV#CDJJL>QZ[(Q 8 9  8H:-A$qI JJr:c<eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy )rrLrJ N)r?r@rAr r!r"r#r$r%r&r'r(r)r*r+rBr:r8rr:s>GH E E C D D FIGHHr:rc(eZdZdZdZdZdZdZdZdZ y) rrrLrJrVrWrXrYN) r?r@rAr,r-r.r/r0r1r2rBr:r8rrKs% FGIH FH Fr:r) rrararcrararcrarcrac eZdZedDcgc]&}t j d|dzdj (c}}}ZejdddZ dZ dZ y cc}}}w) _localized_monthr_rLrcy)NrB)xs r8z_localized_month.asr:c||_yr5formatr7rms r8r9z_localized_month.__init__c  r:c|j|}t|tr |Dcgc]}||jc}S||jScc}wr5)_months isinstanceslicermr7ifuncsfs r8 __getitem__z_localized_month.__getitem__fsJ Q a ,12EqAdkkNE2 2% %3Acy)N rBr<s r8__len__z_localized_month.__len__msr:N) r?r@rArangedatetimedatestrftimerqinsertr9rxr|.0rur~s000r8rere^sT=B2YGYx}}T1Q3*33YGG NN1l#&Hs+Arec eZdZedDcgc]&}t j dd|dzj (c}}}ZdZdZ dZ ycc}}}w)_localized_dayrZrfrLc||_yr5rlrns r8r9z_localized_day.__init__vror:c|j|}t|tr |Dcgc]}||jc}S||jScc}wr5)_daysrrrsrmrts r8rxz_localized_day.__getitem__ysJ 1  a ,12EqAdkkNE2 2% %3rycyNrZrBr<s r8r|z_localized_day.__len__sr:N) r?r@rAr}r~rrrr9rxr|rs000r8rrqsI&, ?E ;r:cBt||tk(xr t|zSr5)rr!r rrs r8 _monthlenrs <5H,= >>r:c(|dk(r|dz dfS||dz fS)NrLr_rBrs r8 _prevmonthrs% zAvrzU1W}r:c(|dk(r|dzdfS||dzfS)Nr_rLrBrs r8 _nextmonthrs% {AvqyU1W}r:ceZdZdZddZdZdZeeeZdZ dZ dZ dZ d Z d Zd Zd Zd ZddZddZddZy)rzo Base calendar class. This class doesn't do any formatting. It simply provides data to subclasses. c||_yr5r r7r s r8r9zCalendar.__init__s (r:c |jdzSr _firstweekdayr<s r8getfirstweekdayzCalendar.getfirstweekdays!!A%%r:c||_yr5rrs r8rzCalendar.setfirstweekdays )r:c#jKt|j|jdzD] }|dz yw)zt Return an iterator for one week of weekday numbers starting with the configured first one. rZN)r}r )r7rus r8 iterweekdayszCalendar.iterweekdayss4 t(($*;*;a*?@AA#IAs13c#tK|j||D]\}}}tj|||!yw)z Return an iterator for one month. The iterator will yield datetime.date values and will always iterate through complete weeks, so it will yield dates outside the specified month. N)itermonthdays3r~r)r7rrymds r8itermonthdateszCalendar.itermonthdatess8 **47GAq!--1a( (8s68c#Kt||\}}||jz dz}td|Ed{td|dzEd{|j|z |z dz}td|Ed{y7E707 w)z Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0. rZrNrL)r r rr})r7rrrr days_before days_afters r8 itermonthdayszCalendar.itermonthdayss !u- ed///14 ![)))EAI&&&''$.6!; !Z((( *&(s31A?A9A? A; (A?3A=4A?;A?=A?c#zKt|j|||jD]\}}||dzfyw)z Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0. rZN) enumeraterr )r7rrrurs r8itermonthdays2zCalendar.itermonthdays2s> d00u=t?P?PQDAqQU(NRs9;c#tKt||\}}||jz dz}|j|z |z dz}t||\}}t||dz} t | |z | D] } ||| f t d|dzD] } ||| f t ||\}}t d|dzD] } ||| f yw)z Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range. rZrLN)r r rrr}r) r7rrrrrrrrendrs r8rzCalendar.itermonthdays3s !u- ed///14 ''$.6!; $&11o!s;,AQ'M-q%!)$Aq. %$&1q*q.)AQ'M*sB6B8c#Kt|j||D]!\}\}}}||||j|zdzf#yw)z Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples. Can be used for dates outside of datetime.date range. rZN)rrr )r7rrrurrrs r8itermonthdays4zCalendar.itermonthdays4sN &d&9&9$&FGLAy1aQD--1Q66 6HsAAct|j||}tdt|dDcgc] }|||dz c}Scc}w)z Return a matrix (list of lists) representing a month's calendar. Each row represents a week; week entries are datetime.date values. rrZ)listrr}len)r7rrdatesrus r8monthdatescalendarzCalendar.monthdatescalendar sL T((u56',QE A'>@'>!q1'>@@@Act|j||}tdt|dDcgc] }|||dz c}Scc}w)z Return a matrix representing a month's calendar. Each row represents a week; week entries are (day number, weekday number) tuples. Day numbers outside this month are zero. rrZ)rrr}rr7rrdaysrus r8monthdays2calendarzCalendar.monthdays2calendarsLD''e45&+As4y!&<>&<a!&<>>>rct|j||}tdt|dDcgc] }|||dz c}Scc}w)z Return a matrix representing a month's calendar. Each row represents a week; days outside this month are zero. rrZ)rrr}rrs r8monthdayscalendarzCalendar.monthdayscalendarsL D&&tU34&+As4y!&<>&<a!&<>>>rctDcgc]}|j||}}tdt||Dcgc] }||||z c}Scc}wcc}w)a' Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months. Each month contains between 4 and 6 weeks and each week contains 1-7 days. Days are datetime.date objects. r)rrr}rr7rwidthrmonthsrus r8yeardatescalendarzCalendar.yeardatescalendar'^=BBEq$))$2EB+0CK+GI+Gaq5!+GIICI AActDcgc]}|j||}}tdt||Dcgc] }||||z c}Scc}wcc}w)z Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are (day number, weekday number) tuples. Day numbers outside this month are zero. r)rrr}rrs r8yeardays2calendarzCalendar.yeardays2calendar1rrctDcgc]}|j||}}tdt||Dcgc] }||||z c}Scc}wcc}w)z Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are day numbers. Day numbers outside this month are zero. r)rrr}rrs r8yeardayscalendarzCalendar.yeardayscalendar;s^ t|j||dy)z3 Print a single week (no newline). rhrN)print formatweekr7theweekrs r8prweekzTextCalendar.prweekKs doogu-26r:c>|dk(rd}nd|z}|j|S)z* Returns a formatted day. rrhz%2icenter)r7rr rss r8 formatdayzTextCalendar.formatdayQs' !8A Axxr:c<djfd|DS)zA Returns a single week in a string (no newline).  c3JK|]\}}j||ywr5r)rrwdr7rs r8 z*TextCalendar.formatweek.._s#LG!Rq"e4Gs #joinrs` `r8rzTextCalendar.formatweek[sxxLGLLLr:cT|dk\rt}nt}||d|j|S)z4 Returns a formatted week day name. r\N)rrr)r7rrnamess r8 formatweekdayzTextCalendar.formatweekdayas1 A:EESz&5!((//r:cXdjfdjDS)z- Return a header for a week. rc3BK|]}j|ywr5r)rrur7rs r8rz0TextCalendar.formatweekheader..os!R>Q**1e4>Qsrr)r7rs``r8formatweekheaderzTextCalendar.formatweekheaderks#xxRd>O>O>QRRRr:cHt|}|r|d|}|j|S)z0 Return a formatted month name. r)rr)r7theyearthemonthrwithyearrs r8formatmonthnamezTextCalendar.formatmonthnameqs) x  g&Axxr:cBt|j||||dy)z+ Print a month's calendar. rhrN)r formatmonth)r7rrwls r8rzTextCalendar.prmonthzs dw!Q7R@r:cvtd|}td|}|j||d|dzzdz }|j}|d|zz }||j|jz }|d|zz }|j ||D]-}||j ||jz }|d|zz }/|S)z@ Return a month's calendar string (multi-line). rJrLrZ )maxrrstriprrr)r7rrrrrweeks r8rzTextCalendar.formatmonths 1I 1I  (AQK!O D HHJ TAX  T " "1 % , , .. TAX ++GX>D q)002 2A MA?r:c td|}td|}td|}|dzdzdz g}|j}|tj|z||dz zzj |d|zj |t j|D]A\}} t||zdzt||dzzdzd} |d|zfd| D} |t| |j |d|zfd| D} |t| |j |d|ztd| D} t| D]{}g}| D]F}|t|k\r|jd #|jj|||H|t||j |d|z}Dd j|S) zC Returns a year's calendar as a multi-line string. rJrLrZrr{c3FK|]}j|dyw)FN)r)rkcolwidthr7rs r8rz*TextCalendar.formatyear..s*&$))'1hF$s!c3"K|]}ywr5rB)rrheaders r8rz*TextCalendar.formatyear..s.v!vvs c32K|]}t|ywr5)r)rcals r8rz*TextCalendar.formatyear..s1ScSSsrh)rappendreprrrrrrr}min formatstringrrr)r7rrrcrvarurowrrheadersheightjweeksr rrs`` @@r8 formatyearzTextCalendar.formatyears 1I 1I 1IEQ;?  HH $w-  xz!QqS'1 2 9 9 ;< $q& &&q)!$"8"8!"DEHQ1Q3q5#a1gai"45F d1fI&$&E l5(A.557 8 d1fI.v.G l7Ha0779 : d1fI1S11F6]CCH} R( T__SVQ%?@  ,uh299;<$( #F,wwqzr:c Dt|j|||||dy)zPrint a year's calendar.rhrN)rr)r7rrrrrs r8pryearzTextCalendar.pryears doogq!Q2;r:NT)rr)rJrLrYrV)rrrYrV)r?r@rArrrrrrrrrrrrBr:r8rrEs= 7 M 0S A  #J z%d)cssclass_noday cssclasses)r7rr s r8rzHTMLCalendar.formatdays5 !8/$2E2EE E+tw/G.MM Mr:cBdjfd|D}d|zS)z8 Return a complete week as a table row. rhc3HK|]\}}j||ywr5r)rrrr7s r8rz*HTMLCalendar.formatweek..s!Agq"DNN1b)s" %sr)r7rrs` r8rzHTMLCalendar.formatweeks$ GGAA Aq  r:c<d|j|dt|dS)z: Return a weekday name as a table header. z z)cssclasses_weekday_headr)r7rs r8rzHTMLCalendar.formatweekdays"  ( ( -x}> >r:c^djfdjD}d|zS)z< Return a header for a week as a table row. rhc3@K|]}j|ywr5r)rrur7s r8rz0HTMLCalendar.formatweekheader..sG3FaD&&q)3Fr(r)r7rs` r8rzHTMLCalendar.formatweekheaders- GGG43D3D3FG Gq  r:cb|rt|d|}n dt|z}d|jd|dS)z5 Return a month name as a table row. rz%szrrrh)r cssclass_monthrrrrr)r7rrrrrrs r8rzHTMLCalendar.formatmonths  HH I    ! " $ $  w8  DE $ $   !" $++GX>D dood# $ dG? *  $wwqzr:c g}|j}t|d}|d|jz|d|d||j|fzt t t dz|D]\}t |t ||zd}|d|D],}|d||j||d |d .|d ^|d dj|S)z? Return a formatted year as a table of tables. rLr2rz,%sr_r{zzFr3zzr4rh) r r cssclass_yearcssclass_year_headr}r r rr)r7rrrrrurrs r8rzHTMLCalendar.formatyears  HHE1  I      $ 8 4**G<5 5 6w E2A1c!E'2./F fI& $""7A">?'  gJ3 * wwqzr:Nc|tj}g}|j}|d|z|d|d|d|d|z| |d|z|d|z|d|d ||j|||d |d d j |j |d S)zB Return a formatted year as a complete HTML page. z$ zn z z zC z4 zCalendar for %d z z z z rhxmlcharrefreplace)sysgetdefaultencodingr rrencode)r7rrcssencodingrrs r8formatyearpagezHTMLCalendar.formatyearpage*s  --/H  HH 1H <= {| *  *  PS[ [\ ? EK L ,w 67 + *  $//'5 )* + +wwqz  +>??r:rr)rV calendar.cssN)r?r@rArr%r+r$r0r5r8r7rrrrrrrr@rBr:r8rrsf CJ)N"N MN!>! )(0@r:rceZdZdZdZdZy)different_localec ||_d|_yr5)locale oldlocale)r7rEs r8r9zdifferent_locale.__init__Cs r:ctjtjd|_tjtj|jyr5)_locale setlocaleLC_TIMErFrEr<s r8 __enter__zdifferent_locale.__enter__Gs2 **7??DA'//4;;7r:cz|jytjtj|jyr5)rFrHrIrJ)r7argss r8__exit__zdifferent_locale.__exit__Ks' >> ! '//4>>:r:N)r?r@rAr9rKrNrBr:r8rCrCBs8;r:rCctjtjd}|dk(r:td5tjtjd}ddd|S|S#1swY|SxYw)NCrh)rHrIrJrCrEs r8_get_default_localerRQs\   w 5F } b !&&w=F" M6M " Ms %A&&A0c6eZdZdZddZfdZdfd ZxZS)r This class can be passed a locale name in the constructor and will return month and weekday names in the specified locale. cVtj||| t}||_yr5)rr9rRrEr7r rEs r8r9zLocaleTextCalendar.__init__a&dL1 >(*F r:czt|j5t| ||cdddS#1swYyxYwr5rCrEsuperr)r7rr __class__s r8rz LocaleTextCalendar.formatweekdaygs/ dkk *7(e4 5 5 * *s1:c~t|j5t| ||||cdddS#1swYyxYwr5rCrErZr)r7rrrrr[s r8rz"LocaleTextCalendar.formatmonthnameks5 dkk *7*7HeXN O O * *s3<rNrr?r@rArr9rr __classcell__r[s@r8rr[s  5OOr:rc6eZdZdZddZfdZdfd ZxZS)rrTcVtj||| t}||_yr5)rr9rRrErVs r8r9zLocaleHTMLCalendar.__init__urWr:cxt|j5t| |cdddS#1swYyxYwr5rY)r7rr[s r8rz LocaleHTMLCalendar.formatweekday{s- dkk *7(- . . * *s09c|t|j5t| |||cdddS#1swYyxYwr5r])r7rrrr[s r8rz"LocaleHTMLCalendar.formatmonthnames3 dkk *7*7HhG H H * *s2;r^rr_ras@r8rrps .HHr:rcnt|cxkrtkst|t||t_yr5)r,r2rrr rs r8rrs1 \ +V +!,// ,!,//!ANr:rYc0tt|||y)z1Prints multi-column formatting for year calendarsN)rr colsrspacings r8rmrms ,tXw /0r:cB|dz}|jfd|DS)zEReturns a string formatted from n strings, centered within n columns.rc3@K|]}|jywr5r)rrrs r8rzformatstring..s9Dq*Dr.rris ` r8r r s! sNG <<9D9 99r:irLc|dd\}}}}}}tj||djtz |zdz }|dz|z}|dz|z} | dz|z} | S)zBUnrelated but handy function to calculate Unix timestamp from GMT.NrYrL<)r~r toordinal _EPOCH_ORD) tuplerrrhourminutesecondrhoursminutessecondss r8rrsr-22AY*D%dFF ==ua ( 2 2 4z AC G! KD GdNEBhGbj6!G Nr:cnddl}|j}|jd}|jd}|jddtdd|jd d td d |jd dtdd|jddtdd|jdddd|jdddd|jdddd|jd d!d"d#d$%|jd&d'td()|jd*d'td+)|j |d d}|j r2|js&|jd,tjd |j |jf}|jd-k(r#|j r t|.}n t}|j}|tj}t||j /} tj"j$j&} |j(@| |j*t,j.j1j(fi| y|j2$| |j*|j(fi| y|jd0tjd y|j r t5|.}n t7}t|j8|j:1} |j2|j<| d2<|j>| d3<|j(:|j@t,j.j1j(fi| } nR|j2|j@|j(fi| } n(|jB|j(|j2fi| } tj"j&} |jr?| jE|j} tj"j$j&} | | y)4Nrztext only argumentszhtml only argumentsz-wz--widthrJz width of date column (default 2))typedefaulthelpz-lz--linesrLz)number of lines for each week (default 1)z-sz --spacingrYz"spacing between months (default 6)z-mz--monthsrVzmonths per row (default 3)z-cz--cssrAzCSS to use for page)r|r}z-Lz--localez)locale to use for month and weekday namesz-ez --encodingzencoding to use for outputz-tz--typetext)r~htmlzoutput type (text or html))r|choicesr}r?z year number)nargsr{r}rzmonth number (1-12, text only)z/if --locale is specified --encoding is requiredrrQ)r?r>zincorrect number of arguments)rrrr)#argparseArgumentParseradd_argument_group add_argumentint parse_argsrEr?errorr;exitr{rrr<dictr>stdoutbufferwriterr@r~rtodayrrrrlinesrkrrrr=) rMrparser textgroup htmlgroupoptionsrEr r?optdictrresults r8mainrs  $ $ &F))*?@I))*?@I  i ! /  i ! 8  k ! 1  j ! )  g "   j 8   l )   h )       - QR)G~~g.. FG  ^^W-- -F||v >>$F3C.C##  --/Hgkk: !!'' <<  $#$$X]]%8%8%:%?%?K7K L ]] " $#$$W\\=W= > LL8 9 HHQK >>$F3C.C'--8 == "??GCL">>GCL << #S^^HMM$7$7$9$>$>J'JF ]] "#S^^GLLrs!7 % ! @ @X*X K  G     '  <&( $  $ d # d # B G:?EJvEJPr<8r