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
787451b6
Kaydet (Commit)
787451b6
authored
Mar 26, 1999
tarafından
Greg Ward
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added 'linestart' array and 'unreadline()' method (makes parsing a lot easier).
üst
447b4a06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
text_file.py
Lib/distutils/text_file.py
+30
-1
No files found.
Lib/distutils/text_file.py
Dosyayı görüntüle @
787451b6
...
@@ -52,6 +52,11 @@ class TextFile:
...
@@ -52,6 +52,11 @@ class TextFile:
self
.
filename
=
filename
self
.
filename
=
filename
self
.
file
=
file
self
.
file
=
file
self
.
current_line
=
0
# assuming that file is at BOF!
self
.
current_line
=
0
# assuming that file is at BOF!
# 'linestart' stores the file offset of the start of each logical
# line; it is used to back up the file pointer when the caller
# wants to "unread" a line
self
.
linestart
=
[]
def
open
(
self
,
filename
):
def
open
(
self
,
filename
):
...
@@ -81,6 +86,11 @@ class TextFile:
...
@@ -81,6 +86,11 @@ class TextFile:
buildup_line
=
''
buildup_line
=
''
while
1
:
while
1
:
# record current file position; this will be appended to
# the linestart array *unless* we're accumulating a
# continued logical line
current_pos
=
self
.
file
.
tell
()
# read the line, optionally strip comments
# read the line, optionally strip comments
line
=
self
.
file
.
readline
()
line
=
self
.
file
.
readline
()
if
self
.
strip_comments
and
line
:
if
self
.
strip_comments
and
line
:
...
@@ -101,6 +111,11 @@ class TextFile:
...
@@ -101,6 +111,11 @@ class TextFile:
self
.
current_line
[
1
]
=
self
.
current_line
[
1
]
+
1
self
.
current_line
[
1
]
=
self
.
current_line
[
1
]
+
1
else
:
else
:
self
.
current_line
=
[
self
.
current_line
,
self
.
current_line
+
1
]
self
.
current_line
=
[
self
.
current_line
,
self
.
current_line
+
1
]
# Forget current position: don't want to save it in the
# middle of a logical line
current_pos
=
None
# just an ordinary line, read it as usual
# just an ordinary line, read it as usual
else
:
else
:
if
not
line
:
if
not
line
:
...
@@ -111,7 +126,7 @@ class TextFile:
...
@@ -111,7 +126,7 @@ class TextFile:
self
.
current_line
=
self
.
current_line
[
1
]
+
1
self
.
current_line
=
self
.
current_line
[
1
]
+
1
else
:
else
:
self
.
current_line
=
self
.
current_line
+
1
self
.
current_line
=
self
.
current_line
+
1
# strip whitespace however the client wants (leading and
# strip whitespace however the client wants (leading and
# trailing, or one or the other, or neither)
# trailing, or one or the other, or neither)
...
@@ -128,6 +143,12 @@ class TextFile:
...
@@ -128,6 +143,12 @@ class TextFile:
if
line
==
''
or
line
==
'
\n
'
and
self
.
skip_blanks
:
if
line
==
''
or
line
==
'
\n
'
and
self
.
skip_blanks
:
continue
continue
# if we're still here and have kept the current position,
# then this physical line starts a logical line; record its
# starting offset
if
current_pos
is
not
None
:
self
.
linestart
.
append
(
current_pos
)
if
self
.
join_lines
:
if
self
.
join_lines
:
if
line
[
-
1
]
==
'
\\
'
:
if
line
[
-
1
]
==
'
\\
'
:
buildup_line
=
line
[:
-
1
]
buildup_line
=
line
[:
-
1
]
...
@@ -147,6 +168,14 @@ class TextFile:
...
@@ -147,6 +168,14 @@ class TextFile:
# end readline
# end readline
def
unreadline
(
self
):
if
not
self
.
linestart
:
raise
IOError
,
"at beginning of file -- can't unreadline"
pos
=
self
.
linestart
[
-
1
]
del
self
.
linestart
[
-
1
]
self
.
file
.
seek
(
pos
)
def
readlines
(
self
):
def
readlines
(
self
):
lines
=
[]
lines
=
[]
while
1
:
while
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