1 |
Index: ./transifex/storage/models.py |
2 |
=================================================================== |
3 |
--- ./transifex/storage/models.py |
4 |
+++ ./transifex/storage/models.py 2011-03-24 17:25:44.947065584 +0100 |
5 |
@@ -113,10 +113,18 @@ |
6 |
""" |
7 |
Try to parse the file and fill in information fields in current model |
8 |
""" |
9 |
+ # this try to guess the API of the magic module, between |
10 |
+ # the one from file and the other one from python-magic |
11 |
+ try: |
12 |
+ m = magic.Magic(mime=True) |
13 |
+ # guess mimetype and remove charset |
14 |
+ self.mime_type = m.from_file(self.get_storage_path()) |
15 |
+ except (TypeError, AttributeError): |
16 |
+ m = magic.open(magic.MAGIC_NONE) |
17 |
+ m.load() |
18 |
+ self.mime_type = m.file(self.get_storage_path()) |
19 |
+ m.close() |
20 |
|
21 |
- m = magic.Magic(mime=True) |
22 |
- # guess mimetype and remove charset |
23 |
- self.mime_type = m.from_file(self.get_storage_path()) |
24 |
self.save() |
25 |
|
26 |
parser = self.find_parser() |