grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B (R}i0ñûã@s0ddlZddlZddlZddlmZddddddd d d d d dddddddddddddgZeZGdd„deƒZ Gdd„deƒZ dZ dZ ddd dd!dd!ddd!dd!dg Z Gd"d#„d#ƒZGd$d%„d%ƒZed&ƒZed'ƒZed(ƒZed)ƒZed*ƒ\ZZZZZZZd+d„Zd,d„Zd-d „Zd.d „Zd/d0„Z d1d2„Z!d3d4„Z"Gd5d„de#ƒZ$Gd6d„de$ƒZ%Gd7d„de$ƒZ&Gd8d9„d9ƒZ'Gd:d„de%ƒZ(Gd;d„de&ƒZ)e%ƒZ*e*j+Z,dZ=ee4sz_localized_month.é rcCsdS)NÚr)ÚxrrrÚ5óz_localized_month.cCs ||_dS)N)Úformat)rr4rrrr7sz_localized_month.__init__cs4ˆj|}t|tƒr&‡fdd„|DƒS|ˆjƒSdS)Ncsg|]}|ˆjƒ‘qSr)r4)r,Úf)rrrr.=sz0_localized_month.__getitem__..)Ú_monthsÚ isinstanceÚslicer4)rr-Úfuncsr)rrÚ __getitem__:s  z_localized_month.__getitem__cCsdS)Né r)rrrrÚ__len__Asz_localized_month.__len__N) r r!r"Úranger6Úinsertrr:r<rrrrr(2s r(c@s6eZdZdd„edƒDƒZdd„Zdd„Zdd „Zd S) Ú_localized_daycCs g|]}t dd|d¡j‘qS)iÑr#)r)r*r+)r,r-rrrr.Hsz_localized_day.écCs ||_dS)N)r4)rr4rrrrJsz_localized_day.__init__cs4ˆj|}t|tƒr&‡fdd„|DƒS|ˆjƒSdS)Ncsg|]}|ˆjƒ‘qSr)r4)r,r5)rrrr.Psz._localized_day.__getitem__..)Ú_daysr7r8r4)rr-r9r)rrr:Ms  z_localized_day.__getitem__cCsdS)Nr@r)rrrrr<Tsz_localized_day.__len__N)r r!r"r=rArr:r<rrrrr?Esr?z%Az%az%Bz%br@cCs$|ddko"|ddkp"|ddkS)Nérédi�r)ÚyearrrrrdscCs@|d8}|d8}|d|d|d|d|d|dS)Nr#rBrCi�r)Zy1Zy2rrrriscCs8tj|krtjks&nd|d}t |||¡ ¡S)NiÐi�)r)ZMINYEARZMAXYEARr*r )rDr Údayrrrr qs cCsJd|krdksnt|ƒ‚t||dƒ}t||tko>t|ƒ}||fS)Nr#r/)rr ÚmdaysÚFebruaryr)rDr Úday1Úndaysrrrr xs  cCst||tkot|ƒS)N)rFrGr)rDr rrrÚmonthlen‚srJcCs$|dkr|ddfS||dfSdS)Nr#r/r)rDr rrrÚ prevmonth†s rKcCs$|dkr|ddfS||dfSdS)Nr/r#r)rDr rrrÚ nextmonth�s rLc@s–eZdZd"dd„Zdd„Zdd„ZeeeƒZdd „Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd#dd„Zd$dd„Zd%dd „Zd!S)&rrcCs ||_dS)N)r)rrrrrršszCalendar.__init__cCs |jdS)Nr@)Ú _firstweekday)rrrrÚgetfirstweekday�szCalendar.getfirstweekdaycCs ||_dS)N)rM)rrrrrr szCalendar.setfirstweekdayccs*x$t|j|jdƒD]}|dVqWdS)Nr@)r=r)rr-rrrÚ iterweekdays¥szCalendar.iterweekdaysccs0x*| ||¡D]\}}}t |||¡VqWdS)N)Úitermonthdays3r)r*)rrDr ÚyÚmÚdrrrÚitermonthdates­szCalendar.itermonthdatesccsft||ƒ\}}||jd}td|ƒEdHtd|dƒEdH|j||d}td|ƒEdHdS)Nr@rr#)r rrr=)rrDr rHrIÚ days_beforeÚ days_afterrrrÚ itermonthdays¶s zCalendar.itermonthdaysccs4x.t| ||¡|jƒD]\}}||dfVqWdS)Nr@)Ú enumeraterWr)rrDr r-rSrrrÚitermonthdays2ÂszCalendar.itermonthdays2c csÈt||ƒ\}}||jd}|j||d}t||ƒ\}}t||ƒd} x"t| || ƒD]} ||| fVqZWx"td|dƒD]} ||| fVq~Wt||ƒ\}}x"td|dƒD]} ||| fVq°WdS)Nr@r#)r rrKrJr=rL) rrDr rHrIrUrVrQrRÚendrSrrrrPÊszCalendar.itermonthdays3ccs@x:t| ||¡ƒD]&\}\}}}||||j|dfVqWdS)Nr@)rXrPr)rrDr r-rQrRrSrrrÚitermonthdays4Üs zCalendar.itermonthdays4cs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)Ncsg|]}ˆ||d…‘qS)r@r)r,r-)Údatesrrr.êsz/Calendar.monthdatescalendar..rr@)ÚlistrTr=Úlen)rrDr r)r\rÚmonthdatescalendaräszCalendar.monthdatescalendarcs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)Ncsg|]}ˆ||d…‘qS)r@r)r,r-)Údaysrrr.ôsz/Calendar.monthdays2calendar..rr@)r]rYr=r^)rrDr r)r`rÚmonthdays2calendarìszCalendar.monthdays2calendarcs.t| ||¡ƒ‰‡fdd„tdtˆƒdƒDƒS)Ncsg|]}ˆ||d…‘qS)r@r)r,r-)r`rrr.üsz.Calendar.monthdayscalendar..rr@)r]rWr=r^)rrDr r)r`rÚmonthdayscalendaröszCalendar.monthdayscalendarécs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)Ncsg|]}ˆ ˆ|¡‘qSr)r_)r,r-)rrDrrr.sz.Calendar.yeardatescalendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)ÚmonthsÚwidthrrr. sr)r=ÚJanuaryr^)rrDrer)rdrrerDrÚyeardatescalendarþs zCalendar.yeardatescalendarcs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)Ncsg|]}ˆ ˆ|¡‘qSr)ra)r,r-)rrDrrr.sz.Calendar.yeardays2calendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)rdrerrr.sr)r=rfr^)rrDrer)rdrrerDrÚyeardays2calendar s zCalendar.yeardays2calendarcs>‡‡fdd„tttdƒDƒ‰‡‡fdd„tdtˆƒˆƒDƒS)Ncsg|]}ˆ ˆ|¡‘qSr)rb)r,r-)rrDrrr.sz-Calendar.yeardayscalendar..r/csg|]}ˆ||ˆ…‘qSrr)r,r-)rdrerrr."sr)r=rfr^)rrDrer)rdrrerDrÚyeardayscalendars zCalendar.yeardayscalendarN)r)rc)rc)rc)r r!r"rrNrÚpropertyrrOrTrWrYrPr[r_rarbrgrhrirrrrr”s       c@sfeZdZdd„Zdd„Zdd„Zdd„Zd d „Zdd d „Zddd„Z ddd„Z ddd„Z d dd„Z dS)!rcCst| ||¡dd�dS)Nr0)rZ)ÚprintÚ formatweek)rÚtheweekrerrrÚprweek+szTextCalendar.prweekcCs |dkrd}nd|}| |¡S)Nrr0z%2i)Úcenter)rrEr reÚsrrrÚ formatday1szTextCalendar.formatdaycsd ‡‡fdd„|Dƒ¡S)Nú c3s |]\}}ˆ ||ˆ¡VqdS)N)rq)r,rSÚwd)rrerrú ?sz*TextCalendar.formatweek..)Újoin)rrmrer)rrerrl;szTextCalendar.formatweekcCs(|dkrt}nt}||d|… |¡S)Né )rrro)rrEreÚnamesrrrÚ formatweekdayAszTextCalendar.formatweekdaycsd ‡‡fdd„ˆ ¡Dƒ¡S)Nrrc3s|]}ˆ |ˆ¡VqdS)N)rx)r,r-)rrerrrtOsz0TextCalendar.formatweekheader..)rurO)rrer)rrerÚformatweekheaderKszTextCalendar.formatweekheaderTcCs"t|}|rd||f}| |¡S)Nz%s %r)rro)rÚtheyearÚthemonthreÚwithyearrprrrÚformatmonthnameQs zTextCalendar.formatmonthnamercCst| ||||¡dd�dS)Nr0)rZ)rkÚ formatmonth)rrzr{ÚwÚlrrrr ZszTextCalendar.prmonthcCsštd|ƒ}td|ƒ}| ||d|dd¡}| ¡}|d|7}|| |¡ ¡7}|d|7}x4| ||¡D]$}|| ||¡ ¡7}|d|7}qnW|S)Nr$r#r@Ú )Úmaxr}Úrstripryrarl)rrzr{rr€rpÚweekrrrr~`s    zTextCalendar.formatmonthr$r#ércc sÂtd|ƒ}td|ƒ}td|ƒ}|ddd‰g}|j}|tˆƒ ˆ|||d¡ ¡ƒ|d|ƒˆ |¡‰�x@tˆ ˆ|¡ƒD�]*\}} t||dt ||dddƒƒ} |d|ƒ‡‡‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒ‡fdd„| Dƒ} |t | ˆ|ƒ ¡ƒ|d|ƒtd d„| Dƒƒ} xvt| ƒD]j}g}x>| D]6}|t |ƒk�rr| d ¡n| ˆ  |||¡¡�qTW|t |ˆ|ƒ ¡ƒ|d|ƒ�qFWqˆWd   |¡S) Nr$r#r@r�r;c3s|]}ˆ ˆ|ˆd¡VqdS)FN)r})r,Úk)Úcolwidthrrzrrrt�sz*TextCalendar.formatyear..c3s|] }ˆVqdS)Nr)r,r†)Úheaderrrrt…scss|]}t|ƒVqdS)N)r^)r,Úcalrrrrt‰sr0)r‚ÚappendÚreprrorƒryrXrhr=ÚminÚ formatstringr^rlru)rrzrr€ÚcrRÚvÚar-ÚrowrdrwZheadersZheightÚjZweeksr‰r)r‡rˆrrzrÚ formatyearps:   &  $     zTextCalendar.formatyearcCst| |||||¡dd�dS)Nr0)rZ)rkr“)rrzrr€rŽrRrrrÚpryear•szTextCalendar.pryearN)T)rr)rr)r$r#r…rc)rrr…rc) r r!r"rnrqrlrxryr}r r~r“r”rrrrr%s     %c@s~eZdZdddddddgZeZdZd Zd Zd Zd Z d d „Z d d„Z dd„Z dd„Z ddd„Zd dd„Zd!dd„Zd"dd„ZdS)#rZmonZtueZwedZthuZfriZsatZsunZnodayr rDcCs(|dkrd|jSd|j||fSdS)Nrz z%d)Úcssclass_nodayÚ cssclasses)rrEr rrrrq´s zHTMLCalendar.formatdaycs d ‡fdd„|Dƒ¡}d|S)Nr0c3s|]\}}ˆ ||¡VqdS)N)rq)r,rSrs)rrrrtÂsz*HTMLCalendar.formatweek..z %s)ru)rrmrpr)rrrl¾szHTMLCalendar.formatweekcCsd|j|t|fS)Nz%s)Úcssclasses_weekday_headr)rrErrrrxÅszHTMLCalendar.formatweekdaycs$d ‡fdd„ˆ ¡Dƒ¡}d|S)Nr0c3s|]}ˆ |¡VqdS)N)rx)r,r-)rrrrtÐsz0HTMLCalendar.formatweekheader..z %s)rurO)rrpr)rrryÌszHTMLCalendar.formatweekheaderTcCs0|rdt||f}n dt|}d|j|fS)Nz%s %sz%sz+%s)rÚcssclass_month_head)rrzr{r|rprrrr}Ós  zHTMLCalendar.formatmonthnamecCs–g}|j}|d|jƒ|dƒ||j|||d�ƒ|dƒ|| ¡ƒ|dƒx*| ||¡D]}|| |¡ƒ|dƒq^W|dƒ|dƒd |¡S)Nz=r�)r|z
r0)rŠÚcssclass_monthr}ryrarlru)rrzr{r|r�r�r„rrrr~Þs   zHTMLCalendar.formatmonthrccCsÀg}|j}t|dƒ}|d|jƒ|dƒ|d||j|fƒxntttd|ƒD]Z}t|t||dƒƒ}|dƒx0|D](}|dƒ||j||d d �ƒ|d ƒqvW|d ƒqPW|d ƒd |¡S)Nr#z=r�z,r/r;zzzz
%s
F)r|z
r0) rŠr‚Ú cssclass_yearÚcssclass_year_headr=rfrŒr~ru)rrzrer�r�r-rdrRrrrr“òs$     zHTMLCalendar.formatyearú calendar.cssNcCs¬|dkrt ¡}g}|j}|d|ƒ|dƒ|dƒ|dƒ|d|ƒ|dk r^|d|ƒ|d|ƒ|dƒ|d ƒ|| ||¡ƒ|d ƒ|d ƒd  |¡ |d ¡S)Nz$ zn z z zC z4 zCalendar for %d z z z z r0Úxmlcharrefreplace)ÚsysÚgetdefaultencodingrŠr“ruÚencode)rrzreÚcssÚencodingr�r�rrrÚformatyearpage s$    zHTMLCalendar.formatyearpage)T)T)rc)rcrœN)r r!r"r–r—r•r˜r™r›ršrqrlrxryr}r~r“r£rrrrršs   c@s$eZdZdd„Zdd„Zdd„ZdS)Údifferent_localecCs ||_dS)N)Úlocale)rr¥rrrr#szdifferent_locale.__init__cCs"t tj¡|_t tj|j¡dS)N)Ú_localeÚ getlocaleÚLC_TIMEÚ oldlocaleÚ setlocaler¥)rrrrÚ __enter__&szdifferent_locale.__enter__cGst tj|j¡dS)N)r¦rªr¨r©)rÚargsrrrÚ__exit__*szdifferent_locale.__exit__N)r r!r"rr«r­rrrrr¤"sr¤c@s(eZdZd dd„Zdd„Zd dd „ZdS) rrNcCs&t ||¡|dkrt ¡}||_dS)N)rrr¦Úgetdefaultlocaler¥)rrr¥rrrr6s zLocaleTextCalendar.__init__c CsBt|jƒ�.|dkrt}nt}||}|d|… |¡SQRXdS)Nrv)r¤r¥rrro)rrErerwÚnamerrrrx<s  z LocaleTextCalendar.formatweekdayTc Cs8t|jƒ�$t|}|r$d||f}| |¡SQRXdS)Nz%s %r)r¤r¥rro)rrzr{rer|rprrrr}Es   z"LocaleTextCalendar.formatmonthname)rN)T)r r!r"rrxr}rrrrr.s  c@s(eZdZd dd„Zdd„Zd dd „ZdS) rrNcCs&t ||¡|dkrt ¡}||_dS)N)rrr¦r®r¥)rrr¥rrrrTs zLocaleHTMLCalendar.__init__c Cs0t|jƒ�t|}d|j||fSQRXdS)Nz%s)r¤r¥rr–)rrErprrrrxZs z LocaleHTMLCalendar.formatweekdayTc Cs6t|jƒ�"t|}|r$d||f}d|SQRXdS)Nz%s %sz.%s)r¤r¥r)rrzr{r|rprrrr}_s   z"LocaleHTMLCalendar.formatmonthname)rN)T)r r!r"rrxr}rrrrrMs cCs(t|krtksnt|ƒ‚|t_dS)N)ÚMONDAYÚSUNDAYrrŽr)rrrrrlsér…cCstt|||ƒƒdS)N)rkr�)Úcolsr‡Úspacingrrrr4€sr4cs |d9}| ‡fdd„|Dƒ¡S)Nrrc3s|]}| ˆ¡VqdS)N)ro)r,rŽ)r‡rrrtˆszformatstring..)ru)r³r‡r´r)r‡rr�…sr�i²c Cs^|dd…\}}}}}}t ||d¡ ¡t|d}|d|}|d|} | d|} | S)Nr…r#éé<)r)r*Ú toordinalÚ _EPOCH_ORD) ÚtuplerDr rEZhourZminuteÚsecondr`ZhoursZminutesZsecondsrrrr�s    c Cs¬ddl}| ¡}| d¡}| d¡}|jddtddd�|jd d td d d�|jd dtddd�|jddtddd�|jddddd�|jddddd�|jddddd�|jd d!d"d#d$d%�|jd&d'td(d)�|jd*d'td+d)�| |d d…¡}|j�r|j�s| d,¡t   d ¡|j|jf}|j d-k�rÚ|j�rDt |d.�}nt ƒ}|j}|dk�rbt  ¡}t||jd/�} t jjj} |jdk�r¢| |jtj ¡jf| Žƒn6|jdk�rÄ| |j|jf| Žƒn| d0¡t   d ¡nÎ|j�rît|d.�}ntƒ}t|j|jd1�} |jdk�r$|j| d2<|j| d3<|jdk�rH|j tj ¡jf| Ž} n2|jdk�rf|j |jf| Ž} n|j!|j|jf| Ž} t jj} |j�r |  "|j¡} t jjj} | | ƒdS)4Nrztext only argumentszhtml only argumentsz-wz--widthr$z width of date column (default 2))ÚtypeÚdefaultÚhelpz-lz--linesr#z)number of lines for each week (default 1)z-sz --spacingr…z"spacing between months (default 6)z-mz--monthsrczmonths per row (default 3)z-cz--cssz calendar.csszCSS to use for page)r¼r½z-Lz--localez.locale to be used from month and weekday namesz-ez --encodingzencoding to use for outputz-tz--typeÚtext)r¾Úhtmlzoutput type (text or html))r¼Úchoicesr½rDú?zyear number (1-9999))Únargsr»r½r zmonth number (1-12, text only)z/if --locale is specified --encoding is requiredr¿)r¥)r¢r¡zincorrect number of arguments)rr€rŽrR)#ÚargparseÚArgumentParserÚadd_argument_groupÚ add_argumentÚintÚ parse_argsr¥r¢ÚerrorržÚexitr»rrrŸÚdictr¡ÚstdoutÚbufferÚwriterDr£r)r*Ztodayr rrreÚlinesr´rdr“r~r ) r¬rÃÚparserZ textgroupZ htmlgroupÚoptionsr¥r‰r¢ZoptdictrÎÚresultrrrÚmain™s¤                     rÓÚ__main__)Hržr)r¥r¦Ú itertoolsrÚ__all__Ú ValueErrorrÉrrrfrGrFr(r?rrrrr=r°ZTUESDAYZ WEDNESDAYZTHURSDAYZFRIDAYZSATURDAYr±rrr r rJrKrLÚobjectrrrr¤rrrŽrNrrrbr rnrlr„ryrr r~r r“rr”rZ _colwidthZ_spacingr4r�ZEPOCHr*r·r¸rrÓr ÚargvrrrrÚst     u   h