From 86cbabb3e314ac905dc35a560daf8c4aeaf6e6ff Mon Sep 17 00:00:00 2001 From: mtu <mtu@mtu> Date: Sun, 14 Feb 2016 20:31:11 +0100 Subject: [PATCH] Avoid unnecessary list creations with keys() --- scapy/asn1fields.py | 10 +++++----- scapy/layers/x509.py | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scapy/asn1fields.py b/scapy/asn1fields.py index e1fefd07..5cbaabd3 100644 --- a/scapy/asn1fields.py +++ b/scapy/asn1fields.py @@ -256,7 +256,7 @@ class ASN1F_SEQUENCE(ASN1F_field): name = "dummy_seq_name" default = [field.default for field in seq] for kwarg in ["context", "implicit_tag", "explicit_tag"]: - if kwarg in kwargs.keys(): + if kwarg in kwargs: setattr(self, kwarg, kwargs[kwarg]) else: setattr(self, kwarg, None) @@ -401,12 +401,12 @@ class ASN1F_CHOICE(ASN1F_field): holds_packets = 1 ASN1_tag = ASN1_Class_UNIVERSAL.ANY def __init__(self, name, default, *args, **kwargs): - if "implicit_tag" in kwargs.keys(): + if "implicit_tag" in kwargs: err_msg = "ASN1F_CHOICE has been called with an implicit_tag" raise ASN1_Error(err_msg) self.implicit_tag = None for kwarg in ["context", "explicit_tag"]: - if kwarg in kwargs.keys(): + if kwarg in kwargs: setattr(self, kwarg, kwargs[kwarg]) else: setattr(self, kwarg, None) @@ -419,7 +419,7 @@ class ASN1F_CHOICE(ASN1F_field): for p in args: if hasattr(p, "ASN1_root"): # should be ASN1_Packet if hasattr(p.ASN1_root, "choices"): - for k,v in p.ASN1_root.choices.items(): + for k,v in p.ASN1_root.choices.iteritems(): self.choices[k] = v # ASN1F_CHOICE recursion else: self.choices[p.ASN1_root.network_tag] = p @@ -462,7 +462,7 @@ class ASN1F_CHOICE(ASN1F_field): s = "" else: s = str(x) - if hash(type(x)) in self.pktchoices.keys(): + if hash(type(x)) in self.pktchoices: imp, exp = self.pktchoices[hash(type(x))] s = BER_tagging_enc(s, implicit_tag=imp, explicit_tag=exp) diff --git a/scapy/layers/x509.py b/scapy/layers/x509.py index 027e1d7f..fa0389a5 100644 --- a/scapy/layers/x509.py +++ b/scapy/layers/x509.py @@ -622,7 +622,7 @@ class ASN1F_EXT_SEQUENCE(ASN1F_SEQUENCE): extnID.set_val(pkt, oid) s = critical.dissect(pkt, s) encapsed = X509_ExtDefault - if oid.val in ext_mapping.keys(): + if oid.val in ext_mapping: encapsed = ext_mapping[oid.val] self.seq[2].cls = encapsed self.seq[2].cls.ASN1_root.flexible_tag = True @@ -788,10 +788,10 @@ class X509_TBSCertificate(ASN1_Packet): name_str = "" attrsDict = self.get_issuer() for attrType, attrSymbol in attrName_mapping: - if attrType in attrsDict.keys(): + if attrType in attrsDict: name_str += "/" + attrSymbol + "=" name_str += attrsDict[attrType] - for attrType in sorted(attrsDict.keys()): + for attrType in sorted(attrsDict): if attrType not in attrName_specials: name_str += "/" + attrType + "=" name_str += attrsDict[attrType] @@ -807,10 +807,10 @@ class X509_TBSCertificate(ASN1_Packet): name_str = "" attrsDict = self.get_subject() for attrType, attrSymbol in attrName_mapping: - if attrType in attrsDict.keys(): + if attrType in attrsDict: name_str += "/" + attrSymbol + "=" name_str += attrsDict[attrType] - for attrType in sorted(attrsDict.keys()): + for attrType in sorted(attrsDict): if attrType not in attrName_specials: name_str += "/" + attrType + "=" name_str += attrsDict[attrType] @@ -915,10 +915,10 @@ class X509_TBSCertList(ASN1_Packet): name_str = "" attrsDict = self.get_issuer() for attrType, attrSymbol in attrName_mapping: - if attrType in attrsDict.keys(): + if attrType in attrsDict: name_str += "/" + attrSymbol + "=" name_str += attrsDict[attrType] - for attrType in sorted(attrsDict.keys()): + for attrType in sorted(attrsDict): if attrType not in attrName_specials: name_str += "/" + attrType + "=" name_str += attrsDict[attrType] -- GitLab