Commit eb424ff7 authored by Michael Büsch's avatar Michael Büsch

Use itertools.chain

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent aeab3b95
......@@ -2,7 +2,7 @@
#
# AWL simulator - common utility functions
#
# Copyright 2012-2014 Michael Buesch <m@bues.ch>
# Copyright 2012-2015 Michael Buesch <m@bues.ch>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -31,6 +31,7 @@ import random
import base64
import binascii
import functools
import itertools
class Logging(object):
......@@ -174,13 +175,6 @@ def CALL_NOEX(_callable, *args, **kwargs):
pass
return None
# Return a generator over all elements of all iterables
# passed to allElementsIn().
def allElementsIn(*iterables):
for iterable in iterables:
for element in iterable:
yield element
def strToBase64(string, ignoreErrors=False):
"""Convert a string to a base64 encoded ascii string.
Throws ValueError on errors, if ignoreErrors is False."""
......
......@@ -104,11 +104,11 @@ class S7Prog(object):
self.reset()
def reset(self):
for rawBlock in allElementsIn(self.pendingRawDBs,
self.pendingRawFBs,
self.pendingRawFCs,
self.pendingRawOBs,
self.pendingRawUDTs):
for rawBlock in itertools.chain(self.pendingRawDBs,
self.pendingRawFBs,
self.pendingRawFCs,
self.pendingRawOBs,
self.pendingRawUDTs):
rawBlock.destroySourceRef()
self.pendingRawDBs = []
self.pendingRawFBs = []
......@@ -706,9 +706,9 @@ class S7CPU(object): #+cdef
def reset(self):
self.prog.reset()
for block in allElementsIn(self.udts.values(), self.dbs.values(),
self.obs.values(), self.fcs.values(),
self.fbs.values()):
for block in itertools.chain(self.udts.values(), self.dbs.values(),
self.obs.values(), self.fcs.values(),
self.fbs.values()):
block.destroySourceRef()
self.udts = {} # UDTs
self.dbs = { # DBs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment