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
8a9a4a23
Kaydet (Commit)
8a9a4a23
authored
Tem 11, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Jeffrey's latest.
üst
035aae0f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
50 deletions
+71
-50
re.py
Lib/re.py
+71
-50
test_re
Lib/test/output/test_re
+0
-0
No files found.
Lib/re.py
Dosyayı görüntüle @
8a9a4a23
...
...
@@ -51,13 +51,13 @@ def search(pattern, string, flags=0):
return
compile
(
pattern
,
flags
)
.
search
(
string
)
def
sub
(
pattern
,
repl
,
string
,
count
=
0
):
pass
return
compile
(
pattern
)
.
sub
(
repl
,
string
,
count
)
def
subn
(
pattern
,
repl
,
string
,
count
=
0
):
pass
return
compile
(
pattern
)
.
subn
(
repl
,
string
,
count
)
def
split
(
string
,
pattern
,
maxsplit
=
0
):
pass
def
split
(
pattern
,
string
,
maxsplit
=
0
):
return
compile
(
pattern
)
.
subn
(
string
,
maxsplit
)
#
#
...
...
@@ -79,21 +79,6 @@ class RegexObject:
else
:
self
.
anchor
=
0
self
.
buffer
=
assemble
(
code
)
def
match
(
self
,
string
,
pos
=
0
):
regs
=
reop
.
match
(
self
.
buffer
,
self
.
num_regs
,
self
.
flags
,
self
.
fastmap
.
can_be_null
,
self
.
fastmap
.
fastmap
(),
self
.
anchor
,
string
,
pos
)
if
regs
is
None
:
return
None
return
MatchObject
(
self
,
string
,
pos
,
regs
)
def
search
(
self
,
string
,
pos
=
0
):
regs
=
reop
.
search
(
self
.
buffer
,
self
.
num_regs
,
...
...
@@ -109,6 +94,27 @@ class RegexObject:
string
,
pos
,
regs
)
def
match
(
self
,
string
,
pos
=
0
):
regs
=
reop
.
match
(
self
.
buffer
,
self
.
num_regs
,
self
.
flags
,
self
.
fastmap
.
can_be_null
,
self
.
fastmap
.
fastmap
(),
self
.
anchor
,
string
,
pos
)
if
regs
is
None
:
return
None
return
MatchObject
(
self
,
string
,
pos
,
regs
)
def
sub
(
self
,
repl
,
string
,
count
=
0
):
pass
def
subn
(
self
,
repl
,
string
,
count
=
0
):
pass
def
split
(
self
,
string
,
maxsplit
=
0
):
pass
class
MatchObject
:
def
__init__
(
self
,
re
,
string
,
pos
,
regs
):
...
...
@@ -116,34 +122,49 @@ class MatchObject:
self
.
string
=
string
self
.
pos
=
pos
self
.
regs
=
regs
def
start
(
self
,
i
):
if
type
(
i
)
==
type
(
''
):
def
start
(
self
,
g
):
if
type
(
g
)
==
type
(
''
):
try
:
i
=
self
.
re
.
groupindex
[
i
]
g
=
self
.
re
.
groupindex
[
g
]
except
(
KeyError
,
TypeError
):
raise
IndexError
return
self
.
regs
[
i
][
0
]
def
end
(
self
,
i
):
if
type
(
i
)
==
type
(
''
):
raise
IndexError
,
(
'group "'
+
g
+
'" is undefined'
)
return
self
.
regs
[
g
][
0
]
def
end
(
self
,
g
):
if
type
(
g
)
==
type
(
''
):
try
:
i
=
self
.
re
.
groupindex
[
i
]
g
=
self
.
re
.
groupindex
[
g
]
except
(
KeyError
,
TypeError
):
raise
IndexError
return
self
.
regs
[
i
][
1
]
def
span
(
self
,
i
):
if
type
(
i
)
==
type
(
''
):
raise
IndexError
,
(
'group "'
+
g
+
'" is undefined'
)
return
self
.
regs
[
g
][
1
]
def
span
(
self
,
g
):
if
type
(
g
)
==
type
(
''
):
try
:
i
=
self
.
re
.
groupindex
[
i
]
g
=
self
.
re
.
groupindex
[
g
]
except
(
KeyError
,
TypeError
):
raise
IndexError
return
self
.
regs
[
i
]
def
group
(
self
,
i
):
if
type
(
i
)
==
type
(
''
):
try
:
i
=
self
.
re
.
groupindex
[
i
]
except
(
KeyError
,
TypeError
):
raise
IndexError
return
self
.
string
[
self
.
regs
[
i
][
0
]:
self
.
regs
[
i
][
1
]]
raise
IndexError
,
(
'group "'
+
g
+
'" is undefined'
)
return
self
.
regs
[
g
]
def
group
(
self
,
*
groups
):
if
len
(
groups
)
==
0
:
groups
=
range
(
1
,
self
.
re
.
num_regs
)
result
=
[]
for
g
in
groups
:
if
type
(
g
)
==
type
(
''
):
try
:
g
=
self
.
re
.
groupindex
[
g
]
except
(
KeyError
,
TypeError
):
raise
IndexError
,
(
'group "'
+
g
+
'" is undefined'
)
if
g
>=
len
(
self
.
regs
):
result
.
append
(
None
)
elif
(
self
.
regs
[
g
][
0
]
==
-
1
)
or
(
self
.
regs
[
g
][
1
]
==
-
1
):
result
.
append
(
None
)
else
:
result
.
append
(
self
.
string
[
self
.
regs
[
g
][
0
]:
self
.
regs
[
g
][
1
]])
if
len
(
result
)
>
1
:
return
tuple
(
result
)
elif
len
(
result
)
==
1
:
return
result
[
0
]
else
:
return
()
#
# A set of classes to make assembly a bit easier, if a bit verbose.
...
...
@@ -331,7 +352,7 @@ class SyntaxSpec(Instruction):
def
assemble
(
self
,
postition
,
labels
):
return
self
.
opcode
+
chr
(
self
.
syntax
)
class
SyntaxSpec
(
Instruction
):
class
Not
SyntaxSpec
(
Instruction
):
name
=
'notsyntaxspec'
def
__init__
(
self
,
syntax
):
self
.
syntax
=
syntax
...
...
@@ -382,13 +403,12 @@ def assemble(instructions):
#
def
escape
(
pattern
):
result
=
''
result
=
[]
for
char
in
pattern
:
if
'word'
not
in
syntax_table
[
char
]:
result
=
result
+
'
\\
'
+
char
else
:
result
=
result
+
char
return
result
result
.
append
(
'
\\
'
)
result
.
append
(
char
)
return
string
.
join
(
result
,
''
)
#
#
...
...
@@ -631,7 +651,7 @@ def compile(pattern, flags=0):
expr
+
\
[
Jump
(
-
1
),
Label
(
label
)])
stack
.
append
([
(
'|'
,
)])
stack
.
append
([
Alternation
(
)])
label
=
label
+
1
elif
char
==
'('
:
...
...
@@ -693,12 +713,13 @@ def compile(pattern, flags=0):
stack
.
append
([
FunctionCallout
(
name
)])
else
:
raise
error
,
'unknown Python extension'
raise
error
,
(
'unknown Python extension: '
+
\
pattern
[
index
])
elif
pattern
[
index
]
==
':'
:
# grouping, but no registers
index
=
index
+
1
stack
.
append
([
(
'('
,
-
1
)])
stack
.
append
([
OpenParen
(
-
1
)])
elif
pattern
[
index
]
==
'#'
:
# comment
...
...
Lib/test/output/test_re
Dosyayı görüntüle @
8a9a4a23
This diff is collapsed.
Click to expand it.
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