summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJoe Guo <joeg@catalyst.net.nz>2018-05-10 17:11:29 +1200
committerAndrew Bartlett <abartlet@samba.org>2018-05-12 02:09:29 +0200
commit38fc8125e2728926da31555386b93a0d5acb1c0e (patch)
treec2bc8553a0c6831234ee847abe7217ffb8dcb854 /python
parentc1af6a0dada79888d3eb9c820163a6b34e900638 (diff)
downloadsamba-38fc8125e2728926da31555386b93a0d5acb1c0e.tar.gz
samba-38fc8125e2728926da31555386b93a0d5acb1c0e.tar.bz2
samba-38fc8125e2728926da31555386b93a0d5acb1c0e.zip
traffic: improve is_really_a_packet
This function will repeat on each packet. Avoid exception for getattr, which is expensive for performance. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r--python/samba/emulate/traffic.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/python/samba/emulate/traffic.py b/python/samba/emulate/traffic.py
index 08a0fa32278..503e1e4c5bf 100644
--- a/python/samba/emulate/traffic.py
+++ b/python/samba/emulate/traffic.py
@@ -273,13 +273,12 @@ class Packet(object):
return False
fn_name = 'packet_%s_%s' % (self.protocol, self.opcode)
- try:
- fn = getattr(traffic_packets, fn_name)
- if fn is traffic_packets.null_packet:
- return False
- except AttributeError:
+ fn = getattr(traffic_packets, fn_name, None)
+ if not fn:
print("missing packet %s" % fn_name, file=sys.stderr)
return False
+ if fn is traffic_packets.null_packet:
+ return False
return True