[Python-checkins] r72051 - in python/branches/release30-maint: Lib/mimetypes.py Misc/NEWS

antoine.pitrou python-checkins at python.org
Mon Apr 27 23:06:06 CEST 2009


Author: antoine.pitrou
Date: Mon Apr 27 23:06:06 2009
New Revision: 72051

Log:
Merged revisions 72050 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r72050 | antoine.pitrou | 2009-04-27 23:04:19 +0200 (lun., 27 avril 2009) | 11 lines
  
  Merged revisions 72045 via svnmerge from 
  svn+ssh://pythondev@svn.python.org/python/trunk
  
  ........
    r72045 | antoine.pitrou | 2009-04-27 22:50:20 +0200 (lun., 27 avril 2009) | 5 lines
    
    Issue #5853: calling a function of the mimetypes module from several threads
    at once could hit the recursion limit if the mimetypes database hadn't been
    initialized before.
  ........
................


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Lib/mimetypes.py
   python/branches/release30-maint/Misc/NEWS

Modified: python/branches/release30-maint/Lib/mimetypes.py
==============================================================================
--- python/branches/release30-maint/Lib/mimetypes.py	(original)
+++ python/branches/release30-maint/Lib/mimetypes.py	Mon Apr 27 23:06:06 2009
@@ -44,6 +44,7 @@
     ]
 
 inited = False
+_db = None
 
 
 class MimeTypes:
@@ -237,9 +238,9 @@
     Optional `strict' argument when false adds a bunch of commonly found, but
     non-standard types.
     """
-    if not inited:
+    if _db is None:
         init()
-    return guess_type(url, strict)
+    return _db.guess_type(url, strict)
 
 
 def guess_all_extensions(type, strict=True):
@@ -255,9 +256,9 @@
     Optional `strict' argument when false adds a bunch of commonly found,
     but non-standard types.
     """
-    if not inited:
+    if _db is None:
         init()
-    return guess_all_extensions(type, strict)
+    return _db.guess_all_extensions(type, strict)
 
 def guess_extension(type, strict=True):
     """Guess the extension for a file based on its MIME type.
@@ -271,9 +272,9 @@
     Optional `strict' argument when false adds a bunch of commonly found,
     but non-standard types.
     """
-    if not inited:
+    if _db is None:
         init()
-    return guess_extension(type, strict)
+    return _db.guess_extension(type, strict)
 
 def add_type(type, ext, strict=True):
     """Add a mapping between a type and an extension.
@@ -287,16 +288,15 @@
     list of standard types, else to the list of non-standard
     types.
     """
-    if not inited:
+    if _db is None:
         init()
-    return add_type(type, ext, strict)
+    return _db.add_type(type, ext, strict)
 
 
 def init(files=None):
-    global guess_all_extensions, guess_extension, guess_type
     global suffix_map, types_map, encodings_map, common_types
-    global add_type, inited
-    inited = True
+    global inited, _db
+    inited = True    # so that MimeTypes.__init__() doesn't call us again
     db = MimeTypes()
     if files is None:
         files = knownfiles
@@ -306,11 +306,9 @@
     encodings_map = db.encodings_map
     suffix_map = db.suffix_map
     types_map = db.types_map[True]
-    guess_all_extensions = db.guess_all_extensions
-    guess_extension = db.guess_extension
-    guess_type = db.guess_type
-    add_type = db.add_type
     common_types = db.types_map[False]
+    # Make the DB a global variable now that it is fully initialized
+    _db = db
 
 
 def read_mime_types(file):

Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS	(original)
+++ python/branches/release30-maint/Misc/NEWS	Mon Apr 27 23:06:06 2009
@@ -42,6 +42,10 @@
 Library
 -------
 
+- Issue #5853: calling a function of the mimetypes module from several threads
+  at once could hit the recursion limit if the mimetypes database hadn't been
+  initialized before.
+
 - Issue 5830:  The sched module no longer raises a TypeError when
   prioritizing Events with the same time and priority.
 


More information about the Python-checkins mailing list