From 4a2f187967adb55ecc8ec788eb9e561e475f88e9 Mon Sep 17 00:00:00 2001 From: Alex Schworer Date: Fri, 17 Jul 2015 08:10:02 -0400 Subject: [PATCH 1/3] Allow for the JSON module to be configured. Set `ZENCODER_PY_JSON_MODULE` to `simplejson` to use simplejson instead of the built-in json module. --- README.md | 4 ++++ zencoder/core.py | 22 +++++++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index f057bd4..7828060 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ client = Zencoder('API_KEY') client = Zencoder() ``` +#### Configuring the JSON Module + +By default, zencoder-py uses the built-in `json` module, but you can optionally configure it to use `simplejson` by setting the `ZENCODER_PY_JSON_MODULE` environment variable to `simplejson`. Note that zencoder-py will not install either module, it must already be installed. + ## [Jobs](https://app.zencoder.com/docs/api/jobs) Create a [new job](https://app.zencoder.com/docs/api/jobs/create). diff --git a/zencoder/core.py b/zencoder/core.py index 1220446..521087e 100644 --- a/zencoder/core.py +++ b/zencoder/core.py @@ -2,21 +2,13 @@ import requests from datetime import datetime -# Note: I've seen this pattern for dealing with json in different versions of -# python in a lot of modules -- if there's a better way, I'd love to use it. -try: - # python 2.6 and greater - import json -except ImportError: - try: - # python 2.5 - import simplejson - json = simplejson - except ImportError: - # if we're in django or Google AppEngine land - # use this as a last resort - from django.utils import simplejson - json = simplejson +json_module = os.environ.get('ZENCODER_PY_JSON_MODULE', 'json') +valid_json_modules = ('json', 'simplejson') +if json_module not in valid_json_modules: + msg = 'ZENCODER_PY_JSON_MODULE=%s is not supported. Supported JSON modules: %s' % (json_module, ', '.join(valid_json_modules)) + raise RuntimeError(msg) + +json = __import__(json_module) __version__ = '0.6.5' From 5ec8aa00b3467132cb426a60faa75e2c5e6315af Mon Sep 17 00:00:00 2001 From: Alex Schworer Date: Fri, 17 Jul 2015 08:23:46 -0400 Subject: [PATCH 2/3] configure travis to test simplejson --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a9e5993..0c89e36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,13 @@ python: - "3.3" - "3.4" - "pypy" -install: pip install -e . +env: + matrix: + - ZENCODER_PY_JSON_MODULE=simplejson + +install: + - pip install simplejson + - pip install -e . # command to run tests script: nosetests From dbe944d4cc840f6c706a4d69798a5fc4c9435ae7 Mon Sep 17 00:00:00 2001 From: Alex Schworer Date: Fri, 17 Jul 2015 08:28:01 -0400 Subject: [PATCH 3/3] add standard json to build list --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0c89e36..ec970c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ python: env: matrix: - ZENCODER_PY_JSON_MODULE=simplejson + - ZENCODER_PY_JSON_MODULE=json install: - pip install simplejson