Skip to content

Commit

Permalink
Merge pull request #33 from p-l-/fix-argument-set
Browse files Browse the repository at this point in the history
Rename argument / attribute "set"
  • Loading branch information
guedou committed Jan 24, 2016
2 parents d1c7e32 + e3de546 commit 6ac34c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
22 changes: 11 additions & 11 deletions scapy/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ def __iter__(self):
return iter([])

class SetGen(Gen):
def __init__(self, set, _iterpacket=1):
def __init__(self, values, _iterpacket=1):
self._iterpacket=_iterpacket
if isinstance(set, (list, BasePacketList)):
self.set = list(set)
elif (type(set) is tuple) and (2 <= len(set) <= 3) and \
all(type(i) is int for i in set):
# We use set[1] + 1 as stop value for xrange to maintain
# the behavior of using tuples as field `set`
self.set = [xrange(*((set[0], set[1] + 1) + set[2:]))]
if isinstance(values, (list, BasePacketList)):
self.values = list(values)
elif (type(values) is tuple) and (2 <= len(values) <= 3) and \
all(type(i) is int for i in values):
# We use values[1] + 1 as stop value for xrange to maintain
# the behavior of using tuples as field `values`
self.values = [xrange(*((values[0], values[1] + 1) + values[2:]))]
else:
self.set = [set]
self.values = [values]
def transf(self, element):
return element
def __iter__(self):
for i in self.set:
for i in self.values:
if (isinstance(i, Gen) and
(self._iterpacket or not isinstance(i,BasePacket))) or (
isinstance(i, (xrange, types.GeneratorType))):
Expand All @@ -44,7 +44,7 @@ def __iter__(self):
else:
yield i
def __repr__(self):
return "<SetGen %s>" % self.set.__repr__()
return "<SetGen %r>" % self.values

class Net(Gen):
"""Generate a list of IPs from a network address or a name"""
Expand Down
30 changes: 16 additions & 14 deletions scapy/tools/UTscapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ class External_Files:
0K8TKasyOhGsVamTUAZBXfQVw1zmdS4rHDnbHgtIjX3DcCt6UIr0BHTYjdV0JbPj
r1APYgXihjQwM2M83AKIhwQQJv/F3JFOFCQNsEI0QA==""")
def get_local_dict(cls):
return dict(map(lambda (x,y): (x, y.name), filter(lambda (x,y): isinstance(y, File), cls.__dict__.items())))
return dict((x, y.name) for (x, y) in cls.__dict__.iteritems()
if isinstance(y, File))
get_local_dict = classmethod(get_local_dict)
def get_URL_dict(cls):
return dict(map(lambda (x,y): (x, y.URL), filter(lambda (x,y): isinstance(y, File), cls.__dict__.items())))
return dict((x, y.URL) for (x, y) in cls.__dict__.iteritems()
if isinstance(y, File))
get_URL_dict = classmethod(get_URL_dict)


Expand Down Expand Up @@ -138,15 +140,15 @@ def all_tests(self):
class TestSet(TestClass):
def __init__(self, name):
self.name = name
self.set = []
self.tests = []
self.comments = ""
self.keywords = []
self.crc = None
self.expand = 1
def add_test(self, test):
self.set.append(test)
self.tests.append(test)
def __iter__(self):
return self.set.__iter__()
return self.tests.__iter__()

class UnitTest(TestClass):
def __init__(self, name):
Expand Down Expand Up @@ -257,8 +259,9 @@ def compute_campaign_digests(test_campaign):
def filter_tests_on_numbers(test_campaign, num):
if num:
for ts in test_campaign:
ts.set = filter(lambda t: t.num in num, ts.set)
test_campaign.campaign = filter(lambda ts: len(ts.set) > 0, test_campaign.campaign)
ts.tests = [t for t in ts.tests if t.num in num]
test_campaign.campaign = [ts for ts in test_campaign.campaign
if ts.tests]

def filter_tests_keep_on_keywords(test_campaign, kw):
def kw_match(lst, kw):
Expand All @@ -269,7 +272,7 @@ def kw_match(lst, kw):

if kw:
for ts in test_campaign:
ts.set = filter(lambda t: kw_match(t.keywords, kw), ts.set)
ts.tests = [t for t in ts.tests if kw_match(t.keywords, kw)]

def filter_tests_remove_on_keywords(test_campaign, kw):
def kw_match(lst, kw):
Expand All @@ -280,11 +283,11 @@ def kw_match(lst, kw):

if kw:
for ts in test_campaign:
ts.set = filter(lambda t: not kw_match(t.keywords, kw), ts.set)
ts.tests = [t for t in ts.tests if not kw_match(t.keywords, kw)]


def remove_empty_testsets(test_campaign):
test_campaign.campaign = filter(lambda ts: len(ts.set) > 0, test_campaign.campaign)
test_campaign.campaign = [ts for ts in test_campaign.campaign if ts.tests]


#### RUN CAMPAIGN #####
Expand Down Expand Up @@ -569,13 +572,12 @@ def main(argv):
LOCAL = 1
elif opt == "-n":
NUM = []
for v in map( lambda x: x.strip(), optarg.split(",") ):
for v in (x.strip() for x in optarg.split(",")):
try:
NUM.append(int(v))
except ValueError:
v1,v2 = map(int, v.split("-"))
for vv in xrange(v1, v2 + 1):
NUM.append(vv)
v1, v2 = map(int, v.split("-", 1))
NUM.extend(xrange(v1, v2 + 1))
elif opt == "-m":
MODULES.append(optarg)
elif opt == "-k":
Expand Down

0 comments on commit 6ac34c6

Please sign in to comment.