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
213eb969
Kaydet (Commit)
213eb969
authored
Mar 25, 2011
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
#2650: Merge with 3.1.
üst
32a95a70
ebbf1e67
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
24 deletions
+56
-24
re.py
Lib/re.py
+1
-2
test_re.py
Lib/test/test_re.py
+55
-22
No files found.
Lib/re.py
Dosyayı görüntüle @
213eb969
...
...
@@ -224,8 +224,7 @@ def escape(pattern):
if
isinstance
(
pattern
,
str
):
alphanum
=
_alphanum_str
s
=
list
(
pattern
)
for
i
in
range
(
len
(
pattern
)):
c
=
pattern
[
i
]
for
i
,
c
in
enumerate
(
pattern
):
if
c
not
in
alphanum
:
if
c
==
"
\000
"
:
s
[
i
]
=
"
\\
000"
...
...
Lib/test/test_re.py
Dosyayı görüntüle @
213eb969
from
test.support
import
verbose
,
run_unittest
import
re
from
re
import
Scanner
import
sys
,
traceback
import
sys
import
string
import
traceback
from
weakref
import
proxy
# Misc tests from Tim Peters' re.doc
...
...
@@ -411,31 +413,62 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
re
.
search
(
"
\
s(b)"
,
" b"
)
.
group
(
1
),
"b"
)
self
.
assertEqual
(
re
.
search
(
"a
\
s"
,
"a "
)
.
group
(
0
),
"a "
)
def
assertMatch
(
self
,
pattern
,
text
,
match
=
None
,
span
=
None
,
matcher
=
re
.
match
):
if
match
is
None
and
span
is
None
:
# the pattern matches the whole text
match
=
text
span
=
(
0
,
len
(
text
))
elif
match
is
None
or
span
is
None
:
raise
ValueError
(
'If match is not None, span should be specified '
'(and vice versa).'
)
m
=
matcher
(
pattern
,
text
)
self
.
assertTrue
(
m
)
self
.
assertEqual
(
m
.
group
(),
match
)
self
.
assertEqual
(
m
.
span
(),
span
)
def
test_re_escape
(
self
):
p
=
""
self
.
assertEqual
(
re
.
escape
(
p
),
p
)
for
i
in
range
(
0
,
256
)
:
p
=
p
+
chr
(
i
)
self
.
assertEqual
(
re
.
match
(
re
.
escape
(
chr
(
i
)),
chr
(
i
))
is
not
None
,
True
)
self
.
assertEqual
(
re
.
match
(
re
.
escape
(
chr
(
i
)),
chr
(
i
))
.
span
(),
(
0
,
1
)
)
pat
=
re
.
compile
(
re
.
escape
(
p
)
)
self
.
assertEqual
(
pat
.
match
(
p
)
is
not
None
,
True
)
self
.
assert
Equal
(
pat
.
match
(
p
)
.
span
(),
(
0
,
256
)
)
alnum_chars
=
string
.
ascii_letters
+
string
.
digits
p
=
''
.
join
(
chr
(
i
)
for
i
in
range
(
256
)
)
for
c
in
p
:
if
c
in
alnum_chars
:
self
.
assertEqual
(
re
.
escape
(
c
),
c
)
elif
c
==
'
\x00
'
:
self
.
assertEqual
(
re
.
escape
(
c
),
'
\\
000'
)
else
:
self
.
assertEqual
(
re
.
escape
(
c
),
'
\\
'
+
c
)
self
.
assertMatch
(
re
.
escape
(
c
),
c
)
self
.
assert
Match
(
re
.
escape
(
p
),
p
)
def
test_re_escape_byte
(
self
):
p
=
b
""
self
.
assertEqual
(
re
.
escape
(
p
),
p
)
for
i
in
range
(
0
,
256
)
:
alnum_chars
=
(
string
.
ascii_letters
+
string
.
digits
)
.
encode
(
'ascii'
)
p
=
bytes
(
range
(
256
)
)
for
i
in
p
:
b
=
bytes
([
i
])
p
+=
b
self
.
assertEqual
(
re
.
match
(
re
.
escape
(
b
),
b
)
is
not
None
,
True
)
self
.
assertEqual
(
re
.
match
(
re
.
escape
(
b
),
b
)
.
span
(),
(
0
,
1
))
pat
=
re
.
compile
(
re
.
escape
(
p
))
self
.
assertEqual
(
pat
.
match
(
p
)
is
not
None
,
True
)
self
.
assertEqual
(
pat
.
match
(
p
)
.
span
(),
(
0
,
256
))
if
b
in
alnum_chars
:
self
.
assertEqual
(
re
.
escape
(
b
),
b
)
elif
i
==
0
:
self
.
assertEqual
(
re
.
escape
(
b
),
b
'
\\
000'
)
else
:
self
.
assertEqual
(
re
.
escape
(
b
),
b
'
\\
'
+
b
)
self
.
assertMatch
(
re
.
escape
(
b
),
b
)
self
.
assertMatch
(
re
.
escape
(
p
),
p
)
def
test_re_escape_non_ascii
(
self
):
s
=
'xxx
\u2620\u2620\u2620
xxx'
s_escaped
=
re
.
escape
(
s
)
self
.
assertEqual
(
s_escaped
,
'xxx
\\\u2620\\\u2620\\\u2620
xxx'
)
self
.
assertMatch
(
s_escaped
,
s
)
self
.
assertMatch
(
'.
%
s+.'
%
re
.
escape
(
'
\u2620
'
),
s
,
'x
\u2620\u2620\u2620
x'
,
(
2
,
7
),
re
.
search
)
def
test_re_escape_non_ascii_bytes
(
self
):
b
=
'y
\u2620
y
\u2620
y'
.
encode
(
'utf-8'
)
b_escaped
=
re
.
escape
(
b
)
self
.
assertEqual
(
b_escaped
,
b
'y
\\\xe2\\\x98\\\xa0
y
\\\xe2\\\x98\\\xa0
y'
)
self
.
assertMatch
(
b_escaped
,
b
)
res
=
re
.
findall
(
re
.
escape
(
'
\u2620
'
.
encode
(
'utf-8'
)),
b
)
self
.
assertEqual
(
len
(
res
),
2
)
def
pickle_test
(
self
,
pickle
):
oldpat
=
re
.
compile
(
'a(?:b|(c|e){1,2}?|d)+?(.)'
)
...
...
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