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
2498c9f0
Kaydet (Commit)
2498c9f0
authored
Nis 11, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #11747: Fix range formatting in context and unified diffs.
üst
a3359eec
49353d0e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
11 deletions
+42
-11
difflib.py
Lib/difflib.py
+23
-11
test_difflib.py
Lib/test/test_difflib.py
+16
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/difflib.py
Dosyayı görüntüle @
2498c9f0
...
...
@@ -1144,6 +1144,17 @@ def IS_CHARACTER_JUNK(ch, ws=" \t"):
return
ch
in
ws
def
_format_range
(
start
,
stop
):
'Convert range to the "ed" format'
# Per the diff spec at http://www.unix.org/single_unix_specification/
beginning
=
start
+
1
# lines start numbering with one
length
=
stop
-
start
if
length
==
1
:
return
'{}'
.
format
(
beginning
)
if
not
length
:
beginning
-=
1
# empty ranges begin at line just before the range
return
'{},{}'
.
format
(
beginning
,
length
)
def
unified_diff
(
a
,
b
,
fromfile
=
''
,
tofile
=
''
,
fromfiledate
=
''
,
tofiledate
=
''
,
n
=
3
,
lineterm
=
'
\n
'
):
r"""
...
...
@@ -1193,9 +1204,12 @@ def unified_diff(a, b, fromfile='', tofile='', fromfiledate='',
todate
=
'
\t
{}'
.
format
(
tofiledate
)
if
tofiledate
else
''
yield
'--- {}{}{}'
.
format
(
fromfile
,
fromdate
,
lineterm
)
yield
'+++ {}{}{}'
.
format
(
tofile
,
todate
,
lineterm
)
first
,
last
=
group
[
0
],
group
[
-
1
]
i1
,
i2
,
j1
,
j2
=
first
[
1
],
last
[
2
],
first
[
3
],
last
[
4
]
yield
'@@ -{},{} +{},{} @@{}'
.
format
(
i1
+
1
,
i2
-
i1
,
j1
+
1
,
j2
-
j1
,
lineterm
)
file1_range
=
_format_range
(
first
[
1
],
last
[
2
])
file2_range
=
_format_range
(
first
[
3
],
last
[
4
])
yield
'@@ -{} +{} @@{}'
.
format
(
file1_range
,
file2_range
,
lineterm
)
for
tag
,
i1
,
i2
,
j1
,
j2
in
group
:
if
tag
==
'equal'
:
for
line
in
a
[
i1
:
i2
]:
...
...
@@ -1264,22 +1278,20 @@ def context_diff(a, b, fromfile='', tofile='',
yield
'--- {}{}{}'
.
format
(
tofile
,
todate
,
lineterm
)
first
,
last
=
group
[
0
],
group
[
-
1
]
yield
'***************{}'
.
format
(
lineterm
)
yield
'***************'
+
lineterm
file1_range
=
_format_range
(
first
[
1
],
last
[
2
])
yield
'*** {} ****{}'
.
format
(
file1_range
,
lineterm
)
if
last
[
2
]
-
first
[
1
]
>
1
:
yield
'*** {},{} ****{}'
.
format
(
first
[
1
]
+
1
,
last
[
2
],
lineterm
)
else
:
yield
'*** {} ****{}'
.
format
(
last
[
2
],
lineterm
)
if
any
(
tag
in
{
'replace'
,
'delete'
}
for
tag
,
_
,
_
,
_
,
_
in
group
):
for
tag
,
i1
,
i2
,
_
,
_
in
group
:
if
tag
!=
'insert'
:
for
line
in
a
[
i1
:
i2
]:
yield
prefix
[
tag
]
+
line
if
last
[
4
]
-
first
[
3
]
>
1
:
yield
'--- {},{} ----{}'
.
format
(
first
[
3
]
+
1
,
last
[
4
],
lineterm
)
else
:
yield
'--- {} ----{}'
.
format
(
last
[
4
],
lineterm
)
file2_range
=
_format_range
(
first
[
3
],
last
[
4
])
yield
'--- {} ----{}'
.
format
(
file2_range
,
lineterm
)
if
any
(
tag
in
{
'replace'
,
'insert'
}
for
tag
,
_
,
_
,
_
,
_
in
group
):
for
tag
,
_
,
_
,
j1
,
j2
in
group
:
if
tag
!=
'delete'
:
...
...
Lib/test/test_difflib.py
Dosyayı görüntüle @
2498c9f0
...
...
@@ -236,6 +236,22 @@ class TestOutputFormat(unittest.TestCase):
cd
=
difflib
.
context_diff
(
*
args
,
lineterm
=
''
)
self
.
assertEqual
(
list
(
cd
)[
0
:
2
],
[
"*** Original"
,
"--- Current"
])
def
test_range_format
(
self
):
# Per the diff spec at http://www.unix.org/single_unix_specification/
spec
=
'''
\
Each <range> field shall be of the form:
%1
d", <beginning line number> if the range contains exactly one line,
and:
"
%1
d,
%1
d", <beginning line number>, <number of lines> otherwise.
If a range is empty, its beginning line number shall be the number of
the line just before the range, or 0 if the empty range starts the file.
'''
fmt
=
difflib
.
_format_range
self
.
assertEqual
(
fmt
(
3
,
3
),
'3,0'
)
self
.
assertEqual
(
fmt
(
3
,
4
),
'4'
)
self
.
assertEqual
(
fmt
(
3
,
5
),
'4,2'
)
self
.
assertEqual
(
fmt
(
3
,
6
),
'4,3'
)
self
.
assertEqual
(
fmt
(
0
,
0
),
'0,0'
)
def
test_main
():
difflib
.
HtmlDiff
.
_default_prefix
=
0
...
...
Misc/NEWS
Dosyayı görüntüle @
2498c9f0
...
...
@@ -109,6 +109,9 @@ Library
- Issue #11814: Fix likely typo in multiprocessing.Pool._terminate().
- Issue #11747: Fix range formatting in difflib.context_diff() and
difflib.unified_diff().
- Issue #8428: Fix a race condition in multiprocessing.Pool when terminating
worker processes: new processes would be spawned while the pool is being
shut down. Patch by Charles-François Natali.
...
...
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