File size: 819 Bytes
d1ceb73 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import re
from typing import Dict
from isoduration.constants import PERIOD_PREFIX, TIME_PREFIX, WEEK_PREFIX
from isoduration.parser.exceptions import OutOfDesignators
def is_period(ch: str) -> bool:
return ch == PERIOD_PREFIX
def is_time(ch: str) -> bool:
return ch == TIME_PREFIX
def is_week(ch: str) -> bool:
return ch == WEEK_PREFIX
def is_number(ch: str) -> bool:
return bool(re.match(r"[+\-0-9.,eE]", ch))
def is_letter(ch: str) -> bool:
return ch.isalpha() and ch.lower() != "e"
def parse_designator(designators: Dict[str, str], target: str) -> str:
while True:
try:
key, value = designators.popitem(last=False) # type: ignore
except KeyError as exc:
raise OutOfDesignators from exc
if key == target:
return value
|