1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/6a718b389bf1/ Changeset: 6a718b389bf1 User: dannon Date: 2014-09-04 22:58:57 Summary: Pep8 fixes in galaxy.util.json prior to work there. Affected #: 1 file diff -r 83e45a9e4cc994daed44e406a334660d9db7ed30 -r 6a718b389bf1caa5461c5ff7a7dd644f1279cd69 lib/galaxy/util/json.py --- a/lib/galaxy/util/json.py +++ b/lib/galaxy/util/json.py @@ -5,7 +5,6 @@ import json import logging import random -import socket import string to_json_string = json.dumps @@ -13,6 +12,7 @@ log = logging.getLogger( __name__ ) + def json_fix( val ): if isinstance( val, list ): return [ json_fix( v ) for v in val ] @@ -25,33 +25,44 @@ # Methods for handling JSON-RPC + def validate_jsonrpc_request( request, regular_methods, notification_methods ): try: request = from_json_string( request ) except Exception, e: - return False, request, jsonrpc_response( id = None, error = dict( code = -32700, message = 'Parse error', data = str( e ) ) ) + return False, request, jsonrpc_response( id=None, + error=dict( code=-32700, + message='Parse error', + data=str( e ) ) ) try: assert 'jsonrpc' in request, \ 'This server requires JSON-RPC 2.0 and no "jsonrpc" member was sent with the Request object as per the JSON-RPC 2.0 Specification.' assert request['jsonrpc'] == '2.0', \ - 'Requested JSON-RPC version "%s" != required version "2.0".' % request['jsonrpc'] + 'Requested JSON-RPC version "%s" != required version "2.0".' % request['jsonrpc'] assert 'method' in request, 'No "method" member was sent with the Request object' except AssertionError, e: - return False, request, jsonrpc_response( request = request, error = dict( code = -32600, message = 'Invalid Request', data = str( e ) ) ) + return False, request, jsonrpc_response( request=request, + error=dict( code=-32600, + message='Invalid Request', + data=str( e ) ) ) try: assert request['method'] in ( regular_methods + notification_methods ) except AssertionError, e: - return False, request, jsonrpc_response( request = request, - error = dict( code = -32601, - message = 'Method not found', - data = 'Valid methods are: %s' % ', '.join( regular_methods + notification_methods ) ) ) + return False, request, jsonrpc_response( request=request, + error=dict( code=-32601, + message='Method not found', + data='Valid methods are: %s' % ', '.join( regular_methods + notification_methods ) ) ) try: if request['method'] in regular_methods: assert 'id' in request, 'No "id" member was sent with the Request object and the requested method "%s" is not a notification method' % request['method'] except AssertionError, e: - return False, request, jsonrpc_response( request = request, error = dict( code = -32600, message = 'Invalid Request', data = str( e ) ) ) + return False, request, jsonrpc_response( request=request, + error=dict( code=-32600, + message='Invalid Request', + data=str( e ) ) ) return True, request, None + def validate_jsonrpc_response( response, id=None ): try: response = from_json_string( response ) @@ -81,11 +92,12 @@ return False, response return True, response + def jsonrpc_request( method, params=None, id=None, jsonrpc='2.0' ): if method is None: log.error( 'jsonrpc_request(): "method" parameter cannot be None' ) return None - request = dict( jsonrpc = jsonrpc, method = method ) + request = dict( jsonrpc=jsonrpc, method=method ) if params: request['params'] = params if id is not None and id is True: @@ -94,15 +106,16 @@ request['id'] = id return request + def jsonrpc_response( request=None, id=None, result=None, error=None, jsonrpc='2.0' ): if result: - rval = dict( jsonrpc = jsonrpc, result = result ) + rval = dict( jsonrpc=jsonrpc, result=result ) elif error: - rval = dict( jsonrpc = jsonrpc, error = error ) + rval = dict( jsonrpc=jsonrpc, error=error ) else: msg = 'jsonrpc_response() called with out a "result" or "error" parameter' log.error( msg ) - rval = dict( jsonrpc = jsonrpc, error = msg ) + rval = dict( jsonrpc=jsonrpc, error=msg ) if id is not None: rval['id'] = id elif request is not None and 'id' in request: Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.