Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for the JSON module to be configured. #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ python:
- "3.3"
- "3.4"
- "pypy"
install: pip install -e .
env:
matrix:
- ZENCODER_PY_JSON_MODULE=simplejson
- ZENCODER_PY_JSON_MODULE=json

install:
- pip install simplejson
- pip install -e .
# command to run tests
script: nosetests

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
22 changes: 7 additions & 15 deletions zencoder/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down