Mercurial > kallithea
diff rhodecode/controllers/api/__init__.py @ 1514:87ec80c280bb beta
fixed issues with python2.5
added compat module to rhodecode to have one point of fetching backward incompatible libs.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 07 Oct 2011 02:51:18 +0200 |
parents | 4aba7be311e8 |
children | fe5575f95850 702e29ce1e9b |
line wrap: on
line diff
--- a/rhodecode/controllers/api/__init__.py Wed Oct 05 00:10:42 2011 +0200 +++ b/rhodecode/controllers/api/__init__.py Fri Oct 07 02:51:18 2011 +0200 @@ -26,12 +26,12 @@ # MA 02110-1301, USA. import inspect -import json import logging import types import urllib import traceback -from itertools import izip_longest + +from rhodecode.lib.compat import izip_longest, json from paste.response import replace_header @@ -103,7 +103,7 @@ try: json_body = json.loads(urllib.unquote_plus(raw_body)) - except ValueError as e: + except ValueError, e: #catch JSON errors Here return jsonrpc_error(message="JSON parse error ERR:%s RAW:%r" \ % (e, urllib.unquote_plus(raw_body))) @@ -116,14 +116,14 @@ log.debug('method: %s, params: %s', self._req_method, self._req_params) - except KeyError as e: + except KeyError, e: return jsonrpc_error(message='Incorrect JSON query missing %s' % e) #check if we can find this session using api_key try: u = User.get_by_api_key(self._req_api_key) auth_u = AuthUser(u.user_id, self._req_api_key) - except Exception as e: + except Exception, e: return jsonrpc_error(message='Invalid API KEY') self._error = None @@ -138,8 +138,8 @@ arglist = argspec[0][1:] defaults = argspec[3] or [] default_empty = types.NotImplementedType - - kwarglist = list(izip_longest(reversed(arglist),reversed(defaults), + + kwarglist = list(izip_longest(reversed(arglist), reversed(defaults), fillvalue=default_empty)) # this is little trick to inject logged in user for @@ -157,12 +157,12 @@ (self._func.__name__, USER_SESSION_ATTR)) # get our arglist and check if we provided them as args - for arg,default in kwarglist: + for arg, default in kwarglist: if arg == USER_SESSION_ATTR: # USER_SESSION_ATTR is something translated from api key and # this is checked before so we don't need validate it continue - + # skip the required param check if it's default value is # NotImplementedType (default_empty) if not self._req_params or (type(default) == default_empty @@ -201,10 +201,11 @@ raw_response = self._inspect_call(self._func) if isinstance(raw_response, HTTPError): self._error = str(raw_response) - except JSONRPCError as e: + except JSONRPCError, e: self._error = str(e) - except Exception as e: - log.error('Encountered unhandled exception: %s' % traceback.format_exc()) + except Exception, e: + log.error('Encountered unhandled exception: %s' \ + % traceback.format_exc()) json_exc = JSONRPCError('Internal server error') self._error = str(json_exc)