Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
72ef8daa
Commit
72ef8daa
authored
May 17, 2007
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calendar.py gets no benefit from xrange() instead of range()
parent
d75f043c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
Lib/calendar.py
Lib/calendar.py
+16
-16
No files found.
Lib/calendar.py
View file @
72ef8daa
...
...
@@ -45,7 +45,7 @@ mdays = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
class
_localized_month
:
_months
=
[
datetime
.
date
(
2001
,
i
+
1
,
1
).
strftime
for
i
in
x
range
(
12
)]
_months
=
[
datetime
.
date
(
2001
,
i
+
1
,
1
).
strftime
for
i
in
range
(
12
)]
_months
.
insert
(
0
,
lambda
x
:
""
)
def
__init__
(
self
,
format
):
...
...
@@ -65,7 +65,7 @@ class _localized_month:
class
_localized_day
:
# January 1, 2001, was a Monday.
_days
=
[
datetime
.
date
(
2001
,
1
,
i
+
1
).
strftime
for
i
in
x
range
(
7
)]
_days
=
[
datetime
.
date
(
2001
,
1
,
i
+
1
).
strftime
for
i
in
range
(
7
)]
def
__init__
(
self
,
format
):
self
.
format
=
format
...
...
@@ -144,7 +144,7 @@ class Calendar(object):
Return a iterator for one week of weekday numbers starting with the
configured first one.
"""
for
i
in
x
range
(
self
.
firstweekday
,
self
.
firstweekday
+
7
):
for
i
in
range
(
self
.
firstweekday
,
self
.
firstweekday
+
7
):
yield
i
%
7
def
itermonthdates
(
self
,
year
,
month
):
...
...
@@ -192,7 +192,7 @@ class Calendar(object):
Each row represents a week; week entries are datetime.date values.
"""
dates
=
list
(
self
.
itermonthdates
(
year
,
month
))
return
[
dates
[
i
:
i
+
7
]
for
i
in
x
range
(
0
,
len
(
dates
),
7
)
]
return
[
dates
[
i
:
i
+
7
]
for
i
in
range
(
0
,
len
(
dates
),
7
)
]
def
monthdays2calendar
(
self
,
year
,
month
):
"""
...
...
@@ -202,7 +202,7 @@ class Calendar(object):
are zero.
"""
days
=
list
(
self
.
itermonthdays2
(
year
,
month
))
return
[
days
[
i
:
i
+
7
]
for
i
in
x
range
(
0
,
len
(
days
),
7
)
]
return
[
days
[
i
:
i
+
7
]
for
i
in
range
(
0
,
len
(
days
),
7
)
]
def
monthdayscalendar
(
self
,
year
,
month
):
"""
...
...
@@ -210,7 +210,7 @@ class Calendar(object):
Each row represents a week; days outside this month are zero.
"""
days
=
list
(
self
.
itermonthdays
(
year
,
month
))
return
[
days
[
i
:
i
+
7
]
for
i
in
x
range
(
0
,
len
(
days
),
7
)
]
return
[
days
[
i
:
i
+
7
]
for
i
in
range
(
0
,
len
(
days
),
7
)
]
def
yeardatescalendar
(
self
,
year
,
width
=
3
):
"""
...
...
@@ -221,9 +221,9 @@ class Calendar(object):
"""
months
=
[
self
.
monthdatescalendar
(
year
,
i
)
for
i
in
x
range
(
January
,
January
+
12
)
for
i
in
range
(
January
,
January
+
12
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
x
range
(
0
,
len
(
months
),
width
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
range
(
0
,
len
(
months
),
width
)
]
def
yeardays2calendar
(
self
,
year
,
width
=
3
):
"""
...
...
@@ -234,9 +234,9 @@ class Calendar(object):
"""
months
=
[
self
.
monthdays2calendar
(
year
,
i
)
for
i
in
x
range
(
January
,
January
+
12
)
for
i
in
range
(
January
,
January
+
12
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
x
range
(
0
,
len
(
months
),
width
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
range
(
0
,
len
(
months
),
width
)
]
def
yeardayscalendar
(
self
,
year
,
width
=
3
):
"""
...
...
@@ -246,9 +246,9 @@ class Calendar(object):
"""
months
=
[
self
.
monthdayscalendar
(
year
,
i
)
for
i
in
x
range
(
January
,
January
+
12
)
for
i
in
range
(
January
,
January
+
12
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
x
range
(
0
,
len
(
months
),
width
)
]
return
[
months
[
i
:
i
+
width
]
for
i
in
range
(
0
,
len
(
months
),
width
)
]
class
TextCalendar
(
Calendar
):
...
...
@@ -341,7 +341,7 @@ class TextCalendar(Calendar):
header
=
self
.
formatweekheader
(
w
)
for
(
i
,
row
)
in
enumerate
(
self
.
yeardays2calendar
(
theyear
,
m
)):
# months in this row
months
=
x
range
(
m
*
i
+
1
,
min
(
m
*
(
i
+
1
)
+
1
,
13
))
months
=
range
(
m
*
i
+
1
,
min
(
m
*
(
i
+
1
)
+
1
,
13
))
a
(
'
\
n
'
*
l
)
names
=
(
self
.
formatmonthname
(
theyear
,
k
,
colwidth
,
False
)
for
k
in
months
)
...
...
@@ -352,7 +352,7 @@ class TextCalendar(Calendar):
a
(
'
\
n
'
*
l
)
# max number of weeks for this row
height
=
max
(
len
(
cal
)
for
cal
in
row
)
for
j
in
x
range
(
height
):
for
j
in
range
(
height
):
weeks
=
[]
for
cal
in
row
:
if
j
>=
len
(
cal
):
...
...
@@ -444,9 +444,9 @@ class HTMLCalendar(Calendar):
a
(
'<table border="0" cellpadding="0" cellspacing="0" class="year">'
)
a
(
'
\
n
'
)
a
(
'<tr><th colspan="%d" class="year">%s</th></tr>'
%
(
width
,
theyear
))
for
i
in
x
range
(
January
,
January
+
12
,
width
):
for
i
in
range
(
January
,
January
+
12
,
width
):
# months in this row
months
=
x
range
(
i
,
min
(
i
+
width
,
13
))
months
=
range
(
i
,
min
(
i
+
width
,
13
))
a
(
'<tr>'
)
for
m
in
months
:
a
(
'<td>'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment