Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
96996823
Commit
96996823
authored
9 years ago
by
Guillaume Valadon
Browse files
Options
Downloads
Plain Diff
Merge pull request #21 from p-l-/feature-fields-generators
Accept generators and xrange objects as field values
parents
648951b7
2fcb18a4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
scapy/base_classes.py
+9
-7
9 additions, 7 deletions
scapy/base_classes.py
with
9 additions
and
7 deletions
scapy/base_classes.py
+
9
−
7
View file @
96996823
...
...
@@ -14,6 +14,7 @@ Generators and packet meta classes.
import
re
,
random
,
socket
import
config
import
error
import
types
class
Gen
(
object
):
def
__iter__
(
self
):
...
...
@@ -24,19 +25,20 @@ class SetGen(Gen):
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
:]))]
else
:
self
.
set
=
[
set
]
def
transf
(
self
,
element
):
return
element
def
__iter__
(
self
):
for
i
in
self
.
set
:
if
(
type
(
i
)
is
tuple
)
and
(
len
(
i
)
==
2
)
and
type
(
i
[
0
])
is
int
and
type
(
i
[
1
])
is
int
:
if
(
i
[
0
]
<=
i
[
1
]):
j
=
i
[
0
]
while
j
<=
i
[
1
]:
yield
j
j
+=
1
elif
isinstance
(
i
,
Gen
)
and
(
self
.
_iterpacket
or
not
isinstance
(
i
,
BasePacket
)):
if
(
isinstance
(
i
,
Gen
)
and
(
self
.
_iterpacket
or
not
isinstance
(
i
,
BasePacket
)))
or
(
isinstance
(
i
,
(
xrange
,
types
.
GeneratorType
))):
for
j
in
i
:
yield
j
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment