Skip to content

Commit

Permalink
fixed one edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
benlindsay committed Jan 22, 2018
1 parent 4ec2e47 commit 21768a6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion create_jobs/create_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,23 @@ def _replace_vars(text, param_dict):
>>> _replace_vars('{last}, {first} {last}', {'last':'Bond'})
'Bond, {first} Bond'
"""
return string.Formatter().vformat(text, (), _Safe_Dict(param_dict))
# Handle the edge case where a '{}' in text breaks things.
if '{}' in text:
text = text.replace('{}', '__dummy__')
contains_empty_brackets = True
else:
contains_empty_brackets = False

# TODO: Handle case where there are invalid characters inside brackets

# Run the string formatter
text = string.Formatter().vformat(text, (), _Safe_Dict(param_dict))

# Put empty brackets back in if they were there originally
if contains_empty_brackets:
text = text.replace('__dummy__', '{}')

return text

class _Safe_Dict(dict):
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
setup(
name = 'create_jobs',
packages = ['create_jobs'],
version = '0.0.9',
version = '0.0.10',
description = desc,
long_description = long_desc,
requires = ['numpy', 'pandas'],
Expand Down

0 comments on commit 21768a6

Please sign in to comment.