cleanup for core.misc and core.netns
This commit is contained in:
parent
05a5574155
commit
eb04e0a79f
7 changed files with 29 additions and 29 deletions
|
@ -155,7 +155,8 @@ class EventLoop(object):
|
|||
schedule = True
|
||||
break
|
||||
event = heapq.heappop(self.queue)
|
||||
assert event.time <= now
|
||||
if event.time > now:
|
||||
raise ValueError("invalid event time: %s > %s", event.time, now)
|
||||
event.run()
|
||||
|
||||
with self.lock:
|
||||
|
@ -170,11 +171,13 @@ class EventLoop(object):
|
|||
:return: nothing
|
||||
"""
|
||||
with self.lock:
|
||||
assert self.running
|
||||
if not self.running:
|
||||
raise ValueError("scheduling event while not running")
|
||||
if not self.queue:
|
||||
return
|
||||
delay = self.queue[0].time - time.time()
|
||||
assert self.timer is None
|
||||
if self.timer:
|
||||
raise ValueError("timer was already set")
|
||||
self.timer = Timer(delay, self.__run_events)
|
||||
self.timer.daemon = True
|
||||
self.timer.start()
|
||||
|
|
|
@ -31,7 +31,7 @@ class MacAddress(object):
|
|||
:return: string representation
|
||||
:rtype: str
|
||||
"""
|
||||
return ":".join(map(lambda x: "%02x" % ord(x), self.addr))
|
||||
return ":".join("%02x" % ord(x) for x in self.addr)
|
||||
|
||||
def to_link_local(self):
|
||||
"""
|
||||
|
@ -61,7 +61,7 @@ class MacAddress(object):
|
|||
:return: mac address class
|
||||
:rtype: MacAddress
|
||||
"""
|
||||
addr = "".join(map(lambda x: chr(int(x, 16)), s.split(":")))
|
||||
addr = "".join(chr(int(x, 16)) for x in s.split(":"))
|
||||
return cls(addr)
|
||||
|
||||
@classmethod
|
||||
|
@ -154,14 +154,14 @@ class IpAddress(object):
|
|||
logger.exception("error during addition")
|
||||
return NotImplemented
|
||||
|
||||
tmp = map(lambda x: ord(x), self.addr)
|
||||
tmp = [ord(x) for x in self.addr]
|
||||
for i in xrange(len(tmp) - 1, -1, -1):
|
||||
x = tmp[i] + carry
|
||||
tmp[i] = x & 0xff
|
||||
carry = x >> 8
|
||||
if carry == 0:
|
||||
break
|
||||
addr = "".join(map(lambda x: chr(x), tmp))
|
||||
addr = "".join(chr(x) for x in tmp)
|
||||
return self.__class__(self.af, addr)
|
||||
|
||||
def __sub__(self, other):
|
||||
|
@ -200,8 +200,8 @@ class IpAddress(object):
|
|||
:return: integer value
|
||||
:rtype: int
|
||||
"""
|
||||
bin = socket.inet_pton(AF_INET, s)
|
||||
return struct.unpack("!I", bin)[0]
|
||||
value = socket.inet_pton(AF_INET, s)
|
||||
return struct.unpack("!I", value)[0]
|
||||
|
||||
|
||||
class IpPrefix(object):
|
||||
|
|
|
@ -293,10 +293,10 @@ def file_demunge(pathname, header):
|
|||
start = None
|
||||
end = None
|
||||
|
||||
for i in range(len(lines)):
|
||||
if lines[i] == "# BEGIN %s\n" % header:
|
||||
for i, line in enumerate(lines):
|
||||
if line == "# BEGIN %s\n" % header:
|
||||
start = i
|
||||
elif lines[i] == "# END %s\n" % header:
|
||||
elif line == "# END %s\n" % header:
|
||||
end = i + 1
|
||||
|
||||
if start is None or end is None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue