import weakref
import warnings
import urllib
+import urllib2
from md5 import md5
_use_simplejson = False
pass
+class RTMParseError(RTMError):
+ pass
+
+
class AuthStateMachine(object):
"""If the state is in those setup for the machine, then return
the datum sent. Along the way, it is an automatic call if the
if queryArgs:
url += '?' + urllib.urlencode(queryArgs)
warnings.warn("Performing download of %s" % url, stacklevel=5)
- return urllib.urlopen(url)
+ return urllib2.urlopen(url)
def get(self, **params):
"Get the XML response for the passed `params`."
params['format'] = 'json'
params['api_sig'] = self._sign(params)
- json = self.open_url(SERVICE_URL, params).read()
-
- if _use_simplejson:
- data = DottedDict('ROOT', simplejson.loads(json))
- else:
- data = DottedDict('ROOT', safer_eval(json))
+ connection = self.open_url(SERVICE_URL, params)
+ json = connection.read()
+ data = DottedDict('ROOT', parse_json(json))
rsp = data.rsp
if rsp.stat == 'fail':
def safer_eval(string):
- return eval(string, {}, {})
+ try:
+ return eval(string, {}, {})
+ except SyntaxError, e:
+ newE = RTMParseError("Error parseing json")
+ newE.error = e
+ raise newE
+
+
+if _use_simplejson:
+ parse_json = simplejson.loads
+else:
+ parse_json = safer_eval
API = {