Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
erp5_rtl_support
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
Romain Courteaud
erp5_rtl_support
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
Show 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):
# + (111) 111-111/111 or + (111) 111-111/ or + (111) 111-111
"
\
+
(
?
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')
def fromText(self, coordinate_text):
""" See ICoordinate.fromText """
...
...
@@ -248,15 +250,14 @@ class Telephone(Coordinate, Base):
# This regexp get the coordinate text
# and extract number and letters
input_regex_without_markup = '[0-9A-Za-z]'
input_without_markup = ''.join(re.findall(input_regex_without_markup,
\
coordinate_text))
input_without_markup = ''.join(self.compiled_input_regex_without_markup.
\
findall(coordinate_text))
# Test if coordinate_text has or not markups.
if len(coordinate_text) > len(input_without_markup):
number_match = None
for regex in self._getRegexList():
possible_number_match = re
.match(regex,
coordinate_text)
if possible_number_match
not in [None]
:
possible_number_match = re
gex.match(
coordinate_text)
if possible_number_match
is not None
:
number_match = possible_number_match
number_dict = number_match.groupdict()
break
...
...
@@ -403,4 +404,4 @@ class Telephone(Coordinate, Base):
"""
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