Skip to content

Commit

Permalink
Tiny optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Sep 3, 2014
1 parent 47a4e74 commit 05f4bc1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions terms/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def del_other_occurrences(*args, **kwargs):
pass


def replace_terms(replace_dict, variants_dict, replace_regexp__sub, html):
def get_translate_function(replace_dict, variants_dict):
def translate(match):
before, name = match.group('before', 'name')

Expand All @@ -40,7 +40,7 @@ def translate(match):
else:
replaced_name = name
return before + replaced_name
return replace_regexp__sub(translate, html)
return translate


def is_ignored_parent(parent_tag):
Expand Down Expand Up @@ -69,10 +69,10 @@ def replace_in_html(html):
replace_dict = Term.objects.replace_dict()
replace_regexp = Term.objects.replace_regexp()
replace_regexp__sub = replace_regexp.sub
translate = get_translate_function(replace_dict, variants_dict)

for tag in get_interesting_contents(soup, replace_regexp):
new_tag = str_to_soup(replace_terms(
replace_dict, variants_dict, replace_regexp__sub, tag))
new_tag = str_to_soup(replace_regexp__sub(translate, tag))
tag.replace_with(new_tag)

return smart_text(soup)
Expand Down

0 comments on commit 05f4bc1

Please sign in to comment.