前々回。
「g_content_type_guess だと ContentType は拡張子依存みたい」
と書いた手前、筆者的には当然の結果だけど一応試してみた。
#!/usr/bin/env python3
from gi.repository import Gio
# Doesn't exist a File.
ans = Gio.content_type_guess("Not Found.txt")
print(ans)
#=> ('text/plain', False)
# File Create (No Ext).
with open("found", "w") as f:
f.write("#!/usr/bin/env python3\n")
# g_content_type_guess
ans = Gio.content_type_guess("found")
print(ans)
#=> ('application/octet-stream', False)
# Gio Query
obj = Gio.file_new_for_path("found")
info = obj.query_info(
Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
Gio.FileQueryInfoFlags.NONE )
ans = info.get_content_type()
print(ans)
#=> text/x-python
やっぱり拡張子の有無で関数の違いが出るんですね。
Gtk, GLib と付き合いが長いので結果は解っていたけどこういうこと。
つまり面倒臭い手段を使えば予定通りな結果が得られる。
GNOME プロジェクトは計画的にやっているんだろうな、と思ってしまう。
何故こうなるかは割愛、これは GNOME 関連では単純なほうだyo!