Commit 33637ce1 authored by Jim Fulton's avatar Jim Fulton

Fixes a serious bug in compile and syscomp. They were not mixing

in Sync.Synchronized, because Sync.Synchronized doesn't want to play
with __getattr__.

Also changed to allow correct execution on systems without threads.
parent 9d717ae3
......@@ -82,22 +82,27 @@
# attributions are listed in the accompanying credits file.
#
##############################################################################
import regex, regsub
"""Provide a thread-safe interface to regex
"""
import regex, regsub, Sync
from regex import *
from regsub import split, sub, gsub, splitx, capwords
try:
import thread, Sync
class compile:
class compile(Sync.Synchronized):
_r=None
groupindex=None
def __init__(self, *args):
self._r=r=apply(regex.compile,args)
self._init(r)
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 search_group(self, str, group, pos=0):
"""Search a string for a pattern.
......@@ -145,15 +150,17 @@ try:
r.match(str, pos)
return r.regs
def __getattr__(self, name): return getattr(self._r, name)
class symcomp(compile):
class symcomp(compile):
def __init__(self, *args):
self._r=r=apply(regex.symcomp,args)
self.search=r.search
self.match=r.match
self._init(r)
self.groupindex=r.groupindex
try:
import thread
except: pass
else:
class SafeFunction:
_l=thread.allocate_lock()
_a=_l.acquire
......@@ -173,7 +180,6 @@ try:
splitx=SafeFunction(splitx)
capwords=SafeFunction(capwords)
except: pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment