Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
2a8f4f52
Commit
2a8f4f52
authored
Aug 17, 1999
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed to not use Synchronized because there is a refcounting
problem with the Synchronized class. :(
parent
6f33860d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
40 deletions
+70
-40
lib/python/ts_regex.py
lib/python/ts_regex.py
+70
-40
No files found.
lib/python/ts_regex.py
View file @
2a8f4f52
...
...
@@ -84,11 +84,40 @@
##############################################################################
"""Provide a thread-safe interface to regex
"""
import
regex
,
regsub
,
Sync
import
regex
,
regsub
#
, Sync
from
regex
import
*
from
regsub
import
split
,
sub
,
gsub
,
splitx
,
capwords
class
compile
(
Sync
.
Synchronized
):
try
:
import
thread
except
:
class
allocate_lock
:
def
acquire
(
*
args
):
pass
def
release
(
*
args
):
pass
else
:
class
SafeFunction
:
_l
=
thread
.
allocate_lock
()
_a
=
_l
.
acquire
_r
=
_l
.
release
def
__init__
(
self
,
f
):
self
.
_f
=
f
def
__call__
(
self
,
*
args
,
**
kw
):
self
.
_a
()
try
:
return
apply
(
self
.
_f
,
args
,
kw
)
finally
:
self
.
_r
()
split
=
SafeFunction
(
split
)
sub
=
SafeFunction
(
sub
)
gsub
=
SafeFunction
(
gsub
)
splitx
=
SafeFunction
(
splitx
)
capwords
=
SafeFunction
(
capwords
)
allocate_lock
=
thread
.
allocate_lock
class
compile
:
_r
=
None
groupindex
=
None
...
...
@@ -96,13 +125,24 @@ class compile(Sync.Synchronized):
def
__init__
(
self
,
*
args
):
self
.
_r
=
r
=
apply
(
regex
.
compile
,
args
)
self
.
_init
(
r
)
lock
=
allocate_lock
()
self
.
__a
=
lock
.
acquire
self
.
__r
=
lock
.
release
def
_init
(
self
,
r
):
self
.
search
=
r
.
search
self
.
match
=
r
.
match
self
.
translate
=
r
.
translate
self
.
givenpat
=
r
.
givenpat
self
.
realpat
=
r
.
realpat
def
match
(
self
,
string
,
pos
=
0
):
self
.
__a
()
try
:
return
self
.
_r
.
match
(
string
,
pos
)
finally
:
self
.
__r
()
def
search
(
self
,
string
,
pos
=
0
):
self
.
__a
()
try
:
return
self
.
_r
.
search
(
string
,
pos
)
finally
:
self
.
__r
()
def
search_group
(
self
,
str
,
group
,
pos
=
0
):
"""Search a string for a pattern.
...
...
@@ -111,10 +151,13 @@ class compile(Sync.Synchronized):
otherwise, the location where the pattern was found,
as well as any specified group are returned.
"""
r
=
self
.
_r
l
=
r
.
search
(
str
,
pos
)
if
l
<
0
:
return
None
return
l
,
apply
(
r
.
group
,
group
)
self
.
__a
()
try
:
r
=
self
.
_r
l
=
r
.
search
(
str
,
pos
)
if
l
<
0
:
return
None
return
l
,
apply
(
r
.
group
,
group
)
finally
:
self
.
__r
()
def
match_group
(
self
,
str
,
group
,
pos
=
0
):
"""Match a pattern against a string
...
...
@@ -123,10 +166,13 @@ class compile(Sync.Synchronized):
returned, otherwise, the length of the match, as well
as any specified group are returned.
"""
r
=
self
.
_r
l
=
r
.
match
(
str
,
pos
)
if
l
<
0
:
return
None
return
l
,
apply
(
r
.
group
,
group
)
self
.
__a
()
try
:
r
=
self
.
_r
l
=
r
.
match
(
str
,
pos
)
if
l
<
0
:
return
None
return
l
,
apply
(
r
.
group
,
group
)
finally
:
self
.
__r
()
def
search_regs
(
self
,
str
,
pos
=
0
):
"""Search a string for a pattern.
...
...
@@ -135,9 +181,12 @@ class compile(Sync.Synchronized):
otherwise, the 'regs' attribute of the expression is
returned.
"""
r
=
self
.
_r
r
.
search
(
str
,
pos
)
return
r
.
regs
self
.
__a
()
try
:
r
=
self
.
_r
r
.
search
(
str
,
pos
)
return
r
.
regs
finally
:
self
.
__r
()
def
match_regs
(
self
,
str
,
pos
=
0
):
"""Match a pattern against a string
...
...
@@ -146,9 +195,12 @@ class compile(Sync.Synchronized):
returned, otherwise, the 'regs' attribute of the expression is
returned.
"""
r
=
self
.
_r
r
.
match
(
str
,
pos
)
return
r
.
regs
self
.
__a
()
try
:
r
=
self
.
_r
r
.
match
(
str
,
pos
)
return
r
.
regs
finally
:
self
.
__r
()
class
symcomp
(
compile
):
...
...
@@ -157,28 +209,6 @@ class symcomp(compile):
self
.
_init
(
r
)
self
.
groupindex
=
r
.
groupindex
try
:
import
thread
except
:
pass
else
:
class
SafeFunction
:
_l
=
thread
.
allocate_lock
()
_a
=
_l
.
acquire
_r
=
_l
.
release
def
__init__
(
self
,
f
):
self
.
_f
=
f
def
__call__
(
self
,
*
args
,
**
kw
):
self
.
_a
()
try
:
return
apply
(
self
.
_f
,
args
,
kw
)
finally
:
self
.
_r
()
split
=
SafeFunction
(
split
)
sub
=
SafeFunction
(
sub
)
gsub
=
SafeFunction
(
gsub
)
splitx
=
SafeFunction
(
splitx
)
capwords
=
SafeFunction
(
capwords
)
...
...
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