Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import sys
import encodings
import encodings.aliases
import re
import _collections_abc
from builtins import str as _builtin_str
import functools
Expand Down Expand Up @@ -177,9 +176,6 @@ def _strip_padding(s, amount):
amount -= 1
return s[lpos:rpos+1]

_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')

def _format(percent, value, grouping=False, monetary=False, *additional):
if additional:
formatted = percent % ((value,) + additional)
Expand Down Expand Up @@ -217,6 +213,11 @@ def format_string(f, val, grouping=False, monetary=False):
Grouping is applied if the third parameter is true.
Conversion uses monetary thousands separator and grouping strings if
forth parameter monetary is true."""
import re

_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?(?P<modifiers'
r'>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')

percents = list(_percent_re.finditer(f))
new_f = _percent_re.sub('%s', f)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve import time of :mod:`locale` using lazy import ``re``. Patch by
Semyon Moroz.
Loading