Projet

Général

Profil

0001-decode-remote-data-source-using-qommon.misc.json_loa.patch

Benjamin Dauvergne, 25 mars 2016 21:00

Télécharger (2,18 ko)

Voir les différences:

Subject: [PATCH] decode remote data source using qommon.misc.json_loads
 (#10447)

 wcs/data_sources.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
wcs/data_sources.py
15 15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
16 16

  
17 17
import collections
18
import json
19 18
import urllib2
20 19
import xml.etree.ElementTree as ET
21 20

  
......
84 83
            r += widget.render_content()
85 84
        return r.getvalue()
86 85

  
86

  
87 87
def get_items(data_source):
88 88
    structured_items = get_structured_items(data_source)
89
    tupled_items = [(site_encode(x.get('id')),
90
        site_encode(x.get('text')),
91
        site_encode(x.get('key'))) for x in structured_items]
92
    if tupled_items and tupled_items[0][2] is None: # no key
93
        tupled_items = [tuple(x[:2]) + (x[0],) for x in tupled_items]
89
    tupled_items = []
90
    print 'structured_items', structured_items
91
    for item in structured_items:
92
        # skip malformed items
93
        if not item.get('id') or not item.get('text'):
94
            continue
95
        tupled_items.append((str(item['id']), str(item['text']), str(item.get('key', item['id']))))
94 96
    return tupled_items
95 97

  
98

  
96 99
def get_structured_items(data_source):
97 100
    data_source = get_real(data_source)
98 101
    if data_source.get('type') == 'formula':
......
138 141
        if '[' in url:
139 142
            vars = get_publisher().substitutions.get_context_variables()
140 143
            url = get_variadic_url(url, vars)
141
        charset = get_publisher().site_charset
142 144
        try:
143
            results = []
144
            entries = json.load(urllib2.urlopen(url))
145
            entries = qommon.misc.json_loads(urllib2.urlopen(url).read())
145 146
            if type(entries) is not dict:
146 147
                raise ValueError('not a json dict')
147 148
            if type(entries.get('data')) is not list:
148
-