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
88fdeb45
Kaydet (Commit)
88fdeb45
authored
Nis 10, 2011
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
#2650: re.escape() no longer escapes the "_".
üst
344d26c7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
8 deletions
+15
-8
re.rst
Doc/library/re.rst
+6
-3
re.py
Lib/re.py
+5
-3
test_re.py
Lib/test/test_re.py
+2
-2
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/re.rst
Dosyayı görüntüle @
88fdeb45
...
...
@@ -689,9 +689,12 @@ form.
.. function:: escape(string)
Return *string* with all non-alphanumerics backslashed; this is useful if you
want to match an arbitrary literal string that may have regular expression
metacharacters in it.
Escape all the characters in pattern except ASCII letters, numbers and ``'_'``.
This is useful if you want to match an arbitrary literal string that may
have regular expression metacharacters in it.
.. versionchanged:: 3.3
The ``'_'`` character is no longer escaped.
.. function:: purge()
...
...
Lib/re.py
Dosyayı görüntüle @
88fdeb45
...
...
@@ -215,12 +215,14 @@ def template(pattern, flags=0):
return
_compile
(
pattern
,
flags
|
T
)
_alphanum_str
=
frozenset
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
)
"
_
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
)
_alphanum_bytes
=
frozenset
(
b
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
)
b
"
_
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
)
def
escape
(
pattern
):
"Escape all non-alphanumeric characters in pattern."
"""
Escape all the characters in pattern except ASCII letters, numbers and '_'.
"""
if
isinstance
(
pattern
,
str
):
alphanum
=
_alphanum_str
s
=
list
(
pattern
)
...
...
Lib/test/test_re.py
Dosyayı görüntüle @
88fdeb45
...
...
@@ -428,7 +428,7 @@ class ReTests(unittest.TestCase):
self
.
assertEqual
(
m
.
span
(),
span
)
def
test_re_escape
(
self
):
alnum_chars
=
string
.
ascii_letters
+
string
.
digits
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
:
...
...
@@ -441,7 +441,7 @@ class ReTests(unittest.TestCase):
self
.
assertMatch
(
re
.
escape
(
p
),
p
)
def
test_re_escape_byte
(
self
):
alnum_chars
=
(
string
.
ascii_letters
+
string
.
digits
)
.
encode
(
'ascii'
)
alnum_chars
=
(
string
.
ascii_letters
+
string
.
digits
+
'_'
)
.
encode
(
'ascii'
)
p
=
bytes
(
range
(
256
))
for
i
in
p
:
b
=
bytes
([
i
])
...
...
Misc/NEWS
Dosyayı görüntüle @
88fdeb45
...
...
@@ -98,6 +98,8 @@ Core and Builtins
Library
-------
- Issue #2650: re.escape() no longer escapes the '
_
'.
- Issue #11757: select.select() now raises ValueError when a negative timeout
is passed (previously, a select.error with EINVAL would be raised). 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