Skip to content
Snippets Groups Projects
Commit 86cbabb3 authored by mtu's avatar mtu Committed by mtu
Browse files

Avoid unnecessary list creations with keys()

parent 6882d112
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment