Mercurial > repos > iuc > datatyp_json
comparison json.py @ 0:3b76639ad0bb draft
Uploaded
author | iuc |
---|---|
date | Mon, 28 Jul 2014 02:48:36 -0400 |
parents | |
children | a37d92dc7fd2 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3b76639ad0bb |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 from galaxy.datatypes.data import Text | |
4 from galaxy.datatypes.data import get_file_peek | |
5 import json | |
6 import os | |
7 | |
8 class Json( Text ): | |
9 file_ext = "json" | |
10 | |
11 def set_peek( self, dataset, is_multi_byte=False ): | |
12 if not dataset.dataset.purged: | |
13 dataset.peek = get_file_peek( dataset.file_name, is_multi_byte=is_multi_byte ) | |
14 dataset.blurb = "JavaScript Object Notation (JSON)" | |
15 else: | |
16 dataset.peek = 'file does not exist' | |
17 dataset.blurb = 'file purged from disc' | |
18 | |
19 def sniff( self, filename ): | |
20 """ | |
21 Try to load the string with the json module. If successful it's a json file. | |
22 """ | |
23 try: | |
24 json.load( filename ) | |
25 return True | |
26 except: | |
27 return False | |
28 | |
29 def set_meta( self, dataset, **kwd ): | |
30 """ | |
31 | |
32 Set the number of models in dataset. | |
33 """ | |
34 pass | |
35 | |
36 |