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
9e6b4700
Kaydet (Commit)
9e6b4700
authored
Mar 13, 2007
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1581073: add a flag to textwrap that prevents the dropping of
whitespace while wrapping.
üst
92a6baed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
4 deletions
+26
-4
libtextwrap.tex
Doc/lib/libtextwrap.tex
+7
-0
test_textwrap.py
Lib/test/test_textwrap.py
+8
-0
textwrap.py
Lib/textwrap.py
+8
-4
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/lib/libtextwrap.tex
Dosyayı görüntüle @
9e6b4700
...
...
@@ -115,6 +115,13 @@ replaced by a single space, which is \emph{not} the same as tab
expansion.
}
\end{memberdesc}
\begin{memberdesc}
{
drop
_
whitespace
}
(default:
\code
{
True
}
) If true, whitespace that, after wrapping, happens
to end up at the beginning or end of a line is dropped (leading whitespace
in the first line is always preserved, though).
\versionadded
[Whitespace was always dropped in earlier versions]
{
2.6
}
\end{memberdesc}
\begin{memberdesc}
{
initial
_
indent
}
(default:
\code
{
''
}
) String that will be prepended to the first line
of wrapped output. Counts towards the length of the first line.
...
...
Lib/test/test_textwrap.py
Dosyayı görüntüle @
9e6b4700
...
...
@@ -328,6 +328,14 @@ What a mess!
self
.
check_wrap
(
text
,
30
,
[
" This is a sentence with"
,
"leading whitespace."
])
def
test_no_drop_whitespace
(
self
):
# SF patch #1581073
text
=
" This is a sentence with much whitespace."
self
.
check_wrap
(
text
,
10
,
[
" This is a"
,
" "
,
"sentence "
,
"with "
,
"much white"
,
"space."
],
drop_whitespace
=
False
)
if
test_support
.
have_unicode
:
def
test_unicode
(
self
):
# *Very* simple test of wrapping Unicode strings. I'm sure
...
...
Lib/textwrap.py
Dosyayı görüntüle @
9e6b4700
...
...
@@ -63,6 +63,8 @@ class TextWrapper:
break_long_words (default: true)
Break words longer than 'width'. If false, those words will not
be broken, and some lines might be longer than 'width'.
drop_whitespace (default: true)
Drop leading and trailing whitespace from lines.
"""
whitespace_trans
=
string
.
maketrans
(
_whitespace
,
' '
*
len
(
_whitespace
))
...
...
@@ -98,7 +100,8 @@ class TextWrapper:
expand_tabs
=
True
,
replace_whitespace
=
True
,
fix_sentence_endings
=
False
,
break_long_words
=
True
):
break_long_words
=
True
,
drop_whitespace
=
True
):
self
.
width
=
width
self
.
initial_indent
=
initial_indent
self
.
subsequent_indent
=
subsequent_indent
...
...
@@ -106,6 +109,7 @@ class TextWrapper:
self
.
replace_whitespace
=
replace_whitespace
self
.
fix_sentence_endings
=
fix_sentence_endings
self
.
break_long_words
=
break_long_words
self
.
drop_whitespace
=
drop_whitespace
# -- Private methods -----------------------------------------------
...
...
@@ -140,7 +144,7 @@ class TextWrapper:
'use', ' ', 'the', ' ', '-b', ' ', 'option!'
"""
chunks
=
self
.
wordsep_re
.
split
(
text
)
chunks
=
filter
(
None
,
chunks
)
chunks
=
filter
(
None
,
chunks
)
# remove empty chunks
return
chunks
def
_fix_sentence_endings
(
self
,
chunks
):
...
...
@@ -228,7 +232,7 @@ 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
[
-
1
]
.
strip
()
==
''
and
lines
:
if
self
.
drop_whitespace
and
chunks
[
-
1
]
.
strip
()
==
''
and
lines
:
del
chunks
[
-
1
]
while
chunks
:
...
...
@@ -249,7 +253,7 @@ class TextWrapper:
self
.
_handle_long_word
(
chunks
,
cur_line
,
cur_len
,
width
)
# If the last chunk on this line is all whitespace, drop it.
if
cur_line
and
cur_line
[
-
1
]
.
strip
()
==
''
:
if
self
.
drop_whitespace
and
cur_line
and
cur_line
[
-
1
]
.
strip
()
==
''
:
del
cur_line
[
-
1
]
# Convert current line back to a string and store it in list
...
...
Misc/NEWS
Dosyayı görüntüle @
9e6b4700
...
...
@@ -168,6 +168,9 @@ Core and builtins
Library
-------
- Patch #1581073: add a flag to textwrap that prevents the dropping of
whitespace while wrapping.
- Patch #1603688: ConfigParser.SafeConfigParser now checks values that
are set for invalid interpolation sequences that would lead to errors
on reading back those values.
...
...
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