sugar-toolkit-gtk3/sugar/objects/mime.py

30 lines
821 B
Python
Raw Normal View History

2007-05-24 12:08:05 +02:00
try:
from sugar import _sugarext
except ImportError:
from sugar import ltihooks
from sugar import _sugarext
2007-05-24 12:30:42 +02:00
def get_for_file(file_name):
return _sugarext.get_mime_type_for_file(file_name)
2007-05-24 12:08:05 +02:00
def get_from_file_name(file_name):
return _sugarext.get_mime_type_from_file_name(file_name)
_extensions_cache = {}
def get_primary_extension(mime_type):
if _extensions_cache.has_key(mime_type):
return _extensions_cache[mime_type]
f = open('/etc/mime.types')
while True:
line = f.readline()
cols = line.replace('\t', ' ').split(' ')
if mime_type == cols[0]:
for col in cols[1:]:
if col:
_extensions_cache[mime_type] = col
return col
_extensions_cache[mime_type] = None
return None