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
bddbaf70
Kaydet (Commit)
bddbaf70
authored
Ock 16, 2001
tarafından
Eric S. Raymond
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make pop_source and push_source available, as documented.
üst
1360359b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
15 deletions
+28
-15
shlex.py
Lib/shlex.py
+28
-15
No files found.
Lib/shlex.py
Dosyayı görüntüle @
bddbaf70
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
# Module and documentation by Eric S. Raymond, 21 Dec 1998
# Module and documentation by Eric S. Raymond, 21 Dec 1998
# Input stacking and error message cleanup added by ESR, March 2000
# Input stacking and error message cleanup added by ESR, March 2000
# push_source() and pop_source() made explicit by ESR, January 2001.
import
os.path
import
os.path
import
sys
import
sys
class
shlex
:
class
shlex
:
"A lexical analyzer class for simple shell-like syntaxes."
"A lexical analyzer class for simple shell-like syntaxes."
def
__init__
(
self
,
instream
=
None
,
infile
=
None
):
def
__init__
(
self
,
instream
=
None
,
infile
=
None
):
...
@@ -38,6 +38,28 @@ class shlex:
...
@@ -38,6 +38,28 @@ class shlex:
print
"shlex: pushing token "
+
`tok`
print
"shlex: pushing token "
+
`tok`
self
.
pushback
=
[
tok
]
+
self
.
pushback
self
.
pushback
=
[
tok
]
+
self
.
pushback
def
push_source
(
self
,
newstream
,
newfile
=
None
):
"Push an input source onto the lexer's input source stack."
self
.
filestack
.
insert
(
0
,
(
self
.
infile
,
self
.
instream
,
self
.
lineno
))
self
.
infile
=
newfile
self
.
instream
=
newstream
self
.
lineno
=
1
if
self
.
debug
:
if
newfile
:
print
'shlex: pushing to file
%
s'
%
(
self
.
infile
,)
else
:
print
'shlex: pushing to stream
%
s'
%
(
self
.
instream
,)
def
pop_source
(
self
):
"Pop the input source stack."
self
.
instream
.
close
()
(
self
.
infile
,
self
.
instream
,
self
.
lineno
)
=
self
.
filestack
[
0
]
self
.
filestack
=
self
.
filestack
[
1
:]
if
self
.
debug
:
print
'shlex: popping to
%
s, line
%
d'
\
%
(
self
.
instream
,
self
.
lineno
)
self
.
state
=
' '
def
get_token
(
self
):
def
get_token
(
self
):
"Get a token from the input stream (or from stack if it's nonempty)"
"Get a token from the input stream (or from stack if it's nonempty)"
if
self
.
pushback
:
if
self
.
pushback
:
...
@@ -50,26 +72,17 @@ class shlex:
...
@@ -50,26 +72,17 @@ class shlex:
raw
=
self
.
read_token
()
raw
=
self
.
read_token
()
# Handle inclusions
# Handle inclusions
while
raw
==
self
.
source
:
while
raw
==
self
.
source
:
(
newfile
,
newstream
)
=
self
.
sourcehook
(
self
.
read_token
())
spec
=
self
.
sourcehook
(
self
.
read_token
())
self
.
filestack
.
insert
(
0
,
(
self
.
infile
,
self
.
instream
,
self
.
lineno
))
if
spec
:
self
.
infile
=
newfile
(
newfile
,
newstream
)
=
spec
self
.
instream
=
newstream
self
.
push_source
(
newstream
,
newfile
)
self
.
lineno
=
1
if
self
.
debug
:
print
'shlex: pushing to file
%
s'
%
(
self
.
infile
,)
raw
=
self
.
get_token
()
raw
=
self
.
get_token
()
# Maybe we got EOF instead?
# Maybe we got EOF instead?
while
raw
==
""
:
while
raw
==
""
:
if
len
(
self
.
filestack
)
==
0
:
if
len
(
self
.
filestack
)
==
0
:
return
""
return
""
else
:
else
:
self
.
instream
.
close
()
self
.
pop_source
()
(
self
.
infile
,
self
.
instream
,
self
.
lineno
)
=
self
.
filestack
[
0
]
self
.
filestack
=
self
.
filestack
[
1
:]
if
self
.
debug
:
print
'shlex: popping to
%
s, line
%
d'
\
%
(
self
.
instream
,
self
.
lineno
)
self
.
state
=
' '
raw
=
self
.
get_token
()
raw
=
self
.
get_token
()
# Neither inclusion nor EOF
# Neither inclusion nor EOF
if
self
.
debug
>=
1
:
if
self
.
debug
>=
1
:
...
...
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