From 72fb11ce0f5b4e2af5c437b119d06d7916e92970 Mon Sep 17 00:00:00 2001 From: Stephen Diehl Date: Mon, 14 May 2012 11:57:23 -0400 Subject: [PATCH] removed namedict for good --- zipline/protocol.py | 10 +++-- zipline/utils/protocol_utils.py | 73 --------------------------------- 2 files changed, 6 insertions(+), 77 deletions(-) diff --git a/zipline/protocol.py b/zipline/protocol.py index 94141e64..f062a146 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -258,8 +258,8 @@ def DATASOURCE_FRAME(event): def DATASOURCE_UNFRAME(msg): """ - Extracts payload, and calls correct UNFRAME method based on the \ -datasource type passed along. + Extracts payload, and calls correct UNFRAME method based on the + datasource type passed along. Returns a dict containing at least: @@ -276,11 +276,12 @@ datasource type passed along. - dt - a datetime object """ - try: ds_type, source_id, payload = msgpack.loads(msg) assert isinstance(ds_type, int) + rval = ndict({'source_id':source_id}) + if payload == DATASOURCE_TYPE.EMPTY: child_value = ndict({'dt':None}) elif(ds_type == DATASOURCE_TYPE.TRADE): @@ -291,6 +292,7 @@ datasource type passed along. raise INVALID_DATASOURCE_FRAME(msg) rval.merge(child_value) + import pdb; pdb.set_trace() return rval except TypeError: @@ -306,7 +308,7 @@ INVALID_FEED_FRAME = FrameExceptionFactory('FEED') def FEED_FRAME(event): """ - :param event: a nameddict with at least + :param event: a ndict with at least - source_id - type diff --git a/zipline/utils/protocol_utils.py b/zipline/utils/protocol_utils.py index 60c90814..7f79dd4f 100644 --- a/zipline/utils/protocol_utils.py +++ b/zipline/utils/protocol_utils.py @@ -31,79 +31,6 @@ def FrameExceptionFactory(name): return InvalidFrame -class namedict(MutableMapping): - """ - - Namedicts are dict like objects that have fields accessible by attribute lookup - as well as being indexable and iterable:: - - HEARTBEAT_PROTOCOL = namedict({ - 'REQ' : b'\x01', - 'REP' : b'\x02', - }) - - HEARTBEAT_PROTOCOL.REQ # syntactic sugar - HEARTBEAT_PROTOCOL.REP # oh suga suga - - For more complex structs use collections.namedtuple: - """ - - def __init__(self, dct=None): - if(dct): - self.__dict__.update(dct) - - def __setitem__(self, key, value): - """ - Required for use by pymongo as_class parameter to find. - """ - if(key == '_id'): - self.__dict__['id'] = value - else: - self.__dict__[key] = value - - def __getitem__(self, key): - return self.__dict__[key] - - def __delitem__(self, key): - del self.__dict__[key] - - def __iter__(self): - return self.__dict__.iterkeys() - - def __len__(self): - return len(self.__dict__) - - def keys(self): - return self.__dict__.keys() - - def as_dict(self): - # shallow copy is O(n) - return copy.copy(self.__dict__) - - def delete(self, key): - del(self.__dict__[key]) - - def merge(self, other_nd): - assert isinstance(other_nd, namedict) - self.__dict__.update(other_nd.__dict__) - - def __repr__(self): - return "namedict: " + str(self.__dict__) - - def __eq__(self, other): - # !!!!!!!!!!!!!!!!!!!! - # !!!! DANGEROUS !!!!! - # !!!!!!!!!!!!!!!!!!!! - return other != None and self.__dict__ == other.__dict__ - - def has_attr(self, name): - return self.__dict__.has_key(name) - - def as_series(self): - s = pandas.Series(self.__dict__) - s.name = self.sid - return s - class ndict(MutableMapping): """ Xtreme Namedicts 2.0