Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a783d06f
Commit
a783d06f
authored
Sep 15, 2005
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clear out the regex cache when the TimeRE cache is invalidated by a locale
change. Fixes bug #1290505.
parent
fb1ef85b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
1 deletion
+6
-1
Lib/_strptime.py
Lib/_strptime.py
+2
-1
Lib/test/test_strptime.py
Lib/test/test_strptime.py
+2
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/_strptime.py
View file @
a783d06f
...
...
@@ -275,13 +275,14 @@ _regex_cache = {}
def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the format string."""
global _TimeRE_cache
global _TimeRE_cache
, _regex_cache
_cache_lock.acquire()
try:
time_re = _TimeRE_cache
locale_time = time_re.locale_time
if _getlang() != locale_time.lang:
_TimeRE_cache = TimeRE()
_regex_cache = {}
if len(_regex_cache) > _CACHE_MAX_SIZE:
_regex_cache.clear()
format_regex = _regex_cache.get(format)
...
...
Lib/test/test_strptime.py
View file @
a783d06f
...
...
@@ -462,10 +462,12 @@ class CacheTests(unittest.TestCase):
# Make sure cache is recreated when current locale does not match what
# cached object was created with.
_strptime.strptime("
10
", "
%
d
")
_strptime.strptime("
2005
", "
%
Y
")
_strptime._TimeRE_cache.locale_time.lang = "
Ni
"
original_time_re = id(_strptime._TimeRE_cache)
_strptime.strptime("
10
", "
%
d
")
self.failIfEqual(original_time_re, id(_strptime._TimeRE_cache))
self.failUnlessEqual(len(_strptime._regex_cache), 1)
def test_regex_cleanup(self):
# Make sure cached regexes are discarded when cache becomes "
full
".
...
...
Misc/NEWS
View file @
a783d06f
...
...
@@ -217,6 +217,8 @@ Extension Modules
Library
-------
-
Bug
#
1290505
:
Fix
clearing
the
regex
cache
for
time
.
strptime
().
-
Bug
#
1167128
:
Fix
size
of
a
symlink
in
a
tarfile
to
be
0.
-
Patch
#
810023
:
Fix
off
-
by
-
one
bug
in
urllib
.
urlretrieve
reporthook
...
...
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