Skip to content

Commit

Permalink
better explicit mock structure and fixed state spell
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Feb 2, 2015
1 parent bfb79c8 commit 5d27c37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/netius/common/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,28 @@ def __init__(self, owner):
netius.Observable.__init__(self)
self.owner = owner

@classmethod
def mock(cls, owner, state):
mock = cls(owner)
mock.set_state(state)
return mock

def build(self):
netius.Observable.build(self)

def destroy(self):
netius.Observable.destroy(self)
self.owner = None

def get_sate(self):
def get_state(self):
cls = self.__class__
fields = cls.FIELDS
state = dict()
for field in fields:
state[field] = getattr(self, field)
return state

def set_sate(self, state):
def set_state(self, state):
cls = self.__class__
fields = cls.FIELDS
for field in fields:
Expand Down
5 changes: 2 additions & 3 deletions src/netius/extra/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def on_data_http(self, connection, parser):
# must be delayed until the file is processed (inserted in queue)
if hasattr(connection, "file") and connection.file:
if not hasattr(connection, "queue"): connection.queue = []
state = parser.get_sate()
state = parser.get_state()
connection.queue.append(state)
return

Expand Down Expand Up @@ -379,8 +379,7 @@ def _next_queue(self, connection):
# in the queue and then uses it to construct a mock parser object that is
# going to be used to simulate an on data call to the file server
state = connection.queue.pop(0)
parser = netius.common.HTTPParser(connection.parser.owner)
parser.set_sate(state)
parser = netius.common.HTTPParser.mock(connection.parser.owner, state)
self.on_data_http(connection, parser)

def _file_send(self, connection):
Expand Down

0 comments on commit 5d27c37

Please sign in to comment.