Pelokalan
Python ID · library__mimetypes.po Bahasa Indonesia
id en
Sign in
Project
History
Text
PO Module
All ▾
This file was deleted by Rezha Julio 3 h ago. Its content, history and discussions stay readable, but cannot be changed.
Source text — English
Translation — Bahasa Indonesia
:mod:`!mimetypes` --- Map filenames to MIME types
:mod:`!mimetypes` --- Memetakan nama berkas ke tipe MIME
**Source code:** :source:`Lib/mimetypes.py`
**Kode sumber:** :source:`Lib/mimetypes.py`
The :mod:`!mimetypes` module converts between a filename or URL and the MIME type associated with the filename extension. Conversions are provided from filename to MIME type and from MIME type to filename extension; encodings are not supported for the latter conversion.
Modul :mod:`!mimetypes` mengubah nama berkas atau URL menjadi tipe MIME yang terkait dengan ekstensi nama berkas, dan sebaliknya. Konversi disediakan dari nama berkas ke tipe MIME dan dari tipe MIME ke ekstensi nama berkas; pengodean tidak didukung untuk konversi yang kedua.
The module provides one class and a number of convenience functions. The functions are the normal interface to this module, but some applications may be interested in the class as well.
Modul ini menyediakan satu kelas dan sejumlah fungsi praktis. Fungsi-fungsi tersebut merupakan antarmuka normal modul ini, tetapi beberapa aplikasi mungkin juga tertarik pada kelasnya.
The functions described below provide the primary interface for this module. If the module has not been initialized, they will call :func:`init` if they rely on the information :func:`init` sets up.
Fungsi-fungsi yang dijelaskan di bawah ini menyediakan antarmuka utama modul ini. Jika modul belum diinisialisasi, fungsi-fungsi tersebut akan memanggil :func:`init` bila bergantung pada informasi yang disiapkan :func:`init`.
Guess the type of a file based on its filename, path or URL, given by *url*. URL can be a string or a :term:`path-like object`.
Tebak tipe sebuah berkas berdasarkan nama berkas, path, atau URL-nya, yang diberikan melalui *url*. URL dapat berupa string atau :term:`path-like object`.
The return value is a tuple ``(type, encoding)`` where *type* is ``None`` if the type can't be guessed (missing or unknown suffix) or a string of the form ``'type/subtype'``, usable for a MIME :mailheader:`content-type` header.
Nilai kembaliannya adalah tuple ``(type, encoding)`` dengan *type* bernilai ``None`` jika tipenya tidak dapat ditebak (sufiks hilang atau tidak dikenal) atau berupa string dengan bentuk ``'type/subtype'``, yang dapat dipakai untuk header :mailheader:`content-type` MIME.
*encoding* is ``None`` for no encoding or the name of the program used to encode (e.g. :program:`compress` or :program:`gzip`). The encoding is suitable for use as a :mailheader:`Content-Encoding` header, **not** as a :mailheader:`Content-Transfer-Encoding` header. The mappings are table driven. Encoding suffixes are case sensitive; type suffixes are first tried case sensitively, then case insensitively.
*encoding* bernilai ``None`` jika tidak ada pengodean, atau berupa nama program yang digunakan untuk mengodekan (misalnya :program:`compress` atau :program:`gzip`). Pengodean tersebut cocok dipakai sebagai header :mailheader:`Content-Encoding`, **bukan** sebagai header :mailheader:`Content-Transfer-Encoding`. Pemetaannya berbasis tabel. Sufiks pengodean bersifat peka huruf besar-kecil; sufiks tipe pertama-tama dicoba secara peka huruf besar-kecil, lalu secara tidak peka huruf besar-kecil.
The optional *strict* argument is a flag specifying whether the list of known MIME types is limited to only the official types `registered with IANA <https://www.iana.org/assignments/media-types/media-types.xhtml>`_. However, the behavior of this module also depends on the underlying operating system. Only file types recognized by the OS or explicitly registered with Python's internal database can be identified. When *strict* is ``True`` (the default), only the IANA types are supported; when *strict* is ``False``, some additional non-standard but commonly used MIME types are also recognized.
Argumen opsional *strict* adalah flag yang menentukan apakah daftar tipe MIME yang dikenal dibatasi hanya pada tipe-tipe resmi yang `terdaftar di IANA <https://www.iana.org/assignments/media-types/media-types.xhtml>`_. Namun, perilaku modul ini juga bergantung pada sistem operasi yang mendasarinya. Hanya tipe berkas yang dikenali OS atau yang secara eksplisit didaftarkan ke basis data internal Python yang dapat diidentifikasi. Ketika *strict* bernilai ``True`` (default-nya), hanya tipe-tipe IANA yang didukung; ketika *strict* bernilai ``False``, beberapa tipe MIME nonstandar tambahan yang umum digunakan juga dikenali.
Added support for *url* being a :term:`path-like object`.
Menambahkan dukungan untuk *url* yang berupa :term:`path-like object`.💬 2
Passing a file path instead of URL. Use :func:`guess_file_type` for this.
Meneruskan path berkas, bukan URL. Gunakan :func:`guess_file_type` untuk keperluan ini.
Guess the type of a file based on its path, given by *path*. Similar to the :func:`guess_type` function, but accepts a path instead of URL. Path can be a string, a bytes object or a :term:`path-like object`.
Tebak tipe sebuah berkas berdasarkan path-nya, yang diberikan melalui *path*. Mirip dengan fungsi :func:`guess_type`, tetapi menerima path, bukan URL. Path dapat berupa string, objek bytes, atau :term:`path-like object`.
Guess the extensions for a file based on its MIME type, given by *type*. The return value is a list of strings giving all possible filename extensions, including the leading dot (``'.'``). The extensions are not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type *type* by :func:`guess_type` and :func:`guess_file_type`.
Tebak ekstensi-ekstensi sebuah berkas berdasarkan tipe MIME-nya, yang diberikan melalui *type*. Nilai kembaliannya adalah daftar string yang berisi semua kemungkinan ekstensi nama berkas, termasuk titik di awal (``'.'``). Ekstensi-ekstensi tersebut tidak dijamin pernah dikaitkan dengan aliran data tertentu, tetapi akan dipetakan ke tipe MIME *type* oleh :func:`guess_type` dan :func:`guess_file_type`.
The optional *strict* argument has the same meaning as with the :func:`guess_type` function.
Argumen opsional *strict* memiliki arti yang sama seperti pada fungsi :func:`guess_type`.
Guess the extension for a file based on its MIME type, given by *type*. The return value is a string giving a filename extension, including the leading dot (``'.'``). The extension is not guaranteed to have been associated with any particular data stream, but would be mapped to the MIME type *type* by :func:`guess_type` and :func:`guess_file_type`. If no extension can be guessed for *type*, ``None`` is returned.
Tebak ekstensi sebuah berkas berdasarkan tipe MIME-nya, yang diberikan melalui *type*. Nilai kembaliannya adalah string yang berisi ekstensi nama berkas, termasuk titik di awal (``'.'``). Ekstensi tersebut tidak dijamin pernah dikaitkan dengan aliran data tertentu, tetapi akan dipetakan ke tipe MIME *type* oleh :func:`guess_type` dan :func:`guess_file_type`. Jika tidak ada ekstensi yang dapat ditebak untuk *type*, ``None`` dikembalikan.
Some additional functions and data items are available for controlling the behavior of the module.
Beberapa fungsi dan item data tambahan tersedia untuk mengendalikan perilaku modul.
Initialize the internal data structures. If given, *files* must be a sequence of file names which should be used to augment the default type map. If omitted, the file names to use are taken from :const:`knownfiles`; on Windows, the current registry settings are loaded. Each file named in *files* or :const:`knownfiles` takes precedence over those named before it. Calling :func:`init` repeatedly is allowed.
Inisialisasi struktur data internal. Jika diberikan, *files* harus berupa urutan nama berkas yang dipakai untuk menambah peta tipe default. Jika dihilangkan, nama-nama berkas yang dipakai diambil dari :const:`knownfiles`; di Windows, pengaturan registri saat ini dimuat. Setiap berkas yang disebutkan dalam *files* atau :const:`knownfiles` didahulukan atas berkas-berkas yang disebutkan sebelumnya. Memanggil :func:`init` berulang kali diperbolehkan.
Specifying an empty list for *files* will prevent the system defaults from being applied: only the well-known values will be present from a built-in list.
Menentukan daftar kosong untuk *files* akan mencegah penerapan default sistem: hanya nilai-nilai yang umum dikenal yang akan ada, dari daftar bawaan.
If *files* is ``None`` the internal data structure is completely rebuilt to its initial default value. This is a stable operation and will produce the same results when called multiple times.
Jika *files* bernilai ``None``, struktur data internal dibangun ulang sepenuhnya ke nilai default awalnya. Operasi ini stabil dan akan memberikan hasil yang sama saat dipanggil berkali-kali.
Previously, Windows registry settings were ignored.
Sebelumnya, pengaturan registri Windows diabaikan.
Load the type map given in the file named by *file*, if it exists. *file* must be a string specifying the name of the file to read. The type map is returned as a dictionary mapping file extensions, including the leading dot (``'.'``), to strings of the form ``'type/subtype'``. If the file does not exist or cannot be read, ``None`` is returned.
Muat peta tipe yang ada dalam berkas bernama *file*, jika berkas tersebut ada. *file* harus berupa string yang menentukan nama berkas yang akan dibaca. Peta tipe dikembalikan sebagai dictionary yang memetakan ekstensi berkas, termasuk titik di awal (``'.'``), ke string dengan bentuk ``'type/subtype'``. Jika berkas tidak ada atau tidak dapat dibaca, ``None`` dikembalikan.
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. When the type is already known the extension will be added to the list of known extensions.
Tambahkan pemetaan dari tipe MIME *type* ke ekstensi *ext*. Ketika ekstensi sudah dikenal, tipe yang baru akan menggantikan yang lama. Ketika tipe sudah dikenal, ekstensi akan ditambahkan ke daftar ekstensi yang dikenal.
When *strict* is ``True`` (the default), the mapping will be added to the official MIME types, otherwise to the non-standard ones.
Ketika *strict* bernilai ``True`` (default-nya), pemetaan akan ditambahkan ke tipe-tipe MIME resmi, jika tidak, ke tipe-tipe nonstandar.
Flag indicating whether or not the global data structures have been initialized. This is set to ``True`` by :func:`init`.
Flag yang menunjukkan apakah struktur data global sudah diinisialisasi atau belum. Flag ini diatur ke ``True`` oleh :func:`init`.
List of type map file names commonly installed. These files are typically named :file:`mime.types` and are installed in different locations by different packages.
Daftar nama berkas peta tipe yang umumnya terpasang. Berkas-berkas ini biasanya bernama :file:`mime.types` dan dipasang di lokasi yang berbeda oleh paket yang berbeda.
Dictionary mapping suffixes to suffixes. This is used to allow recognition of encoded files for which the encoding and the type are indicated by the same extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz` to allow the encoding and type to be recognized separately.
Dictionary yang memetakan sufiks ke sufiks. Dictionary ini dipakai agar berkas-berkas yang terkodekan dapat dikenali, ketika pengodean dan tipenya ditunjukkan oleh ekstensi yang sama. Misalnya, ekstensi :file:`.tgz` dipetakan ke :file:`.tar.gz` agar pengodean dan tipenya dapat dikenali secara terpisah.
Dictionary mapping filename extensions to encoding types.
Dictionary yang memetakan ekstensi nama berkas ke tipe pengodean.
Dictionary mapping filename extensions to MIME types.
Dictionary yang memetakan ekstensi nama berkas ke tipe MIME.
Dictionary mapping filename extensions to non-standard, but commonly found MIME types.
Dictionary yang memetakan ekstensi nama berkas ke tipe MIME nonstandar, tetapi umum ditemukan.
An example usage of the module::
Contoh penggunaan modul::
>>> import mimetypes >>> mimetypes.init() >>> mimetypes.knownfiles ['/etc/mime.types', '/etc/httpd/mime.types', ... ] >>> mimetypes.suffix_map['.tgz'] '.tar.gz' >>> mimetypes.encodings_map['.gz'] 'gzip' >>> mimetypes.types_map['.tgz'] 'application/x-tar-gz'
>>> import mimetypes >>> mimetypes.init() >>> mimetypes.knownfiles ['/etc/mime.types', '/etc/httpd/mime.types', ... ] >>> mimetypes.suffix_map['.tgz'] '.tar.gz' >>> mimetypes.encodings_map['.gz'] 'gzip' >>> mimetypes.types_map['.tgz'] 'application/x-tar-gz'
MimeTypes objects
Objek MimeTypes
The :class:`MimeTypes` class may be useful for applications which may want more than one MIME-type database; it provides an interface similar to the one of the :mod:`!mimetypes` module.
Kelas :class:`MimeTypes` mungkin berguna bagi aplikasi yang menginginkan lebih dari satu basis data tipe MIME; kelas ini menyediakan antarmuka yang mirip dengan antarmuka modul :mod:`!mimetypes`.
This class represents a MIME-types database. By default, it provides access to the same database as the rest of this module. The initial database is created from Python's built-in MIME type tables. It may be extended by loading additional :file:`mime.types`\ -style files into the database using the :meth:`read` or :meth:`readfp` methods. The mapping dictionaries may also be cleared before loading additional data if the default data is not desired.
Kelas ini merepresentasikan basis data tipe MIME. Secara default, kelas ini menyediakan akses ke basis data yang sama dengan bagian lain modul ini. Basis data awal dibuat dari tabel-tabel tipe MIME bawaan Python. Basis data ini dapat diperluas dengan memuat berkas-berkas bergaya :file:`mime.types` tambahan ke dalam basis data menggunakan metode :meth:`read` atau :meth:`readfp`. Dictionary pemetaan juga dapat dikosongkan sebelum memuat data tambahan jika data default tidak diinginkan.
The optional *filenames* parameter can be used to cause additional files to be loaded "on top" of the default database.
Parameter opsional *filenames* dapat dipakai agar berkas-berkas tambahan dimuat "di atas" basis data default.
Dictionary mapping suffixes to suffixes. This is used to allow recognition of encoded files for which the encoding and the type are indicated by the same extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz` to allow the encoding and type to be recognized separately. This is initialized with some predefined values.
Dictionary yang memetakan sufiks ke sufiks. Dictionary ini dipakai agar berkas-berkas yang terkodekan dapat dikenali, ketika pengodean dan tipenya ditunjukkan oleh ekstensi yang sama. Misalnya, ekstensi :file:`.tgz` dipetakan ke :file:`.tar.gz` agar pengodean dan tipenya dapat dikenali secara terpisah. Dictionary ini diinisialisasi dengan beberapa nilai yang telah ditentukan sebelumnya.
Dictionary mapping filename extensions to encoding types. This is initialized with some predefined values.
Dictionary yang memetakan ekstensi nama berkas ke tipe pengodean. Dictionary ini diinisialisasi dengan beberapa nilai yang telah ditentukan sebelumnya.
Tuple containing two dictionaries, mapping filename extensions to MIME types: the first dictionary is for the non-standards types and the second one is for the standard types. They are initialized with some predefined values and MIME type information loaded from files specified by the *filenames* argument.
Tuple yang berisi dua dictionary yang memetakan ekstensi nama berkas ke tipe MIME: dictionary pertama untuk tipe-tipe nonstandar dan dictionary kedua untuk tipe-tipe standar. Keduanya diinisialisasi dengan beberapa nilai yang telah ditentukan sebelumnya serta informasi tipe MIME yang dimuat dari berkas-berkas yang ditentukan oleh argumen *filenames*.
Tuple containing two dictionaries, mapping MIME types to a list of filename extensions: the first dictionary is for the non-standards types and the second one is for the standard types. They are initialized with some predefined values and MIME type information loaded from files specified by the *filenames* argument.
Tuple yang berisi dua dictionary yang memetakan tipe MIME ke daftar ekstensi nama berkas: dictionary pertama untuk tipe-tipe nonstandar dan dictionary kedua untuk tipe-tipe standar. Keduanya diinisialisasi dengan beberapa nilai yang telah ditentukan sebelumnya serta informasi tipe MIME yang dimuat dari berkas-berkas yang ditentukan oleh argumen *filenames*.
Similar to the :func:`guess_extension` function, using the tables stored as part of the object.
Mirip dengan fungsi :func:`guess_extension`, menggunakan tabel-tabel yang tersimpan sebagai bagian dari objek.
Similar to the :func:`guess_type` function, using the tables stored as part of the object.
Mirip dengan fungsi :func:`guess_type`, menggunakan tabel-tabel yang tersimpan sebagai bagian dari objek.
Similar to the :func:`guess_file_type` function, using the tables stored as part of the object.
Mirip dengan fungsi :func:`guess_file_type`, menggunakan tabel-tabel yang tersimpan sebagai bagian dari objek.
Similar to the :func:`guess_all_extensions` function, using the tables stored as part of the object.
Mirip dengan fungsi :func:`guess_all_extensions`, menggunakan tabel-tabel yang tersimpan sebagai bagian dari objek.
Load MIME information from a file named *filename*. This uses :meth:`readfp` to parse the file.
Muat informasi MIME dari berkas bernama *filename*. Metode ini menggunakan :meth:`readfp` untuk mengurai berkas tersebut.
If *strict* is ``True``, information will be added to list of standard types, else to the list of non-standard types.
Jika *strict* bernilai ``True``, informasi akan ditambahkan ke daftar tipe standar, jika tidak, ke daftar tipe nonstandar.
Load MIME type information from an open file *fp*. The file must have the format of the standard :file:`mime.types` files.
Muat informasi tipe MIME dari berkas *fp* yang sedang terbuka. Berkas tersebut harus memiliki format berkas :file:`mime.types` standar.
If *strict* is ``True``, information will be added to the list of standard types, else to the list of non-standard types.
Jika *strict* bernilai ``True``, informasi akan ditambahkan ke daftar tipe standar, jika tidak, ke daftar tipe nonstandar.
Load MIME type information from the Windows registry.
Muat informasi tipe MIME dari registri Windows.
Availability
Ketersediaan
Add a mapping from the MIME type *type* to the extension *ext*. Valid extensions start with a '.' or are empty. When the extension is already known, the new type will replace the old one. When the type is already known the extension will be added to the list of known extensions.
Tambahkan pemetaan dari tipe MIME *type* ke ekstensi *ext*. Ekstensi yang valid diawali '.' atau kosong. Ketika ekstensi sudah dikenal, tipe yang baru akan menggantikan yang lama. Ketika tipe sudah dikenal, ekstensi akan ditambahkan ke daftar ekstensi yang dikenal.
Invalid, undotted extensions will raise a :exc:`ValueError` in Python 3.16.
Ekstensi yang tidak valid dan tidak diawali titik akan memunculkan :exc:`ValueError` di Python 3.16.
Command-line usage
Penggunaan baris perintah
The :mod:`!mimetypes` module can be executed as a script from the command line.
Modul :mod:`!mimetypes` dapat dieksekusi sebagai skrip dari baris perintah.
python -m mimetypes [-h] [-e] [-l] type [type ...]
python -m mimetypes [-h] [-e] [-l] type [type ...]
The following options are accepted:
Opsi-opsi berikut diterima:
Show the help message and exit.
Tampilkan pesan bantuan lalu keluar.
Guess extension instead of type.
Tebak ekstensi, bukan tipe.
Additionally search for some common, but non-standard types.
Cari juga beberapa tipe umum, tetapi nonstandar.
By default the script converts MIME types to file extensions. However, if ``--extension`` is specified, it converts file extensions to MIME types.
Secara default, skrip mengubah tipe MIME menjadi ekstensi berkas. Namun, jika ``--extension`` ditentukan, skrip mengubah ekstensi berkas menjadi tipe MIME.
For each ``type`` entry, the script writes a line into the standard output stream. If an unknown type occurs, it writes an error message into the standard output stream and exits with the return code ``1``.
Untuk setiap entri ``type``, skrip menulis satu baris ke aliran keluaran standar. Jika muncul tipe yang tidak dikenal, skrip menulis pesan galat ke aliran keluaran standar lalu keluar dengan kode keluar ``1``.
Command-line example
Contoh baris perintah
Here are some examples of typical usage of the :mod:`!mimetypes` command-line interface:
Berikut adalah beberapa contoh penggunaan antarmuka baris perintah :mod:`!mimetypes` yang umum:
$ # get a MIME type by a file name $ python -m mimetypes filename.png type: image/png encoding: None $ # get a MIME type by a URL $ python -m mimetypes https://example.com/filename.txt type: text/plain encoding: None $ # get a complex MIME type $ python -m mimetypes filename.tar.gz type: application/x-tar encoding: gzip $ # get a MIME type for a rare file extension $ python -m mimetypes filename.pict error: media type unknown for filename.pict $ # now look in the extended database built into Python $ python -m mimetypes --lenient filename.pict type: image/pict encoding: None $ # get a file extension by a MIME type $ python -m mimetypes --extension text/javascript .js $ # get a file extension by a rare MIME type $ python -m mimetypes --extension text/xul error: unknown type text/xul $ # now look in the extended database again $ python -m mimetypes --extension --lenient text/xul .xul $ # try to feed an unknown file extension $ python -m mimetypes filename.sh filename.nc filename.xxx filename.txt type: application/x-sh encoding: None type: application/x-netcdf encoding: None error: media type unknown for filename.xxx type: text/plain encoding: None $ # try to feed an unknown MIME type $ python -m mimetypes --extension audio/aac audio/opus audio/future audio/x-wav .aac .opus error: unknown type audio/future
$ # get a MIME type by a file name $ python -m mimetypes filename.png type: image/png encoding: None $ # get a MIME type by a URL $ python -m mimetypes https://example.com/filename.txt type: text/plain encoding: None $ # get a complex MIME type $ python -m mimetypes filename.tar.gz type: application/x-tar encoding: gzip $ # get a MIME type for a rare file extension $ python -m mimetypes filename.pict error: media type unknown for filename.pict $ # now look in the extended database built into Python $ python -m mimetypes --lenient filename.pict type: image/pict encoding: None $ # get a file extension by a MIME type $ python -m mimetypes --extension text/javascript .js $ # get a file extension by a rare MIME type $ python -m mimetypes --extension text/xul error: unknown type text/xul $ # now look in the extended database again $ python -m mimetypes --extension --lenient text/xul .xul $ # try to feed an unknown file extension $ python -m mimetypes filename.sh filename.nc filename.xxx filename.txt type: application/x-sh encoding: None type: application/x-netcdf encoding: None error: media type unknown for filename.xxx type: text/plain encoding: None $ # try to feed an unknown MIME type $ python -m mimetypes --extension audio/aac audio/opus audio/future audio/x-wav .aac .opus error: unknown type audio/future
MIME
MIME
content type
content type
headers
headers
file
berkas
mime.types
mime.types
Select an entry in the list to start translating.

⌨ Keyboard shortcuts

Saving

Ctrl+Enter
Save and go to the next entry. If the entry is fuzzy, the flag is cleared too (green button).
Ctrl+Shift+Enter
Save and go on, keeping the fuzzy flag.
Ctrl+U
Toggle the fuzzy flag.
Ctrl+B
Copy the source text into the translation box.
Ctrl+Shift+A
Translate this entry with AI (when AI is set up).

Moving around

↑ / ↓
Previous / next entry, also from the translation box. In multi-line text, from the first / last line.
Ctrl+↑ / ↓
Previous / next entry from anywhere.
Ctrl+F
Go to the search box.
Esc
Close a dialog, menu or thesaurus suggestions.
?
Show this help (outside text boxes).

Editing

Select a word
Select a word or phrase in the translation box to see synonyms; click one to replace it.
Click a glossary term
Insert the term's translation at the cursor.
Ctrl+Enter in a comment
Send a discussion comment.

📌 Context of module library__mimetypes

This context is shared by all project members and tied to the module library__mimetypes. It also helps AI translate more accurately.

No context for this module yet.