climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [1/2] git commit: CLIMATE-382 - Fix LFME content type issues
Date Thu, 03 Apr 2014 02:19:24 GMT
Repository: climate
Updated Branches:
  refs/heads/master c273e2ed9 -> 7bde9e126


CLIMATE-382 - Fix LFME content type issues

- Stop parsing JSON with ast.literal_eval in tests. Replace with the more
  correct json.loads.
- json.dumps is no longer called on all output JSON. When returning
  plain JSON this was causing the content type to be incorrectly set as
  text. Now json.dumps is only called when returning a JSONP response so
  we have the dictionary properly serialized. Bottle handles
  automatically setting the content type when returning a dictionary, so
  we don't need to manually set the content-type.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/c1af3625
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/c1af3625
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/c1af3625

Branch: refs/heads/master
Commit: c1af36252894ac9d54a7237e65d62beafc7de659
Parents: c9558e0
Author: Michael Joyce <joyce@apache.org>
Authored: Thu Mar 20 18:08:47 2014 -0700
Committer: Michael Joyce <joyce@apache.org>
Committed: Thu Mar 20 18:08:47 2014 -0700

----------------------------------------------------------------------
 ocw-ui/backend/local_file_metadata_extractors.py      |  9 +++------
 .../tests/test_local_file_metadata_extractors.py      | 14 +++++++-------
 2 files changed, 10 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/c1af3625/ocw-ui/backend/local_file_metadata_extractors.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/local_file_metadata_extractors.py b/ocw-ui/backend/local_file_metadata_extractors.py
index e70714e..8d9299c 100644
--- a/ocw-ui/backend/local_file_metadata_extractors.py
+++ b/ocw-ui/backend/local_file_metadata_extractors.py
@@ -115,9 +115,8 @@ def list_latlon(file_path):
     else:
         output = {'success': success, 'variables': var_names_list}
 
-    output = json.dumps(output)
     if request.query.callback:
-        return '%s(%s)' % (request.query.callback, output)
+        return '%s(%s)' % (request.query.callback, json.dumps(output))
     return output
 
 @lfme_app.route('/list_time/<file_path:path>')
@@ -178,9 +177,8 @@ def list_time(file_path):
     else:
         output = {'success': False, 'variables': var_names_list}
 
-    output = json.dumps(output)
     if request.query.callback:
-        return '%s(%s)' % (request.query.callback, output)
+        return '%s(%s)' % (request.query.callback, json.dumps(output))
     return output
 
 @lfme_app.route('/list_vars/<file_path:path>')
@@ -219,9 +217,8 @@ def list_vars(file_path):
         output = {'success': True, 'variables': in_file.variables.keys()}
         in_file.close()
     finally:
-        output = json.dumps(output)
         if request.query.callback:
-          return "%s(%s)" % (request.query.callback, output)
+            return "%s(%s)" % (request.query.callback, json.dumps(output))
         return output
 
 @lfme_app.hook('after_request')

http://git-wip-us.apache.org/repos/asf/climate/blob/c1af3625/ocw-ui/backend/tests/test_local_file_metadata_extractors.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/tests/test_local_file_metadata_extractors.py b/ocw-ui/backend/tests/test_local_file_metadata_extractors.py
index fa25c1e..8d751c7 100644
--- a/ocw-ui/backend/tests/test_local_file_metadata_extractors.py
+++ b/ocw-ui/backend/tests/test_local_file_metadata_extractors.py
@@ -1,5 +1,5 @@
 import os
-from ast import literal_eval
+from json import loads
 import unittest
 from webtest import TestApp
 
@@ -46,7 +46,7 @@ class TestLatLonExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")
@@ -78,7 +78,7 @@ class TestLatLonExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")
@@ -115,7 +115,7 @@ class TestTimeExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")
@@ -147,7 +147,7 @@ class TestTimeExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")
@@ -180,7 +180,7 @@ class TestVariableExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")
@@ -202,7 +202,7 @@ class TestVariableExtraction(unittest.TestCase):
         # and check for proper content.
         callback = json[:json.index('(')]
         json = json[json.index('(') + 1 : json.rindex(')')]
-        json = literal_eval(json)
+        json = loads(json)
 
         self.assertDictEqual(expected_return, json)
         self.assertEqual(callback, "test_callback")


Mime
View raw message