Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Lu Xu
erp5
Commits
d34575ad
Commit
d34575ad
authored
Jun 17, 2011
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compile regex only once to improve performances
parent
949917dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
product/ERP5/Document/Telephone.py
product/ERP5/Document/Telephone.py
+7
-6
No files found.
product/ERP5/Document/Telephone.py
View file @
d34575ad
...
@@ -232,7 +232,9 @@ class Telephone(Coordinate, Base):
...
@@ -232,7 +232,9 @@ class Telephone(Coordinate, Base):
# + (111) 111-111/111 or + (111) 111-111/ or + (111) 111-111
# + (111) 111-111/111 or + (111) 111-111/ or + (111) 111-111
"
\
+
(
?
P
<
spaces
>
[
\
]
*
)
\
((
?
P
<
country
>
\
d
+
)
\
)
\
(
?
P
<
number
>
[
\
d
\ \
-
\
.]
*
)(
?
:
\
/
)
?
(
?
P
<
ext
>
\
d
+|
)
"
"
\
+
(
?
P
<
spaces
>
[
\
]
*
)
\
((
?
P
<
country
>
\
d
+
)
\
)
\
(
?
P
<
number
>
[
\
d
\ \
-
\
.]
*
)(
?
:
\
/
)
?
(
?
P
<
ext
>
\
d
+|
)
"
]
]
compiled_regex_list = [re.compile(pattern) for pattern in regex_list]
compiled_input_regex_without_markup = re.compile('[0-9A-Za-z]')
security.declareProtected(Permissions.ModifyPortalContent, 'fromText')
security.declareProtected(Permissions.ModifyPortalContent, 'fromText')
def fromText(self, coordinate_text):
def fromText(self, coordinate_text):
""" See ICoordinate.fromText """
""" See ICoordinate.fromText """
...
@@ -248,15 +250,14 @@ class Telephone(Coordinate, Base):
...
@@ -248,15 +250,14 @@ class Telephone(Coordinate, Base):
# This regexp get the coordinate text
# This regexp get the coordinate text
# and extract number and letters
# and extract number and letters
input_regex_without_markup = '[0-9A-Za-z]'
input_without_markup = ''.join(self.compiled_input_regex_without_markup.
\
input_without_markup = ''.join(re.findall(input_regex_without_markup,
\
findall(coordinate_text))
coordinate_text))
# Test if coordinate_text has or not markups.
# Test if coordinate_text has or not markups.
if len(coordinate_text) > len(input_without_markup):
if len(coordinate_text) > len(input_without_markup):
number_match = None
number_match = None
for regex in self._getRegexList():
for regex in self._getRegexList():
possible_number_match = re
.match(regex,
coordinate_text)
possible_number_match = re
gex.match(
coordinate_text)
if possible_number_match
not in [None]
:
if possible_number_match
is not None
:
number_match = possible_number_match
number_match = possible_number_match
number_dict = number_match.groupdict()
number_dict = number_match.groupdict()
break
break
...
@@ -403,4 +404,4 @@ class Telephone(Coordinate, Base):
...
@@ -403,4 +404,4 @@ class Telephone(Coordinate, Base):
"""
"""
Returns the regex list that will be used by fromText method.
Returns the regex list that will be used by fromText method.
"""
"""
return self.regex_list
return self.
compiled_
regex_list
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