Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lettuce
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
lettuce
Commits
2c929ad0
Commit
2c929ad0
authored
Sep 17, 2012
by
Gabriel Falcao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
compiling some regexes once and reusing later
parent
4a78b0b5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
14 deletions
+21
-14
lettuce/core.py
+21
-14
No files found.
lettuce/core.py
View file @
2c929ad0
...
@@ -34,6 +34,18 @@ from lettuce.exceptions import LettuceSyntaxError
...
@@ -34,6 +34,18 @@ from lettuce.exceptions import LettuceSyntaxError
fs
=
FileSystem
()
fs
=
FileSystem
()
class
REP
(
object
):
"RegEx Pattern"
first_of
=
re
.
compile
(
ur'^first_of_'
)
last_of
=
re
.
compile
(
ur'^last_of_'
)
language
=
re
.
compile
(
u"language:[ ]*([^
\
s]+)"
)
within_double_quotes
=
re
.
compile
(
r'("[^"]+")'
)
within_single_quotes
=
re
.
compile
(
r"('[^']+')"
)
only_whitespace
=
re
.
compile
(
'^
\
s*$'
)
tag_extraction_regex
=
re
.
compile
(
r'(?:(?:^|\s+)[@]([^@\s]+))'
)
tag_strip_regex
=
re
.
compile
(
ur'(?:(?:^\s*|\s+)[@]\S+\s*)+$'
,
re
.
DOTALL
)
class
HashList
(
list
):
class
HashList
(
list
):
__base_msg
=
'The step "
%
s" have no table defined, so '
\
__base_msg
=
'The step "
%
s" have no table defined, so '
\
'that you can
\'
t use step.hashes.
%
s'
'that you can
\'
t use step.hashes.
%
s'
...
@@ -86,9 +98,9 @@ class Language(object):
...
@@ -86,9 +98,9 @@ class Language(object):
return
'<Language "
%
s">'
%
self
.
code
return
'<Language "
%
s">'
%
self
.
code
def
__getattr__
(
self
,
attr
):
def
__getattr__
(
self
,
attr
):
for
pattern
in
[
ur'^first_of_'
,
ur'^last_of'
]:
for
pattern
in
[
REP
.
first_of
,
REP
.
last_of
]:
if
re
.
match
(
pattern
,
attr
):
if
pattern
.
match
(
attr
):
name
=
re
.
sub
(
pattern
,
u''
,
attr
)
name
=
pattern
.
sub
(
u''
,
attr
)
return
unicode
(
getattr
(
self
,
name
,
u''
)
.
split
(
u"|"
)[
0
])
return
unicode
(
getattr
(
self
,
name
,
u''
)
.
split
(
u"|"
)[
0
])
return
super
(
Language
,
self
)
.
__getattribute__
(
attr
)
return
super
(
Language
,
self
)
.
__getattribute__
(
attr
)
...
@@ -99,7 +111,7 @@ class Language(object):
...
@@ -99,7 +111,7 @@ class Language(object):
@classmethod
@classmethod
def
guess_from_string
(
cls
,
string
):
def
guess_from_string
(
cls
,
string
):
match
=
re
.
search
(
u"language:[ ]*([^
\
s]+)"
,
string
)
match
=
re
.
search
(
REP
.
language
,
string
)
if
match
:
if
match
:
instance
=
cls
(
match
.
group
(
1
))
instance
=
cls
(
match
.
group
(
1
))
else
:
else
:
...
@@ -209,8 +221,8 @@ class Step(object):
...
@@ -209,8 +221,8 @@ class Step(object):
method_name
=
sentence
method_name
=
sentence
groups
=
[
groups
=
[
(
'"'
,
re
.
compile
(
r'("[^"]+")'
)
,
r'"([^"]*)"'
),
(
'"'
,
REP
.
within_double_quotes
,
r'"([^"]*)"'
),
(
"'"
,
re
.
compile
(
r"('[^']+')"
)
,
r"\'([^\']*)\'"
),
(
"'"
,
REP
.
within_single_quotes
,
r"\'([^\']*)\'"
),
]
]
attribute_names
=
[]
attribute_names
=
[]
...
@@ -457,8 +469,7 @@ class Step(object):
...
@@ -457,8 +469,7 @@ class Step(object):
invalid_first_line_error
%
(
lines
[
0
],
'multiline'
))
invalid_first_line_error
%
(
lines
[
0
],
'multiline'
))
# Select only lines that aren't end-to-end whitespace
# Select only lines that aren't end-to-end whitespace
only_whitspace
=
re
.
compile
(
'^
\
s*$'
)
lines
=
filter
(
lambda
x
:
not
REP
.
only_whitespace
.
match
(
x
),
lines
)
lines
=
filter
(
lambda
x
:
not
only_whitspace
.
match
(
x
),
lines
)
step_strings
=
[]
step_strings
=
[]
in_multiline
=
False
in_multiline
=
False
...
@@ -724,9 +735,7 @@ class Scenario(object):
...
@@ -724,9 +735,7 @@ class Scenario(object):
return
[]
return
[]
def
_extract_tag
(
self
,
item
):
def
_extract_tag
(
self
,
item
):
regex
=
re
.
compile
(
r'(?:(?:^|\s+)[@]([^@\s]+))'
)
return
REP
.
tag_extraction_regex
.
findall
(
item
)
found
=
regex
.
findall
(
item
)
return
found
def
_resolve_steps
(
self
,
steps
,
outlines
,
with_file
,
original_string
):
def
_resolve_steps
(
self
,
steps
,
outlines
,
with_file
,
original_string
):
for
outline
in
outlines
:
for
outline
in
outlines
:
...
@@ -937,9 +946,7 @@ class Feature(object):
...
@@ -937,9 +946,7 @@ class Feature(object):
self
.
described_at
=
definition
self
.
described_at
=
definition
def
_strip_next_scenario_tags
(
self
,
string
):
def
_strip_next_scenario_tags
(
self
,
string
):
regex
=
re
.
compile
(
ur'(?:(?:^\s*|\s+)[@]\S+\s*)+$'
,
re
.
DOTALL
)
stripped
=
REP
.
tag_strip_regex
.
sub
(
''
,
string
)
stripped
=
regex
.
sub
(
''
,
string
)
return
stripped
return
stripped
def
_parse_remaining_lines
(
self
,
lines
,
original_string
,
with_file
=
None
):
def
_parse_remaining_lines
(
self
,
lines
,
original_string
,
with_file
=
None
):
...
...
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