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
72bd327d
Kaydet (Commit)
72bd327d
authored
Mar 24, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #22687: Fixed some corner cases in breaking words in tetxtwrap.
Got rid of quadratic complexity in breaking long words.
üst
b365a06a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
4 deletions
+38
-4
test_textwrap.py
Lib/test/test_textwrap.py
+16
-0
textwrap.py
Lib/textwrap.py
+19
-4
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_textwrap.py
Dosyayı görüntüle @
72bd327d
...
...
@@ -184,6 +184,16 @@ What a mess!
self
.
check_wrap
(
text
,
42
,
[
"this-is-a-useful-feature-for-reformatting-"
,
"posts-from-tim-peters'ly"
])
# The test tests current behavior but is not testing parts of the API.
expect
=
(
"this-|is-|a-|useful-|feature-|for-|"
"reformatting-|posts-|from-|tim-|peters'ly"
)
.
split
(
'|'
)
self
.
check_wrap
(
text
,
1
,
expect
,
break_long_words
=
False
)
self
.
check_split
(
text
,
expect
)
self
.
check_split
(
'e-mail'
,
[
'e-mail'
])
self
.
check_split
(
'Jelly-O'
,
[
'Jelly-O'
])
# The test tests current behavior but is not testing parts of the API.
self
.
check_split
(
'half-a-crown'
,
'half-|a-|crown'
.
split
(
'|'
))
def
test_hyphenated_numbers
(
self
):
# Test that hyphenated numbers (eg. dates) are not broken like words.
...
...
@@ -195,6 +205,7 @@ What a mess!
'released on 1994-02-15.'
])
self
.
check_wrap
(
text
,
40
,
[
'Python 1.0.0 was released on 1994-01-26.'
,
'Python 1.0.1 was released on 1994-02-15.'
])
self
.
check_wrap
(
text
,
1
,
text
.
split
(),
break_long_words
=
False
)
text
=
"I do all my shopping at 7-11."
self
.
check_wrap
(
text
,
25
,
[
"I do all my shopping at"
,
...
...
@@ -202,6 +213,7 @@ What a mess!
self
.
check_wrap
(
text
,
27
,
[
"I do all my shopping at"
,
"7-11."
])
self
.
check_wrap
(
text
,
29
,
[
"I do all my shopping at 7-11."
])
self
.
check_wrap
(
text
,
1
,
text
.
split
(),
break_long_words
=
False
)
def
test_em_dash
(
self
):
# Test text with em-dashes
...
...
@@ -326,6 +338,10 @@ What a mess!
self
.
check_split
(
"the ['wibble-wobble'] widget"
,
[
'the'
,
' '
,
"['wibble-"
,
"wobble']"
,
' '
,
'widget'
])
# The test tests current behavior but is not testing parts of the API.
self
.
check_split
(
"what-d'you-call-it."
,
"what-d'you-|call-|it."
.
split
(
'|'
))
def
test_funky_parens
(
self
):
# Second part of SF bug #596434: long option strings inside
# parentheses.
...
...
Lib/textwrap.py
Dosyayı görüntüle @
72bd327d
...
...
@@ -79,10 +79,25 @@ class TextWrapper:
# splits into
# Hello/ /there/ /--/ /you/ /goof-/ball,/ /use/ /the/ /-b/ /option!
# (after stripping out empty strings).
wordsep_re
=
re
.
compile
(
r'(\s+|'
# any whitespace
r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|'
# hyphenated words
r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))'
)
# em-dash
word_punct
=
r'[\w!"\'&.,?]'
letter
=
r'[^\d\W]'
wordsep_re
=
re
.
compile
(
r'''
( # any whitespace
\s+
| # em-dash between words
(?<=
%(wp)
s) -{2,} (?=\w)
| # word, possibly hyphenated
\S+? (?:
# hyphenated word
-(?: (?<=
%(lt)
s{2}-) | (?<=
%(lt)
s-
%(lt)
s-))
(?=
%(lt)
s -?
%(lt)
s)
| # end of word
(?=\s|\Z)
| # em-dash
(?<=
%(wp)
s) (?=-{2,}\w)
)
)'''
%
{
'wp'
:
word_punct
,
'lt'
:
letter
},
re
.
VERBOSE
)
del
word_punct
,
letter
# This less funky little regex just split on recognized spaces. E.g.
# "Hello there -- you goof-ball, use the -b option!"
...
...
Misc/NEWS
Dosyayı görüntüle @
72bd327d
...
...
@@ -26,6 +26,9 @@ Core and Builtins
Library
-------
-
Issue
#
22687
:
Fixed
some
corner
cases
in
breaking
words
in
tetxtwrap
.
Got
rid
of
quadratic
complexity
in
breaking
long
words
.
-
Issue
#
20289
:
The
copy
module
now
uses
pickle
protocol
4
(
PEP
3154
)
and
supports
copying
of
instances
of
classes
whose
__new__
method
takes
keyword
-
only
arguments
.
...
...
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