Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/objects
diff options
context:
space:
mode:
Diffstat (limited to 'sugar/objects')
-rw-r--r--sugar/objects/mime.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/sugar/objects/mime.py b/sugar/objects/mime.py
index b50ada4..0030e53 100644
--- a/sugar/objects/mime.py
+++ b/sugar/objects/mime.py
@@ -9,3 +9,21 @@ def get_for_file(file_name):
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