1717 from simplejson import JSONDecodeError
1818except ImportError :
1919 import json
20- class JSONDecodeError (Exception ): pass
20+
21+ class JSONDecodeError (Exception ):
22+ pass
2123 # Ugly: No alternative because this exception class doesnt seem to be there
2224 # in the standard python module
2325import urllib
@@ -126,7 +128,7 @@ def call(self, url, params):
126128 headers = {'Authorization' : 'Bearer %s' % self .access_token }
127129 )
128130 response = urllib2 .urlopen (request ).read ()
129- rv = json .loads (response .decode ("UTF-8-sig" ))
131+ rv = json .loads (response .decode ("UTF-8-sig" ))
130132
131133 if isinstance (rv , basestring ) and \
132134 rv .startswith ("ArgumentOutOfRangeException" ):
@@ -159,7 +161,7 @@ def translate(self, text, to_lang, from_lang=None,
159161 'to' : to_lang ,
160162 'contentType' : content_type ,
161163 'category' : category ,
162- }
164+ }
163165 if from_lang is not None :
164166 params ['from' ] = from_lang
165167 return self .call (
@@ -170,23 +172,23 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
170172 """Translates an array of text strings from one language to another.
171173
172174 :param texts: A list containing texts for translation.
173- :param to_lang: A string representing the language code to
175+ :param to_lang: A string representing the language code to
174176 translate the text into.
175- :param from_lang: A string representing the language code of the
176- translation text. If left None the response will include the
177+ :param from_lang: A string representing the language code of the
178+ translation text. If left None the response will include the
177179 result of language auto-detection. (Default: None)
178- :param options: A TranslateOptions element containing the values below.
180+ :param options: A TranslateOptions element containing the values below.
179181 They are all optional and default to the most common settings.
180182
181- Category: A string containing the category (domain) of the
183+ Category: A string containing the category (domain) of the
182184 translation. Defaults to "general".
183- ContentType: The format of the text being translated. The
184- supported formats are "text/plain" and "text/html". Any
185+ ContentType: The format of the text being translated. The
186+ supported formats are "text/plain" and "text/html". Any
185187 HTML needs to be well-formed.
186- Uri: A string containing the content location of this
188+ Uri: A string containing the content location of this
187189 translation.
188190 User: A string used to track the originator of the submission.
189- State: User state to help correlate request and response. The
191+ State: User state to help correlate request and response. The
190192 same contents will be returned in the response.
191193 """
192194 options = {
@@ -195,12 +197,12 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
195197 'Uri' : '' ,
196198 'User' : 'default' ,
197199 'State' : ''
198- }.update (options )
200+ }.update (options )
199201 params = {
200202 'texts' : json .dumps (texts ),
201203 'to' : to_lang ,
202204 'options' : json .dumps (options ),
203- }
205+ }
204206 if from_lang is not None :
205207 params ['from' ] = from_lang
206208
0 commit comments