Skip to content

Commit

Permalink
Add a counter based id generator. Replace lambda in Client with modul…
Browse files Browse the repository at this point in the history
…e level function.
  • Loading branch information
coopernurse committed Mar 16, 2012
1 parent 1ce4f77 commit 4bbb0cd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions runtime.py
@@ -1,8 +1,8 @@

import copy
import urllib2
import uuid
import sys
import itertools
try:
import json
except:
Expand Down Expand Up @@ -34,6 +34,13 @@ def unpack_method(method):
func_name = method[pos+1:]
return iface_name, func_name

def idgen_uuid():
return uuid.uuid4()

idgen_seq_counter = itertools.count()
def idgen_seq():
return str(idgen_seq_counter.next())

class RpcException(Exception, json.JSONEncoder):

def __init__(self, code, msg="", data=None):
Expand Down Expand Up @@ -167,12 +174,10 @@ def request(self, req):
class Client(object):

def __init__(self, transport, validate_request=True, validate_response=True,
id_gen=None):
id_gen=idgen_uuid):
self.transport = transport
self.validate_req = validate_request
self.validate_resp = validate_response
if not id_gen:
id_gen = lambda: uuid.uuid4().hex
self.id_gen = id_gen
req = {"jsonrpc": "2.0", "method": "barrister-idl", "id": "1"}
resp = transport.request(req)
Expand Down

0 comments on commit 4bbb0cd

Please sign in to comment.