1- """
2- Main Zencoder module
3- """
4-
51import os
62import httplib2
73from urllib import urlencode
@@ -32,15 +28,14 @@ def __init__(self, http_response, content):
3228
3329class HTTPBackend (object ):
3430"""
35- Abstracts out an HTTP backend, but defaults to httplib2
31+ Abstracts out an HTTP backend, but defaults to httplib2. Required arguments
32+ are `base_url` and `api_key`.
3633
37- @FIXME: Build in support for supplying arbitrary backends
34+ .. note::
35+ While `as_xml` is provided as a keyword argument, XML or input or output
36+ is not supported.
3837 """
3938def __init__ (self ,base_url ,api_key ,as_xml = False ,resource_name = None ,timeout = None ,test = False ,version = None ):
40- """
41- Creates an HTTPBackend object, which abstracts out some of the
42- library specific HTTP stuff.
43- """
4439self .base_url = base_url
4540if resource_name :
4641self .base_url = self .base_url + resource_name
@@ -53,12 +48,16 @@ def __init__(self, base_url, api_key, as_xml=False, resource_name=None, timeout=
5348
5449def content_length (self ,body ):
5550"""
56- Returns the content length as an int for the given body data
51+ Returns the content length as an int for the given `body` data. Used by
52+ PUT and POST requests to set the Content-Length header.
5753 """
5854return str (len (body ))if body else "0"
5955
6056@property
6157def headers (self ):
58+ """ Returns default headers, by setting the Content-Type and Accepts
59+ headers.
60+ """
6261if self .as_xml :
6362return {'Content-Type' :'application/xml' ,
6463'Accepts' :'application/xml' }
@@ -68,8 +67,11 @@ def headers(self):
6867
6968def encode (self ,data ):
7069"""
71- Encodes data as either JSON or XML, so that it can be passed onto
72- the Zencoder API
70+ Encodes data as JSON (by calling `json.dumps`), so that it can be
71+ passed onto the Zencoder API.
72+
73+ .. note::
74+ Encoding as XML is not supported.
7375 """
7476if not self .as_xml :
7577return json .dumps (data )
@@ -78,7 +80,11 @@ def encode(self, data):
7880
7981def decode (self ,raw_body ):
8082"""
81- Returns the raw_body as json (the default) or XML
83+ Returns the JSON-encoded `raw_body` and decodes it to a `dict` (using
84+ `json.loads`).
85+
86+ .. note::
87+ Decoding as XML is not supported.
8288 """
8389if not self .as_xml :
8490# only parse json when it exists, else just return None