Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimetypes on Windows should read MIME database from registry (w/patch) #49219

Closed
ggenellina mannequin opened this issue Jan 17, 2009 · 6 comments
Closed

mimetypes on Windows should read MIME database from registry (w/patch) #49219

ggenellina mannequin opened this issue Jan 17, 2009 · 6 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ggenellina
Copy link
Mannequin

ggenellina mannequin commented Jan 17, 2009

BPO 4969
Nosy @pitrou
Files
  • mimetypes.diff: Version 2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-11-15.14:26:22.545>
    created_at = <Date 2009-01-17.08:58:40.600>
    labels = ['type-feature', 'library']
    title = 'mimetypes on Windows should read MIME database from registry (w/patch)'
    updated_at = <Date 2013-03-23.12:05:36.049>
    user = 'https://bugs.python.org/ggenellina'

    bugs.python.org fields:

    activity = <Date 2013-03-23.12:05:36.049>
    actor = 'fhamand'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-11-15.14:26:22.545>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2009-01-17.08:58:40.600>
    creator = 'ggenellina'
    dependencies = []
    files = ['15338']
    hgrepos = []
    issue_num = 4969
    keywords = ['patch']
    message_count = 6.0
    messages = ['80007', '94875', '95279', '95291', '95294', '185039']
    nosy_count = 5.0
    nosy_names = ['ggenellina', 'pitrou', 'ocean-city', 'tercero12', 'fhamand']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4969'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @ggenellina
    Copy link
    Mannequin Author

    ggenellina mannequin commented Jan 17, 2009

    The mimetypes module has a built-in default database, and, in addition,
    reads mime.types files from a list of standard places (/etc/mime.types
    by example)
    On Windows, those files usually don't even present; MIME information is
    stored in the registry instead. Until now, the mimetypes module just
    ignored those settings; this patch adds support for reading the MIME
    database from the Windows registry.

    @ggenellina ggenellina mannequin added the stdlib Python modules in the Lib dir label Jan 17, 2009
    @pitrou
    Copy link
    Member

    pitrou commented Nov 4, 2009

    A couple of points:

    • if the method is Windows-specific, I don't think it shouldn't bear a
      name as generic as "read_registry()". There are "registries" on other
      systems.
    • the method should probably raise early on non-Windows systems (raise
      NotImplementedError?)
    • please fix the coding style; don't collapse a "try", "except" or
      "finally" and the following statement on a single line
    • in the tests, rather than defining an empty test case on non-Windows
      systems, make the tests skip (for example, call self.skipTest()

    @pitrou pitrou added the type-feature A feature request or enhancement label Nov 4, 2009
    @ggenellina
    Copy link
    Mannequin Author

    ggenellina mannequin commented Nov 15, 2009

    A new patch taking into account M. Pitrou comments:

    • name changed to read_windows_registry()
    • read_windows_registry() does nothing on non-Windows platforms; same
      as read_mime_types(filename) when the file does not exist.
    • I hope the coding style is acceptable now
    • the test is skipped on non-Windows platforms
    • documentation updated
    • documentation for MimeTypes.guess_all_extensions was missing; I
      added it although it isn't directly related to this issue.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 15, 2009

    Thank you, the patch looks ok to me.

    @pitrou
    Copy link
    Member

    pitrou commented Nov 15, 2009

    Committed in r76306 and r76307, closing.

    @pitrou pitrou closed this as completed Nov 15, 2009
    @fhamand
    Copy link
    Mannequin

    fhamand mannequin commented Mar 23, 2013

    From msg172531 in bpo-10551:

    "You see, "MIME\Database\Content Type" in the Windows registry is a mime type -> file extension mapping, *not the other way around*. But read_windows_registry() tries to use it as a file extension -> mime type mapping, and bad things happen, because there are multiple mime types for certain file extensions."

    This "enhancement" has basically broken the mimetypes module on windows,

    e.g. On my system (windows 7 64 bit, python 3.3)
    >>> mimetypes.guess_type('foo.png')
    ('image/x-png', None)
    >>> mimetypes.guess_type('foo.jpg')
    ('image/pjpeg', None)

    The expected results are image/png and image/jpeg

    I'm having to work around this by calling mimetypes.init(files=[]) immediately after importing mimetypes to prevent it reading from the registry

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant