Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
3e6f4fdb
Commit
3e6f4fdb
authored
4 months ago
by
Raphaël Gomès
Browse files
Options
Downloads
Patches
Plain Diff
utils: create module with new string escaping functions
parent
da96b3d2
No related branches found
Branches containing commit
No related tags found
1 merge request
!37
general improvements
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python-libs/poulpe/scheduling.py
+1
-46
1 addition, 46 deletions
python-libs/poulpe/scheduling.py
python-libs/poulpe/utils.py
+48
-0
48 additions, 0 deletions
python-libs/poulpe/utils.py
with
49 additions
and
46 deletions
python-libs/poulpe/scheduling.py
+
1
−
46
View file @
3e6f4fdb
...
...
@@ -20,6 +20,7 @@
RETURN_CODE_SETUP_ISSUE
,
RETURN_CODE_SUCCESS
,
)
from
poulpe.utils
import
escape_string
,
split_unescape
def
generate_tasks
(
...
...
@@ -137,52 +138,6 @@
yield
kv
def
escape_string
(
s
:
str
,
chars
:
str
,
escape
:
chr
=
"
\\
"
)
->
str
:
"""
Escape all unescaped characters in `chars` with `escape`
"""
for
delim
in
chars
:
s
=
re
.
sub
(
rf
"
([^
{
delim
}
])
{
delim
}
"
,
rf
"
\g<1>
{
escape
}{
delim
}
"
,
s
)
return
s
def
split_unescape
(
s
:
str
,
delim
:
chr
,
escape
:
chr
=
"
\\
"
)
->
str
:
"""
Split a string along `delim`, only if not escaped by `escape`
>>>
split_unescape
(
'
foo,bar
'
,
'
,
'
)
[
'
foo
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo,bar
'
,
'
,
'
)
[
'
foo
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo$,ba$r
'
,
'
,
'
,
'
$
'
)
[
'
foo,ba$r
'
]
>>>
split_unescape
(
'
foo$$,bar
'
,
'
,
'
,
'
$
'
)
[
'
foo$
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo$
'
,
'
,
'
,
'
$
'
)
[
'
foo$
'
]
"""
ret
=
[]
current
=
[]
itr
=
iter
(
s
)
for
ch
in
itr
:
if
ch
==
escape
:
try
:
# skip the next character; it has been escaped!
next_char
=
next
(
itr
)
if
next_char
==
delim
:
current
.
append
(
next_char
)
else
:
current
.
append
(
escape
)
current
.
append
(
next_char
)
except
StopIteration
:
current
.
append
(
escape
)
elif
ch
==
delim
:
# split! (add current to the list and reset it)
ret
.
append
(
""
.
join
(
current
))
current
=
[]
else
:
current
.
append
(
ch
)
ret
.
append
(
""
.
join
(
current
))
return
ret
class
BinEnvSpec
:
@classmethod
def
from_piece
(
cls
,
piece
:
str
):
...
...
This diff is collapsed.
Click to expand it.
python-libs/poulpe/utils.py
0 → 100644
+
48
−
0
View file @
3e6f4fdb
# Useful common code
import
re
def
escape_string
(
s
:
str
,
chars
:
str
,
escape
:
chr
=
"
\\
"
)
->
str
:
"""
Escape all unescaped characters in `chars` with `escape`
"""
for
delim
in
chars
:
s
=
re
.
sub
(
rf
"
([^
{
delim
}
])
{
delim
}
"
,
rf
"
\g<1>
{
escape
}{
delim
}
"
,
s
)
return
s
def
split_unescape
(
s
:
str
,
delim
:
chr
,
escape
:
chr
=
"
\\
"
)
->
str
:
"""
Split a string along `delim`, only if not escaped by `escape`
>>>
split_unescape
(
'
foo,bar
'
,
'
,
'
)
[
'
foo
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo,bar
'
,
'
,
'
)
[
'
foo
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo$,ba$r
'
,
'
,
'
,
'
$
'
)
[
'
foo,ba$r
'
]
>>>
split_unescape
(
'
foo$$,bar
'
,
'
,
'
,
'
$
'
)
[
'
foo$
'
,
'
bar
'
]
>>>
split_unescape
(
'
foo$
'
,
'
,
'
,
'
$
'
)
[
'
foo$
'
]
"""
ret
=
[]
current
=
[]
itr
=
iter
(
s
)
for
ch
in
itr
:
if
ch
==
escape
:
try
:
# skip the next character; it has been escaped!
next_char
=
next
(
itr
)
if
next_char
==
delim
:
current
.
append
(
next_char
)
else
:
current
.
append
(
escape
)
current
.
append
(
next_char
)
except
StopIteration
:
current
.
append
(
escape
)
elif
ch
==
delim
:
# split! (add current to the list and reset it)
ret
.
append
(
""
.
join
(
current
))
current
=
[]
else
:
current
.
append
(
ch
)
ret
.
append
(
""
.
join
(
current
))
return
ret
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment