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

Side by Side Diff: Lib/mimetypes.py

Issue 22028: Python 3.4.1 Installer ended prematurely (Windows msi)
Patch Set: Created 4 years, 8 months 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return 239 return
240 240
241 def enum_types(mimedb): 241 def enum_types(mimedb):
242 i = 0 242 i = 0
243 while True: 243 while True:
244 try: 244 try:
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 if '\0' not in ctype:
250 yield ctype
250 i += 1 251 i += 1
251 252
252 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr: 253 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
253 for subkeyname in enum_types(hkcr): 254 for subkeyname in enum_types(hkcr):
254 try: 255 try:
255 with _winreg.OpenKey(hkcr, subkeyname) as subkey: 256 with _winreg.OpenKey(hkcr, subkeyname) as subkey:
256 # Only check file extensions 257 # Only check file extensions
257 if not subkeyname.startswith("."): 258 if not subkeyname.startswith("."):
258 continue 259 continue
259 # raises EnvironmentError if no 'Content Type' value 260 # raises EnvironmentError if no 'Content Type' value
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 extension = 1 584 extension = 1
584 for gtype in args: 585 for gtype in args:
585 if extension: 586 if extension:
586 guess = guess_extension(gtype, strict) 587 guess = guess_extension(gtype, strict)
587 if not guess: print("I don't know anything about type", gtype) 588 if not guess: print("I don't know anything about type", gtype)
588 else: print(guess) 589 else: print(guess)
589 else: 590 else:
590 guess, encoding = guess_type(gtype, strict) 591 guess, encoding = guess_type(gtype, strict)
591 if not guess: print("I don't know anything about type", gtype) 592 if not guess: print("I don't know anything about type", gtype)
592 else: print('type:', guess, 'encoding:', encoding) 593 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+