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
8bfa8935
Kaydet (Commit)
8bfa8935
authored
Tem 15, 2005
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
textwrap now processes text chucks at O(n) speed instead of O(n**2).
Patch #1209527 (Contributed by Connelly).
üst
d5d469d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
textwrap.py
Lib/textwrap.py
+13
-9
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/textwrap.py
Dosyayı görüntüle @
8bfa8935
...
...
@@ -161,7 +161,7 @@ class TextWrapper:
else
:
i
+=
1
def
_handle_long_word
(
self
,
chunks
,
cur_line
,
cur_len
,
width
):
def
_handle_long_word
(
self
,
reversed_
chunks
,
cur_line
,
cur_len
,
width
):
"""_handle_long_word(chunks : [string],
cur_line : [string],
cur_len : int, width : int)
...
...
@@ -174,14 +174,14 @@ class TextWrapper:
# If we're allowed to break long words, then do so: put as much
# of the next chunk onto the current line as will fit.
if
self
.
break_long_words
:
cur_line
.
append
(
chunks
[
0
][
0
:
space_left
])
chunks
[
0
]
=
chunks
[
0
][
space_left
:]
cur_line
.
append
(
reversed_chunks
[
-
1
][
:
space_left
])
reversed_chunks
[
-
1
]
=
reversed_chunks
[
-
1
][
space_left
:]
# Otherwise, we have to preserve the long word intact. Only add
# it to the current line if there's nothing already there --
# that minimizes how much we violate the width constraint.
elif
not
cur_line
:
cur_line
.
append
(
chunks
.
pop
(
0
))
cur_line
.
append
(
reversed_chunks
.
pop
(
))
# If we're not allowed to break long words, and there's already
# text on the current line, do nothing. Next time through the
...
...
@@ -206,6 +206,10 @@ class TextWrapper:
if
self
.
width
<=
0
:
raise
ValueError
(
"invalid width
%
r (must be > 0)"
%
self
.
width
)
# Arrange in reverse order so items can be efficiently popped
# from a stack of chucks.
chunks
.
reverse
()
while
chunks
:
# Start the list of chunks that will make up the current line.
...
...
@@ -224,15 +228,15 @@ class TextWrapper:
# First chunk on line is whitespace -- drop it, unless this
# is the very beginning of the text (ie. no lines started yet).
if
chunks
[
0
]
.
strip
()
==
''
and
lines
:
del
chunks
[
0
]
if
chunks
[
-
1
]
.
strip
()
==
''
and
lines
:
del
chunks
[
-
1
]
while
chunks
:
l
=
len
(
chunks
[
0
])
l
=
len
(
chunks
[
-
1
])
# Can at least squeeze this chunk onto the current line.
if
cur_len
+
l
<=
width
:
cur_line
.
append
(
chunks
.
pop
(
0
))
cur_line
.
append
(
chunks
.
pop
())
cur_len
+=
l
# Nope, this line is full.
...
...
@@ -241,7 +245,7 @@ class TextWrapper:
# The current line is full, and the next chunk is too big to
# fit on *any* line (not just this one).
if
chunks
and
len
(
chunks
[
0
])
>
width
:
if
chunks
and
len
(
chunks
[
-
1
])
>
width
:
self
.
_handle_long_word
(
chunks
,
cur_line
,
cur_len
,
width
)
# If the last chunk on this line is all whitespace, drop it.
...
...
Misc/NEWS
Dosyayı görüntüle @
8bfa8935
...
...
@@ -168,6 +168,9 @@ Extension Modules
Library
-------
-
textwrap
now
processes
text
chucks
at
O
(
n
)
speed
instead
of
O
(
n
**
2
).
Patch
#
1209527
(
Contributed
by
Connelly
).
-
urllib2
has
now
an
attribute
'httpresponses'
mapping
from
HTTP
status
code
to
W3C
name
(
404
->
'Not Found'
).
RFE
#
1216944.
...
...
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