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
6af4abdb
Kaydet (Commit)
6af4abdb
authored
Agu 13, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Various changes by AMK, e.g. remove \e, \cX, add \v
üst
c24f0384
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
re.py
Lib/re.py
+22
-19
No files found.
Lib/re.py
Dosyayı görüntüle @
6af4abdb
...
...
@@ -5,7 +5,13 @@
import
string
import
reop
error
=
're error'
# reop.error and re.error should be the same, since exceptions can be
# raised from either module.
error
=
reop
.
error
# 're error'
from
reop
import
NORMAL
,
CHARCLASS
,
REPLACEMENT
from
reop
import
CHAR
,
MEMORY_REFERENCE
,
SYNTAX
,
NOT_SYNTAX
,
SET
from
reop
import
WORD_BOUNDARY
,
NOT_WORD_BOUNDARY
,
BEGINNING_OF_BUFFER
,
END_OF_BUFFER
# compilation flags
...
...
@@ -622,9 +628,9 @@ def build_fastmap(code, pos=0):
#
#
[
NORMAL
,
CHARCLASS
,
REPLACEMENT
]
=
range
(
3
)
[
CHAR
,
MEMORY_REFERENCE
,
SYNTAX
,
NOT_SYNTAX
,
SET
,
WORD_BOUNDARY
,
NOT_WORD_BOUNDARY
,
BEGINNING_OF_BUFFER
,
END_OF_BUFFER
]
=
range
(
9
)
#
[NORMAL, CHARCLASS, REPLACEMENT] = range(3)
#
[CHAR, MEMORY_REFERENCE, SYNTAX, NOT_SYNTAX, SET, WORD_BOUNDARY,
#
NOT_WORD_BOUNDARY, BEGINNING_OF_BUFFER, END_OF_BUFFER] = range(9)
def
expand_escape
(
pattern
,
index
,
context
=
NORMAL
):
if
index
>=
len
(
pattern
):
...
...
@@ -636,6 +642,9 @@ def expand_escape(pattern, index, context=NORMAL):
elif
pattern
[
index
]
==
'n'
:
return
CHAR
,
chr
(
10
),
index
+
1
elif
pattern
[
index
]
==
'v'
:
return
CHAR
,
chr
(
11
),
index
+
1
elif
pattern
[
index
]
==
'r'
:
return
CHAR
,
chr
(
13
),
index
+
1
...
...
@@ -645,20 +654,9 @@ def expand_escape(pattern, index, context=NORMAL):
elif
pattern
[
index
]
==
'a'
:
return
CHAR
,
chr
(
7
),
index
+
1
elif
pattern
[
index
]
==
'e'
:
return
CHAR
,
chr
(
27
),
index
+
1
elif
pattern
[
index
]
==
'c'
:
if
index
+
1
>=
len
(
pattern
):
raise
error
,
'
\\
c must be followed by another character'
elif
pattern
[
index
+
1
]
in
'abcdefghijklmnopqrstuvwxyz'
:
return
CHAR
,
chr
(
ord
(
pattern
[
index
+
1
])
-
ord
(
'a'
)
+
1
),
index
+
2
else
:
return
CHAR
,
chr
(
ord
(
pattern
[
index
+
1
])
^
64
),
index
+
2
elif
pattern
[
index
]
==
'x'
:
# CAUTION: this is the Python rule, not the Perl rule!
end
=
index
end
=
index
+
1
# Skip over the 'x' character
while
(
end
<
len
(
pattern
))
and
(
pattern
[
end
]
in
string
.
hexdigits
):
end
=
end
+
1
if
end
==
index
:
...
...
@@ -666,7 +664,7 @@ def expand_escape(pattern, index, context=NORMAL):
# let Python evaluate it, so we don't incorrectly 2nd-guess
# what it's doing (and Python in turn passes it on to sscanf,
# so that *it* doesn't incorrectly 2nd-guess what C does!)
char
=
eval
(
'"'
+
pattern
[
index
-
2
:
end
]
+
'"'
)
char
=
eval
(
'"'
+
pattern
[
index
-
1
:
end
]
+
'"'
)
assert
len
(
char
)
==
1
return
CHAR
,
char
,
end
...
...
@@ -690,12 +688,12 @@ def expand_escape(pattern, index, context=NORMAL):
elif
pattern
[
index
]
==
'Z'
:
if
context
!=
NORMAL
:
return
'Z'
,
index
+
1
return
CHAR
,
'Z'
,
index
+
1
else
:
return
END_OF_BUFFER
,
''
,
index
+
1
elif
pattern
[
index
]
in
'GluLUQE'
:
raise
error
,
(
'
\\
'
+
ch
+
' is not allowed'
)
raise
error
,
(
'
\\
'
+
pattern
[
index
]
+
' is not allowed'
)
elif
pattern
[
index
]
==
'w'
:
if
context
==
NORMAL
:
...
...
@@ -1488,3 +1486,8 @@ def compile(pattern, flags=0):
label
=
label
+
1
code
.
append
(
End
())
return
RegexObject
(
pattern
,
flags
,
code
,
register
,
groupindex
)
# Replace expand_escape and _expand functions with their C equivalents.
# If you suspect bugs in the C versions, comment out the next two lines
expand_escape
=
reop
.
expand_escape
_expand
=
reop
.
_expand
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