Python mimetypes.add_type














































Python mimetypes.add_type



add_type()



mimetypes.add_type(typeextstrict=True)


Add a mapping from the MIME type 'type' to the extension 'ext'. When the extension is already known, the new type will replace the old one. 

Similarly, when the type is already known the extension will be added to the list of known extensions.


NOTE: The strict argument is a flag specifying whether the list of known MIME types is limited to only the official types registered with IANA and is optional. When strict is True (the default), the mapping will be added to the official MIME types, otherwise to the non-standard ones.




An example usage:


import mimetypes
print(mimetypes.add_type("my/website", ".com")
print(mimetypes.guess_type("cppsecrets.com"))

('my/website', None)

print(mimetypes.guess_extension("my/website"))

.com


#Here, 'my/website' is added as a type with extension '.com' without any strict argument (as strict argument is optional).

Then type of the file is guessed for the given file "cppsecrets.com"



 NOTE: Green Box shows the Outputs for the LOC(Line Of Code) above it


<-PREV                                                                                                                                                NEXT->



More Articles of Shubhanjay Pandey:

Name Views Likes
Python ssl Sockets 998 3
Python unittest.mock side_effect 503 2
Python ssl Example Server Side Operation 771 3
Python unittest.mock method_calls and mock_calls 841 2
Python ssl TLS 1.3 and LibreSSL Support 1450 2
Python unittest.mock The patchers 310 2
Python unittest.mock Attaching Mocks as Attributes 433 2
Python ssl Example Client Side Operations 463 3
Python unittest.mock patch.object and patch.dict 2748 2
Python unittest.mock.call_args and call_args_list 3283 2
Python ssl Certificates 321 3
Python unittest.mock Deleting, Mock Names and the name attribute 517 2
Python unittest.mock FILTER_DIR 254 2
Python ssl Introduction 286 3
Python unitest.mock Where to patch, patching descriptors and proxy objects 268 2
Python ssl Memory BIO Support 539 3
Python mimetypes - Introduction 333 3
Python unittest.mock Helpers call 282 2
Python unittest.mock function assert_*() 283 2
Python unittest.mock Introduction 340 2
Python sunau library 305 2
Python unittest.mock The Mock Class 275 2
Python ssl Constants Part 1 357 3
Python mimetypes.add_type 257 4
Python ssl Socket and Context Creation 1300 3
Python unittest.mock.mock_open 297 2
Python ssl non-blocking sockets 646 3
Python unittest.mock MagicMock and magic method support 847 1
Python unittest.mock Magic Mock 370 2
Python ssl Exceptions 307 3
Python unittest.mock TEST_PREFIX and Nesting Patch Decorators 395 2
Python unittest.mock patch.multiple and builtins 2017 2
Python mimetypes additional data 232 3
Python unittest.mock Other HELPERS 252 2
Python MimeTypes Object 267 3
Python mimetypes.guess_type 331 3
Python unittest.mock Autospeccing 304 2
Python unittest.mock.AsyncMock 2440 2
Python ssl Certificates Handling 375 3
Python ssl Random Generation 290 3
Python unittest.mock Function configure_mock 385 2
Python ssl SSLContexts Part 1 618 3
Python unittest.mock patch methods: start and stop 1693 2
Python unittest.mock Calling 271 2
Python unittest.mock other functions 268 2
Python ssl Constants Part 2 430 3
Python ssl SSLContexts Part 2 764 3
Python ssl Security Considerations and SSL Session 416 3
Python mimetypes.guess_extension 313 3
Python unittest.mock PropertyMock and NonCallableMock 787 2
Python mimetypes additional functions 253 3

Comments