Replace format() with bin()

This commit is contained in:
mtu 2016-02-14 20:22:27 +01:00 committed by mtu
parent 4bc7718996
commit 6882d1123f
3 changed files with 4 additions and 4 deletions

View File

@ -263,7 +263,7 @@ class ASN1_BIT_STRING(ASN1_Object):
def __init__(self, val, readable=False):
if readable:
self.val_readable = val
val = "".join(format(ord(x), 'b').zfill(8) for x in val)
val = "".join(bin(ord(x))[2:].zfill(8) for x in val)
self.unused_bits = 0
else:
if len(val) % 8 == 0:

View File

@ -277,7 +277,7 @@ class BERcodec_BIT_STRING(BERcodec_Object):
unused_bits = ord(s[0])
if safe and unused_bits > 7:
raise BER_Decoding_Error("BERcodec_BIT_STRING: too many unused_bits advertised", remaining=s)
s = "".join(format(ord(x), 'b').zfill(8) for x in s[1:])
s = "".join(bin(ord(x))[2:].zfill(8) for x in s[1:])
if unused_bits > 0:
s = s[:-unused_bits]
return cls.tag.asn1_object(s),t

View File

@ -199,7 +199,7 @@ class ASN1F_BIT_STRING(ASN1F_field):
def __init__(self, name, default, default_readable=True, context=None,
implicit_tag=None, explicit_tag=None):
if default is not None and default_readable:
default = "".join(format(ord(x), 'b').zfill(8) for x in default)
default = "".join(bin(ord(x))[2:].zfill(8) for x in default)
ASN1F_field.__init__(self, name, default, context=context,
implicit_tag=implicit_tag,
explicit_tag=explicit_tag)
@ -522,7 +522,7 @@ class ASN1F_BIT_STRING_ENCAPS(ASN1F_BIT_STRING):
s = ""
else:
s = str(x)
s = "".join(format(ord(x),'b').zfill(8) for x in s)
s = "".join(bin(ord(x))[2:].zfill(8) for x in s)
return ASN1F_BIT_STRING.i2m(self, pkt, s)
class ASN1F_FLAGS(ASN1F_BIT_STRING):