Skip to content
This repository has been archived by the owner on Feb 14, 2020. It is now read-only.

Commit

Permalink
net/pollers.py: move Stats and SimpleStats into utils.py
Browse files Browse the repository at this point in the history
SimpleStats and Stats are generic classes and therefore they should live
in neubot/utils.py rather than in net/pollers.py.
  • Loading branch information
bassosimone committed Dec 29, 2010
1 parent 66608fc commit 02a1824
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
31 changes: 2 additions & 29 deletions neubot/net/pollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from select import error
from neubot.utils import unit_formatter
from neubot.utils import ticks
from neubot.utils import SimpleStats
from neubot.utils import Stats
from select import select
from sys import stdout
from errno import EINTR
Expand Down Expand Up @@ -76,35 +78,6 @@ def __del__(self):
# Interval between each check for timed-out I/O operations
CHECK_TIMEOUT = 10

class SimpleStats:
def __init__(self):
self.begin()

def __del__(self):
pass

def begin(self):
self.start = ticks()
self.stop = 0
self.length = 0

def end(self):
self.stop = ticks()

def account(self, count):
self.length += count

def diff(self):
return self.stop - self.start

def speed(self):
return self.length / self.diff()

class Stats:
def __init__(self):
self.send = SimpleStats()
self.recv = SimpleStats()

class Poller:
def __init__(self, timeout):
self.timeout = timeout
Expand Down
33 changes: 33 additions & 0 deletions neubot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,36 @@ def XML_to_string(document):

def XML_to_stringio(document):
return StringIO(XML_to_string(document))

#
# Stats
#

class SimpleStats:
def __init__(self):
self.begin()

def __del__(self):
pass

def begin(self):
self.start = ticks()
self.stop = 0
self.length = 0

def end(self):
self.stop = ticks()

def account(self, count):
self.length += count

def diff(self):
return self.stop - self.start

def speed(self):
return self.length / self.diff()

class Stats:
def __init__(self):
self.send = SimpleStats()
self.recv = SimpleStats()

0 comments on commit 02a1824

Please sign in to comment.