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
488609e4
Kaydet (Commit)
488609e4
authored
Ock 06, 2003
tarafından
Neal Norwitz
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
SF #642236, optparse LaTeX docs by Johannes Gijsbers
üst
11f89b75
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
0 deletions
+128
-0
Makefile.deps
Doc/Makefile.deps
+4
-0
caseless.py
Doc/lib/caseless.py
+62
-0
lib.tex
Doc/lib/lib.tex
+1
-0
liboptparse.tex
Doc/lib/liboptparse.tex
+0
-0
required_1.py
Doc/lib/required_1.py
+20
-0
required_2.py
Doc/lib/required_2.py
+41
-0
No files found.
Doc/Makefile.deps
Dosyayı görüntüle @
488609e4
...
...
@@ -142,6 +142,10 @@ LIBFILES= $(MANSTYLES) $(INDEXSTYLES) $(COMMONTEX) \
lib/tzinfo-examples.py
\
lib/libtime.tex
\
lib/libgetopt.tex
\
lib/liboptparse.tex
\
lib/caseless.py
\
lib/required_1.py
\
lib/required_2.py
\
lib/libtempfile.tex
\
lib/liberrno.tex
\
lib/libsomeos.tex
\
...
...
Doc/lib/caseless.py
0 → 100755
Dosyayı görüntüle @
488609e4
from
optparse
import
Option
,
OptionParser
,
_match_abbrev
# This case-insensitive option parser relies on having a
# case-insensitive dictionary type available. Here's one
# for Python 2.2. Note that a *real* case-insensitive
# dictionary type would also have to implement __new__(),
# update(), and setdefault() -- but that's not the point
# of this exercise.
class
caseless_dict
(
dict
):
def
__setitem__
(
self
,
key
,
value
):
dict
.
__setitem__
(
self
,
key
.
lower
(),
value
)
def
__getitem__
(
self
,
key
):
return
dict
.
__getitem__
(
self
,
key
.
lower
())
def
get
(
self
,
key
,
default
=
None
):
return
dict
.
get
(
self
,
key
.
lower
())
def
has_key
(
self
,
key
):
return
dict
.
has_key
(
self
,
key
.
lower
())
class
CaselessOptionParser
(
OptionParser
):
def
_create_option_list
(
self
):
self
.
option_list
=
[]
self
.
_short_opt
=
caseless_dict
()
self
.
_long_opt
=
caseless_dict
()
self
.
_long_opts
=
[]
self
.
defaults
=
{}
def
_match_long_opt
(
self
,
opt
):
return
_match_abbrev
(
opt
.
lower
(),
self
.
_long_opt
.
keys
())
if
__name__
==
"__main__"
:
from
optik.errors
import
OptionConflictError
# test 1: no options to start with
parser
=
CaselessOptionParser
()
try
:
parser
.
add_option
(
"-H"
,
dest
=
"blah"
)
except
OptionConflictError
:
print
"ok: got OptionConflictError for -H"
else
:
print
"not ok: no conflict between -h and -H"
parser
.
add_option
(
"-f"
,
"--file"
,
dest
=
"file"
)
#print `parser.get_option("-f")`
#print `parser.get_option("-F")`
#print `parser.get_option("--file")`
#print `parser.get_option("--fIlE")`
(
options
,
args
)
=
parser
.
parse_args
([
"--FiLe"
,
"foo"
])
assert
options
.
file
==
"foo"
,
options
.
file
print
"ok: case insensitive long options work"
(
options
,
args
)
=
parser
.
parse_args
([
"-F"
,
"bar"
])
assert
options
.
file
==
"bar"
,
options
.
file
print
"ok: case insensitive short options work"
Doc/lib/lib.tex
Dosyayı görüntüle @
488609e4
...
...
@@ -151,6 +151,7 @@ and how to embed it in other applications.
\input
{
libascii
}
% curses.ascii
\input
{
libcursespanel
}
\input
{
libgetopt
}
\input
{
liboptparse
}
\input
{
libtempfile
}
\input
{
liberrno
}
\input
{
libglob
}
...
...
Doc/lib/liboptparse.tex
0 → 100644
Dosyayı görüntüle @
488609e4
This diff is collapsed.
Click to expand it.
Doc/lib/required_1.py
0 → 100755
Dosyayı görüntüle @
488609e4
import
optparse
class
OptionParser
(
optparse
.
OptionParser
):
def
check_required
(
self
,
opt
):
option
=
self
.
get_option
(
opt
)
# Assumes the option's 'default' is set to None!
if
getattr
(
self
.
values
,
option
.
dest
)
is
None
:
self
.
error
(
"
%
s option not supplied"
%
option
)
parser
=
OptionParser
()
parser
.
add_option
(
"-v"
,
action
=
"count"
,
dest
=
"verbose"
)
parser
.
add_option
(
"-f"
,
"--file"
,
default
=
None
)
(
options
,
args
)
=
parser
.
parse_args
()
print
"verbose:"
,
options
.
verbose
print
"file:"
,
options
.
file
parser
.
check_required
(
"-f"
)
Doc/lib/required_2.py
0 → 100755
Dosyayı görüntüle @
488609e4
import
optparse
class
Option
(
optparse
.
Option
):
ATTRS
=
optparse
.
Option
.
ATTRS
+
[
'required'
]
def
_check_required
(
self
):
if
self
.
required
and
not
self
.
takes_value
():
raise
OptionError
(
"required flag set for option that doesn't take a value"
,
self
)
# Make sure _check_required() is called from the constructor!
CHECK_METHODS
=
optparse
.
Option
.
CHECK_METHODS
+
[
_check_required
]
def
process
(
self
,
opt
,
value
,
values
,
parser
):
optparse
.
Option
.
process
(
self
,
opt
,
value
,
values
,
parser
)
parser
.
option_seen
[
self
]
=
1
class
OptionParser
(
optparse
.
OptionParser
):
def
_init_parsing_state
(
self
):
optparse
.
OptionParser
.
_init_parsing_state
(
self
)
self
.
option_seen
=
{}
def
check_values
(
self
,
values
,
args
):
for
option
in
self
.
option_list
:
if
(
isinstance
(
option
,
Option
)
and
option
.
required
and
not
self
.
option_seen
.
has_key
(
option
)):
self
.
error
(
"
%
s not supplied"
%
option
)
return
(
values
,
args
)
parser
=
OptionParser
(
option_list
=
[
Option
(
"-v"
,
action
=
"count"
,
dest
=
"verbose"
),
Option
(
"-f"
,
"--file"
,
required
=
1
)])
(
options
,
args
)
=
parser
.
parse_args
()
print
"verbose:"
,
options
.
verbose
print
"file:"
,
options
.
file
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