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
80884075
Kaydet (Commit)
80884075
authored
Haz 29, 1998
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Improved by Eric Raymond.
üst
716b7847
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
17 deletions
+84
-17
cmd.py
Lib/cmd.py
+84
-17
No files found.
Lib/cmd.py
Dosyayı görüntüle @
80884075
# A generic class to build line-oriented command interpreters
# A generic class to build line-oriented command interpreters
#
# Interpreters constructed with this class obey the following conventions:
#
# 1. End of file on input is processed as the command 'EOF'.
# 2. A command is parsed out of each line by collecting the prefix composed
# of characters in the identchars member.
# 3. A command `foo' is dispatched to a method 'do_foo()'; the do_ method
# is passed a single argument consisting of the remainder of the line.
# 4. Typing an empty line repeats the last command. (Actually, it calls the
# method `emptyline', which may be overridden in a subclass.)
# 5. There is a predefined `help' method. Given an argument `topic', it
# calls the command `help_topic'. With no arguments, it lists all topics
# with defined help_ functions, broken into up to three topics; documented
# commands, miscellaneous help topics, and undocumented commands.
# 6. The command '?' is a synonym for `help'. The command '!' is a synonym
# for `shell', if a do_shell method exists.
#
# The `default' method may be overridden to intercept commands for which there
# is no do_ method.
#
# The data member `self.ruler' sets the character used to draw separator lines
# in the help messages. If empty, no ruler line is drawn. It defaults to "=".
#
# If the value of `self.intro' is nonempty when the cmdloop method is called,
# it is printed out on interpreter startup. This value may be overridden
# via an optional argument to the cmdloop() method.
#
# The data members `self.doc_header', `self.misc_header', and
# `self.undoc_header' set the headers used for the help function's
# listings of documented functions, miscellaneous topics, and undocumented
# functions respectively.
#
# These interpreters use raw_input; thus, if the readline module is loaded,
# they automatically support Emacs-like command history and editing features.
#
import
string
import
string
import
sys
import
sys
...
@@ -8,27 +43,58 @@ PROMPT = '(Cmd) '
...
@@ -8,27 +43,58 @@ PROMPT = '(Cmd) '
IDENTCHARS
=
string
.
letters
+
string
.
digits
+
'_'
IDENTCHARS
=
string
.
letters
+
string
.
digits
+
'_'
class
Cmd
:
class
Cmd
:
prompt
=
PROMPT
identchars
=
IDENTCHARS
ruler
=
'='
lastcmd
=
''
intro
=
None
doc_header
=
"Documented commands (type help <topic>):"
misc_header
=
"Miscellaneous help topics:"
undoc_header
=
"Undocumented commands:"
def
__init__
(
self
):
def
cmdloop
(
self
,
intro
=
None
):
self
.
pr
ompt
=
PROMPT
self
.
pr
eloop
()
self
.
identchars
=
IDENTCHARS
if
intro
!=
None
:
self
.
lastcmd
=
''
self
.
intro
=
intro
if
self
.
intro
:
def
cmdloop
(
self
):
print
self
.
intro
stop
=
None
stop
=
None
while
not
stop
:
while
not
stop
:
try
:
try
:
line
=
raw_input
(
self
.
prompt
)
line
=
raw_input
(
self
.
prompt
)
except
EOFError
:
except
EOFError
:
line
=
'EOF'
line
=
'EOF'
self
.
precmd
()
stop
=
self
.
onecmd
(
line
)
stop
=
self
.
onecmd
(
line
)
self
.
postcmd
()
self
.
postloop
()
def
precmd
(
self
):
pass
def
postcmd
(
self
):
pass
def
preloop
(
self
):
pass
def
postloop
(
self
):
pass
def
onecmd
(
self
,
line
):
def
onecmd
(
self
,
line
):
line
=
string
.
strip
(
line
)
line
=
string
.
strip
(
line
)
if
not
line
:
if
line
==
'?'
:
line
=
self
.
lastcmd
line
=
'help'
else
:
elif
line
==
'!'
:
self
.
lastcmd
=
line
if
hasattr
(
self
,
'do_shell'
):
line
=
'shell'
else
:
self
.
default
(
line
)
return
elif
not
line
:
self
.
emptyline
()
return
self
.
lastcmd
=
line
i
,
n
=
0
,
len
(
line
)
i
,
n
=
0
,
len
(
line
)
while
i
<
n
and
line
[
i
]
in
self
.
identchars
:
i
=
i
+
1
while
i
<
n
and
line
[
i
]
in
self
.
identchars
:
i
=
i
+
1
cmd
,
arg
=
line
[:
i
],
string
.
strip
(
line
[
i
:])
cmd
,
arg
=
line
[:
i
],
string
.
strip
(
line
[
i
:])
...
@@ -41,6 +107,9 @@ class Cmd:
...
@@ -41,6 +107,9 @@ class Cmd:
return
self
.
default
(
line
)
return
self
.
default
(
line
)
return
func
(
arg
)
return
func
(
arg
)
def
emptyline
(
self
):
return
self
.
onecmd
(
self
.
lastcmd
)
def
default
(
self
,
line
):
def
default
(
self
,
line
):
print
'*** Unknown syntax:'
,
line
print
'*** Unknown syntax:'
,
line
...
@@ -70,17 +139,15 @@ class Cmd:
...
@@ -70,17 +139,15 @@ class Cmd:
else
:
else
:
cmds_undoc
.
append
(
cmd
)
cmds_undoc
.
append
(
cmd
)
print
print
self
.
print_topics
(
"Documented commands (type help "
\
self
.
print_topics
(
self
.
doc_header
,
cmds_doc
,
15
,
80
)
"<topic>):"
,
cmds_doc
,
15
,
80
)
self
.
print_topics
(
self
.
misc_header
,
help
.
keys
(),
15
,
80
)
self
.
print_topics
(
"Miscellaneous help topics:"
,
self
.
print_topics
(
self
.
undoc_header
,
cmds_undoc
,
15
,
80
)
help
.
keys
(),
15
,
80
)
self
.
print_topics
(
"Undocumented commands:"
,
cmds_undoc
,
15
,
80
)
def
print_topics
(
self
,
header
,
cmds
,
cmdlen
,
maxcol
):
def
print_topics
(
self
,
header
,
cmds
,
cmdlen
,
maxcol
):
if
cmds
:
if
cmds
:
print
header
;
print
header
;
print
"="
*
len
(
header
)
if
self
.
ruler
:
print
self
.
ruler
*
len
(
header
)
(
cmds_per_line
,
junk
)
=
divmod
(
maxcol
,
cmdlen
)
(
cmds_per_line
,
junk
)
=
divmod
(
maxcol
,
cmdlen
)
col
=
cmds_per_line
col
=
cmds_per_line
for
cmd
in
cmds
:
for
cmd
in
cmds
:
...
...
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