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
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
b30167aa
Commit
b30167aa
authored
9 years ago
by
Pierre LALET
Browse files
Options
Downloads
Patches
Plain Diff
Add a static __all_slots__ attribute to improve performances
parent
44d8b52b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scapy/base_classes.py
+6
-0
6 additions, 0 deletions
scapy/base_classes.py
scapy/packet.py
+2
-10
2 additions, 10 deletions
scapy/packet.py
with
8 additions
and
10 deletions
scapy/base_classes.py
+
6
−
0
View file @
b30167aa
...
@@ -181,6 +181,12 @@ class Packet_metaclass(type):
...
@@ -181,6 +181,12 @@ class Packet_metaclass(type):
if
"
name
"
in
dct
:
if
"
name
"
in
dct
:
dct
[
"
_name
"
]
=
dct
.
pop
(
"
name
"
)
dct
[
"
_name
"
]
=
dct
.
pop
(
"
name
"
)
newcls
=
super
(
Packet_metaclass
,
cls
).
__new__
(
cls
,
name
,
bases
,
dct
)
newcls
=
super
(
Packet_metaclass
,
cls
).
__new__
(
cls
,
name
,
bases
,
dct
)
newcls
.
__all_slots__
=
set
(
attr
for
cls
in
newcls
.
__mro__
if
hasattr
(
cls
,
"
__slots__
"
)
for
attr
in
cls
.
__slots__
)
if
hasattr
(
newcls
,
"
aliastypes
"
):
if
hasattr
(
newcls
,
"
aliastypes
"
):
newcls
.
aliastypes
=
[
newcls
]
+
newcls
.
aliastypes
newcls
.
aliastypes
=
[
newcls
]
+
newcls
.
aliastypes
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
scapy/packet.py
+
2
−
10
View file @
b30167aa
...
@@ -202,17 +202,9 @@ class Packet(BasePacket):
...
@@ -202,17 +202,9 @@ class Packet(BasePacket):
else
:
else
:
self
.
payload
.
setfieldval
(
attr
,
val
)
self
.
payload
.
setfieldval
(
attr
,
val
)
def
attr_in_slots
(
self
,
attr
):
"""
Return True iff `attr` belongs to the `__slots__` list of
this class or any parent class.
"""
return
any
(
attr
in
cls
.
__slots__
for
cls
in
self
.
__class__
.
__mro__
if
hasattr
(
cls
,
"
__slots__
"
))
def
__setattr__
(
self
,
attr
,
val
):
def
__setattr__
(
self
,
attr
,
val
):
if
isinstance
(
self
,
Packet
):
if
isinstance
(
self
,
Packet
):
if
self
.
attr
_
in
_slots
(
attr
)
:
if
attr
in
self
.
__all_slots__
:
return
object
.
__setattr__
(
self
,
attr
,
val
)
return
object
.
__setattr__
(
self
,
attr
,
val
)
try
:
try
:
return
self
.
setfieldval
(
attr
,
val
)
return
self
.
setfieldval
(
attr
,
val
)
...
@@ -237,7 +229,7 @@ class Packet(BasePacket):
...
@@ -237,7 +229,7 @@ class Packet(BasePacket):
if
isinstance
(
self
,
Packet
):
if
isinstance
(
self
,
Packet
):
if
attr
==
"
payload
"
:
if
attr
==
"
payload
"
:
return
self
.
remove_payload
()
return
self
.
remove_payload
()
if
self
.
attr
_
in
_slots
(
attr
)
:
if
attr
in
self
.
__all_slots__
:
return
object
.
__delattr__
(
self
,
attr
)
return
object
.
__delattr__
(
self
,
attr
)
try
:
try
:
return
self
.
delfieldval
(
attr
)
return
self
.
delfieldval
(
attr
)
...
...
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