Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9785261d
Kaydet (Commit)
9785261d
authored
Kas 01, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #18973: Command-line interface of the calendar module now uses argparse
instead of optparse.
üst
17bdf201
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
40 deletions
+52
-40
calendar.py
Lib/calendar.py
+45
-36
test_calendar.py
Lib/test/test_calendar.py
+4
-4
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/calendar.py
Dosyayı görüntüle @
9785261d
...
@@ -605,51 +605,63 @@ def timegm(tuple):
...
@@ -605,51 +605,63 @@ def timegm(tuple):
def
main
(
args
):
def
main
(
args
):
import
optparse
import
argparse
parser
=
optparse
.
OptionParser
(
usage
=
"usage:
%
prog [options] [year [month]]"
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_option
(
textgroup
=
parser
.
add_argument_group
(
'text only arguments'
)
htmlgroup
=
parser
.
add_argument_group
(
'html only arguments'
)
textgroup
.
add_argument
(
"-w"
,
"--width"
,
"-w"
,
"--width"
,
dest
=
"width"
,
type
=
"int"
,
default
=
2
,
type
=
int
,
default
=
2
,
help
=
"width of date column (default 2
, text only
)"
help
=
"width of date column (default 2)"
)
)
parser
.
add_option
(
textgroup
.
add_argument
(
"-l"
,
"--lines"
,
"-l"
,
"--lines"
,
dest
=
"lines"
,
type
=
"int"
,
default
=
1
,
type
=
int
,
default
=
1
,
help
=
"number of lines for each week (default 1
, text only
)"
help
=
"number of lines for each week (default 1)"
)
)
parser
.
add_option
(
textgroup
.
add_argument
(
"-s"
,
"--spacing"
,
"-s"
,
"--spacing"
,
dest
=
"spacing"
,
type
=
"int"
,
default
=
6
,
type
=
int
,
default
=
6
,
help
=
"spacing between months (default 6
, text only
)"
help
=
"spacing between months (default 6)"
)
)
parser
.
add_option
(
textgroup
.
add_argument
(
"-m"
,
"--months"
,
"-m"
,
"--months"
,
dest
=
"months"
,
type
=
"int"
,
default
=
3
,
type
=
int
,
default
=
3
,
help
=
"months per row (default 3
, text only
)"
help
=
"months per row (default 3)"
)
)
parser
.
add_option
(
htmlgroup
.
add_argument
(
"-c"
,
"--css"
,
"-c"
,
"--css"
,
de
st
=
"css"
,
de
fault
=
"calendar.css"
,
default
=
"calendar.css"
,
help
=
"CSS to use for page
(html only)
"
help
=
"CSS to use for page"
)
)
parser
.
add_
option
(
parser
.
add_
argument
(
"-L"
,
"--locale"
,
"-L"
,
"--locale"
,
de
st
=
"locale"
,
de
fault
=
None
,
default
=
None
,
help
=
"locale to be used from month and weekday names"
help
=
"locale to be used from month and weekday names"
)
)
parser
.
add_
option
(
parser
.
add_
argument
(
"-e"
,
"--encoding"
,
"-e"
,
"--encoding"
,
de
st
=
"encoding"
,
de
fault
=
None
,
default
=
None
,
help
=
"
Encoding to use for output.
"
help
=
"
encoding to use for output
"
)
)
parser
.
add_
option
(
parser
.
add_
argument
(
"-t"
,
"--type"
,
"-t"
,
"--type"
,
de
st
=
"type"
,
de
fault
=
"text"
,
default
=
"text"
,
choices
=
(
"text"
,
"html"
),
choices
=
(
"text"
,
"html"
),
help
=
"output type (text or html)"
help
=
"output type (text or html)"
)
)
parser
.
add_argument
(
"year"
,
nargs
=
'?'
,
type
=
int
,
help
=
"year number (1-9999)"
)
parser
.
add_argument
(
"month"
,
nargs
=
'?'
,
type
=
int
,
help
=
"month number (1-12, text only)"
)
(
options
,
args
)
=
parser
.
parse_args
(
args
)
options
=
parser
.
parse_args
(
args
[
1
:]
)
if
options
.
locale
and
not
options
.
encoding
:
if
options
.
locale
and
not
options
.
encoding
:
parser
.
error
(
"if --locale is specified --encoding is required"
)
parser
.
error
(
"if --locale is specified --encoding is required"
)
...
@@ -667,10 +679,10 @@ def main(args):
...
@@ -667,10 +679,10 @@ def main(args):
encoding
=
sys
.
getdefaultencoding
()
encoding
=
sys
.
getdefaultencoding
()
optdict
=
dict
(
encoding
=
encoding
,
css
=
options
.
css
)
optdict
=
dict
(
encoding
=
encoding
,
css
=
options
.
css
)
write
=
sys
.
stdout
.
buffer
.
write
write
=
sys
.
stdout
.
buffer
.
write
if
len
(
args
)
==
1
:
if
options
.
year
is
None
:
write
(
cal
.
formatyearpage
(
datetime
.
date
.
today
()
.
year
,
**
optdict
))
write
(
cal
.
formatyearpage
(
datetime
.
date
.
today
()
.
year
,
**
optdict
))
elif
len
(
args
)
==
2
:
elif
options
.
month
is
None
:
write
(
cal
.
formatyearpage
(
int
(
args
[
1
])
,
**
optdict
))
write
(
cal
.
formatyearpage
(
options
.
year
,
**
optdict
))
else
:
else
:
parser
.
error
(
"incorrect number of arguments"
)
parser
.
error
(
"incorrect number of arguments"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -680,18 +692,15 @@ def main(args):
...
@@ -680,18 +692,15 @@ def main(args):
else
:
else
:
cal
=
TextCalendar
()
cal
=
TextCalendar
()
optdict
=
dict
(
w
=
options
.
width
,
l
=
options
.
lines
)
optdict
=
dict
(
w
=
options
.
width
,
l
=
options
.
lines
)
if
len
(
args
)
!=
3
:
if
options
.
month
is
None
:
optdict
[
"c"
]
=
options
.
spacing
optdict
[
"c"
]
=
options
.
spacing
optdict
[
"m"
]
=
options
.
months
optdict
[
"m"
]
=
options
.
months
if
len
(
args
)
==
1
:
if
options
.
year
is
None
:
result
=
cal
.
formatyear
(
datetime
.
date
.
today
()
.
year
,
**
optdict
)
result
=
cal
.
formatyear
(
datetime
.
date
.
today
()
.
year
,
**
optdict
)
elif
len
(
args
)
==
2
:
elif
options
.
month
is
None
:
result
=
cal
.
formatyear
(
int
(
args
[
1
]),
**
optdict
)
result
=
cal
.
formatyear
(
options
.
year
,
**
optdict
)
elif
len
(
args
)
==
3
:
result
=
cal
.
formatmonth
(
int
(
args
[
1
]),
int
(
args
[
2
]),
**
optdict
)
else
:
else
:
parser
.
error
(
"incorrect number of arguments"
)
result
=
cal
.
formatmonth
(
options
.
year
,
options
.
month
,
**
optdict
)
sys
.
exit
(
1
)
write
=
sys
.
stdout
.
write
write
=
sys
.
stdout
.
write
if
options
.
encoding
:
if
options
.
encoding
:
result
=
result
.
encode
(
options
.
encoding
)
result
=
result
.
encode
(
options
.
encoding
)
...
...
Lib/test/test_calendar.py
Dosyayı görüntüle @
9785261d
...
@@ -702,19 +702,19 @@ class CommandLineTestCase(unittest.TestCase):
...
@@ -702,19 +702,19 @@ class CommandLineTestCase(unittest.TestCase):
def
assertFailure
(
self
,
*
args
):
def
assertFailure
(
self
,
*
args
):
rc
,
stdout
,
stderr
=
assert_python_failure
(
'-m'
,
'calendar'
,
*
args
)
rc
,
stdout
,
stderr
=
assert_python_failure
(
'-m'
,
'calendar'
,
*
args
)
self
.
assertIn
(
b
'
U
sage:'
,
stderr
)
self
.
assertIn
(
b
'
u
sage:'
,
stderr
)
self
.
assertEqual
(
rc
,
2
)
self
.
assertEqual
(
rc
,
2
)
def
test_help
(
self
):
def
test_help
(
self
):
stdout
=
self
.
run_ok
(
'-h'
)
stdout
=
self
.
run_ok
(
'-h'
)
self
.
assertIn
(
b
'
U
sage:'
,
stdout
)
self
.
assertIn
(
b
'
u
sage:'
,
stdout
)
self
.
assertIn
(
b
'calendar.py'
,
stdout
)
self
.
assertIn
(
b
'calendar.py'
,
stdout
)
self
.
assertIn
(
b
'--help'
,
stdout
)
self
.
assertIn
(
b
'--help'
,
stdout
)
def
test_illegal_arguments
(
self
):
def
test_illegal_arguments
(
self
):
self
.
assertFailure
(
'-z'
)
self
.
assertFailure
(
'-z'
)
#
self.assertFailure('spam')
self
.
assertFailure
(
'spam'
)
#
self.assertFailure('2004', 'spam')
self
.
assertFailure
(
'2004'
,
'spam'
)
self
.
assertFailure
(
'-t'
,
'html'
,
'2004'
,
'1'
)
self
.
assertFailure
(
'-t'
,
'html'
,
'2004'
,
'1'
)
def
test_output_current_year
(
self
):
def
test_output_current_year
(
self
):
...
...
Misc/NEWS
Dosyayı görüntüle @
9785261d
...
@@ -66,6 +66,9 @@ Core and Builtins
...
@@ -66,6 +66,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #18973: Command-line interface of the calendar module now uses argparse
instead of optparse.
- Issue #25510: fileinput.FileInput.readline() now returns b'' instead of ''
- Issue #25510: fileinput.FileInput.readline() now returns b'' instead of ''
at the end if the FileInput was opened with binary mode.
at the end if the FileInput was opened with binary mode.
Patch by Ryosuke Ito.
Patch by Ryosuke Ito.
...
...
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