Projet

Général

Profil

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

Benjamin Dauvergne, 25 mars 2016 23:26

Télécharger (2,14 ko)

Voir les différences:

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

 wcs/data_sources.py | 18 +++++++++---------
 1 file changed, 9 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
    for item in structured_items:
91
        # skip malformed items
92
        if not item.get('id') or not item.get('text'):
93
            continue
94
        tupled_items.append((str(item['id']), str(item['text']), str(item.get('key', item['id']))))
94 95
    return tupled_items
95 96

  
97

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