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
a564cc31
Kaydet (Commit)
a564cc31
authored
Eki 03, 1999
tarafından
Greg Ward
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Hacked to support the notion of "negative alias" options, to handle
-q/--quiet reasonably elegantly.
üst
c74138d9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
3 deletions
+32
-3
fancy_getopt.py
Lib/distutils/fancy_getopt.py
+32
-3
No files found.
Lib/distutils/fancy_getopt.py
Dosyayı görüntüle @
a564cc31
...
...
@@ -21,7 +21,12 @@ from distutils.errors import *
# the same as a Python NAME -- except, in the spirit of most GNU
# utilities, we use '-' in place of '_'. (The spirit of LISP lives on!)
# The similarities to NAME are again not a coincidence...
longopt_re
=
re
.
compile
(
r'^[a-zA-Z]([a-zA-Z0-9-]*)$'
)
longopt_pat
=
r'[a-zA-Z](?:[a-zA-Z0-9-]*)'
longopt_re
=
re
.
compile
(
r'^
%
s$'
%
longopt_pat
)
# For recognizing "negative alias" options, eg. "quiet=!verbose"
neg_alias_re
=
re
.
compile
(
"^(
%
s)=!(
%
s)$"
%
(
longopt_pat
,
longopt_pat
))
# This is used to translate long options to legitimate Python identifiers
# (for use as attributes of some object).
...
...
@@ -46,6 +51,7 @@ def fancy_getopt (options, object, args):
short2long
=
{}
attr_name
=
{}
takes_arg
=
{}
neg_alias
=
{}
for
option
in
options
:
try
:
...
...
@@ -73,7 +79,26 @@ def fancy_getopt (options, object, args):
long
=
long
[
0
:
-
1
]
takes_arg
[
long
]
=
1
else
:
takes_arg
[
long
]
=
0
# Is option is a "negative alias" for some other option (eg.
# "quiet=!verbose")?
match
=
neg_alias_re
.
match
(
long
)
if
match
:
(
alias_from
,
alias_to
)
=
match
.
group
(
1
,
2
)
if
not
takes_arg
.
has_key
(
alias_to
)
or
takes_arg
[
alias_to
]:
raise
DistutilsGetoptError
,
\
(
"option '
%
s' is a negative alias for '
%
s', "
+
"which either hasn't been defined yet "
+
"or takes an argument"
)
%
(
alias_from
,
alias_to
)
long
=
alias_from
neg_alias
[
long
]
=
alias_to
long_opts
[
-
1
]
=
long
takes_arg
[
long
]
=
0
else
:
takes_arg
[
long
]
=
0
# Now enforce some bondage on the long option name, so we can later
# translate it to an attribute name in 'object'. Have to do this a
...
...
@@ -112,7 +137,11 @@ def fancy_getopt (options, object, args):
setattr
(
object
,
attr
,
val
)
else
:
if
val
==
''
:
setattr
(
object
,
attr
,
1
)
alias
=
neg_alias
.
get
(
opt
)
if
alias
:
setattr
(
object
,
attr_name
[
alias
],
0
)
else
:
setattr
(
object
,
attr
,
1
)
else
:
raise
RuntimeError
,
"getopt lies! (bad value '
%
s')"
%
value
...
...
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