Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: Lib/mimetypes.py

Issue 20758: mimetypes initialization order
Patch Set: Created 6 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Guess the MIME type of a file. 1 """Guess the MIME type of a file.
2 2
3 This module defines two useful functions: 3 This module defines two useful functions:
4 4
5 guess_type(url, strict=True) -- guess the MIME type and encoding of a URL. 5 guess_type(url, strict=True) -- guess the MIME type and encoding of a URL.
6 6
7 guess_extension(type, strict=True) -- guess the extension for a given MIME type. 7 guess_extension(type, strict=True) -- guess the extension for a given MIME type.
8 8
9 It also contains the following, for tuning the behavior: 9 It also contains the following, for tuning the behavior:
10 10
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 ctype = _winreg.EnumKey(mimedb, i) 245 ctype = _winreg.EnumKey(mimedb, i)
246 except EnvironmentError: 246 except EnvironmentError:
247 break 247 break
248 else: 248 else:
249 yield ctype 249 yield ctype
250 i += 1 250 i += 1
251 251
252 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: 252 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
253 for subkeyname in enum_types(hkcr): 253 for subkeyname in enum_types(hkcr):
254 try: 254 try:
255 # Only check file extensions
256 if not subkeyname.startswith("."):
257 continue
255 with _winreg.OpenKey(hkcr, subkeyname) as subkey: 258 with _winreg.OpenKey(hkcr, subkeyname) as subkey:
256 # Only check file extensions
257 if not subkeyname.startswith("."):
258 continue
259 # raises EnvironmentError if no 'Content Type' value 259 # raises EnvironmentError if no 'Content Type' value
260 mimetype, datatype = _winreg.QueryValueEx( 260 mimetype, datatype = _winreg.QueryValueEx(
261 subkey, 'Content Type') 261 subkey, 'Content Type')
262 if datatype != _winreg.REG_SZ: 262 if datatype != _winreg.REG_SZ:
263 continue 263 continue
264 self.add_type(mimetype, subkeyname, strict) 264 self.add_type(mimetype, subkeyname, strict)
265 except EnvironmentError: 265 except EnvironmentError:
266 continue 266 continue
267 267
268 def guess_type(url, strict=True): 268 def guess_type(url, strict=True):
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 extension = 1 583 extension = 1
584 for gtype in args: 584 for gtype in args:
585 if extension: 585 if extension:
586 guess = guess_extension(gtype, strict) 586 guess = guess_extension(gtype, strict)
587 if not guess: print("I don't know anything about type", gtype) 587 if not guess: print("I don't know anything about type", gtype)
588 else: print(guess) 588 else: print(guess)
589 else: 589 else:
590 guess, encoding = guess_type(gtype, strict) 590 guess, encoding = guess_type(gtype, strict)
591 if not guess: print("I don't know anything about type", gtype) 591 if not guess: print("I don't know anything about type", gtype)
592 else: print('type:', guess, 'encoding:', encoding) 592 else: print('type:', guess, 'encoding:', encoding)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+