)
-def _colorize(what, colour, with_colours, attrs=("bold",)):
+def _colourize(what, colour, with_colours, attrs=("bold",)):
return colored(what, colour, attrs=attrs) if with_colours else what
),
LENINDEF_PP_CHAR if pp.expl_lenindef else " ",
)
- cols.append(_colorize(col, "red", with_colours, ()))
+ cols.append(_colourize(col, "red", with_colours, ()))
col = "[%d,%d,%4d]%s" % (
pp.tlen,
pp.llen,
pp.vlen,
LENINDEF_PP_CHAR if pp.lenindef else " "
)
- col = _colorize(col, "green", with_colours, ())
+ col = _colourize(col, "green", with_colours, ())
cols.append(col)
if len(pp.decode_path) > 0:
cols.append(" ." * (len(pp.decode_path)))
ent = pp.decode_path[-1]
if isinstance(ent, DecodePathDefBy):
- cols.append(_colorize("DEFINED BY", "red", with_colours, ("reverse",)))
+ cols.append(_colourize("DEFINED BY", "red", with_colours, ("reverse",)))
value = str(ent.defined_by)
if (
oids is not None and
ObjectIdentifier.asn1_type_name and
value in oids
):
- cols.append(_colorize("%s:" % oids[value], "green", with_colours))
+ cols.append(_colourize("%s:" % oids[value], "green", with_colours))
else:
- cols.append(_colorize("%s:" % value, "white", with_colours, ("reverse",)))
+ cols.append(_colourize("%s:" % value, "white", with_colours, ("reverse",)))
else:
- cols.append(_colorize("%s:" % ent, "yellow", with_colours, ("reverse",)))
+ cols.append(_colourize("%s:" % ent, "yellow", with_colours, ("reverse",)))
if pp.expl is not None:
klass, _, num = pp.expl
col = "[%s%d] EXPLICIT" % (TagClassReprs[klass], num)
- cols.append(_colorize(col, "blue", with_colours))
+ cols.append(_colourize(col, "blue", with_colours))
if pp.impl is not None:
klass, _, num = pp.impl
col = "[%s%d]" % (TagClassReprs[klass], num)
- cols.append(_colorize(col, "blue", with_colours))
+ cols.append(_colourize(col, "blue", with_colours))
if pp.asn1_type_name.replace(" ", "") != pp.obj_name.upper():
- cols.append(_colorize(pp.obj_name, "magenta", with_colours))
+ cols.append(_colourize(pp.obj_name, "magenta", with_colours))
if pp.bered:
- cols.append(_colorize("BER", "red", with_colours))
- cols.append(_colorize(pp.asn1_type_name, "cyan", with_colours))
+ cols.append(_colourize("BER", "red", with_colours))
+ cols.append(_colourize(pp.asn1_type_name, "cyan", with_colours))
if pp.value is not None:
value = pp.value
- cols.append(_colorize(value, "white", with_colours, ("reverse",)))
+ cols.append(_colourize(value, "white", with_colours, ("reverse",)))
if (
oids is not None and
pp.asn1_type_name == ObjectIdentifier.asn1_type_name and
value in oids
):
- cols.append(_colorize("(%s)" % oids[value], "green", with_colours))
+ cols.append(_colourize("(%s)" % oids[value], "green", with_colours))
if with_blob:
if isinstance(pp.blob, binary_type):
cols.append(hexenc(pp.blob))
elif isinstance(pp.blob, tuple):
cols.append(", ".join(pp.blob))
if pp.optional:
- cols.append(_colorize("OPTIONAL", "red", with_colours))
+ cols.append(_colourize("OPTIONAL", "red", with_colours))
if pp.default:
- cols.append(_colorize("DEFAULT", "red", with_colours))
+ cols.append(_colourize("DEFAULT", "red", with_colours))
return " ".join(cols)
if len(value_decoded) == LEN_YYMMDDHHMMSSZ:
try:
datetime.strptime(value_decoded, self.fmt)
- except ValueError:
+ except (TypeError, ValueError):
raise DecodeError("invalid UTCTime format")
return value
else:
if len(value_decoded) == LEN_YYYYMMDDHHMMSSZ:
try:
datetime.strptime(value_decoded, self.fmt)
- except ValueError:
+ except (TypeError, ValueError):
raise DecodeError(
"invalid GeneralizedTime (without ms) format",
)
elif len(value_decoded) >= LEN_YYYYMMDDHHMMSSDMZ:
try:
datetime.strptime(value_decoded, self.fmt_ms)
- except ValueError:
+ except (TypeError, ValueError):
raise DecodeError(
"invalid GeneralizedTime (with ms) format",
)
continue
raise
- defined = get_def_by_path(ctx.get("defines", ()), sub_decode_path)
+ defined = get_def_by_path(ctx.get("_defines", ()), sub_decode_path)
if defined is not None:
defined_by, defined_spec = defined
if issubclass(value.__class__, SequenceOf):
for rel_path, schema in spec_defines:
defined = schema.get(value, None)
if defined is not None:
- ctx.setdefault("defines", []).append((
+ ctx.setdefault("_defines", []).append((
abs_decode_path(sub_decode_path[:-1], rel_path),
(value, defined),
))
vlen += value_len
v = v_tail
_value.append(value)
- obj = self.__class__(
- value=_value,
- schema=spec,
- bounds=(self._bound_min, self._bound_max),
- impl=self.tag,
- expl=self._expl,
- default=self.default,
- optional=self.optional,
- _decoded=(offset, llen, vlen + (EOC_LEN if lenindef else 0)),
- )
+ try:
+ obj = self.__class__(
+ value=_value,
+ schema=spec,
+ bounds=(self._bound_min, self._bound_max),
+ impl=self.tag,
+ expl=self._expl,
+ default=self.default,
+ optional=self.optional,
+ _decoded=(offset, llen, vlen + (EOC_LEN if lenindef else 0)),
+ )
+ except BoundsError as err:
+ raise DecodeError(
+ msg=str(err),
+ klass=self.__class__,
+ decode_path=decode_path,
+ offset=offset,
+ )
if lenindef:
if v[:EOC_LEN].tobytes() != EOC:
raise DecodeError(