LENINDEF = b"\x80" # length indefinite mark
LENINDEF_PP_CHAR = "I" if PY2 else "∞"
NAMEDTUPLE_KWARGS = {} if PY2 else {"module": __name__}
+SET01 = frozenset(("0", "1"))
+DECIMAL_SIGNS = ".,"
+
+
+def pureint(value):
+ i = int(value)
+ if (value[0] in "+- ") or (value[-1] == " "):
+ raise ValueError("non-pure integer")
+ return i
+
+def fractions2float(fractions_raw):
+ pureint(fractions_raw)
+ return float("0." + fractions_raw)
########################################################################
yield pp
-SET01 = frozenset(("0", "1"))
BitStringState = namedtuple("BitStringState", (
"version",
"specs",
), **NAMEDTUPLE_KWARGS)
-def pureint(value):
- i = int(value)
- if (value[0] in "+- ") or (value[-1] == " "):
- raise ValueError("non-pure integer")
- return i
-
-
class ObjectIdentifier(Obj):
"""``OBJECT IDENTIFIER`` OID type
LEN_YYYYMMDDHHMMSSZ = len("YYYYMMDDHHMMSSZ")
-def fractions2float(fractions_raw):
- pureint(fractions_raw)
- return float("0." + fractions_raw)
-
-
class VisibleString(CommonString):
__slots__ = ()
tag_default = tag_encode(26)
break
if len(value) == 0:
return offset, decoded
- decimal_signs = ".,"
- if value[0] in decimal_signs:
+ if value[0] in DECIMAL_SIGNS:
return offset, (
decoded + timedelta(seconds=3600 * fractions2float(value[1:]))
)
value = value[2:]
if len(value) == 0:
return offset, decoded
- if value[0] in decimal_signs:
+ if value[0] in DECIMAL_SIGNS:
return offset, (
decoded + timedelta(seconds=60 * fractions2float(value[1:]))
)
value = value[2:]
if len(value) == 0:
return offset, decoded
- if value[0] not in decimal_signs:
+ if value[0] not in DECIMAL_SIGNS:
raise ValueError("invalid format after seconds")
return offset, (
decoded + timedelta(microseconds=10**6 * fractions2float(value[1:]))