Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/isoduration/parser/util.py: 48%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

21 statements  

1import re 

2from typing import Dict 

3 

4from isoduration.constants import PERIOD_PREFIX, TIME_PREFIX, WEEK_PREFIX 

5from isoduration.parser.exceptions import OutOfDesignators 

6 

7 

8def is_period(ch: str) -> bool: 

9 return ch == PERIOD_PREFIX 

10 

11 

12def is_time(ch: str) -> bool: 

13 return ch == TIME_PREFIX 

14 

15 

16def is_week(ch: str) -> bool: 

17 return ch == WEEK_PREFIX 

18 

19 

20def is_number(ch: str) -> bool: 

21 return bool(re.match(r"[+\-0-9.,eE]", ch)) 

22 

23 

24def is_letter(ch: str) -> bool: 

25 return ch.isalpha() and ch.lower() != "e" 

26 

27 

28def parse_designator(designators: Dict[str, str], target: str) -> str: 

29 while True: 

30 try: 

31 key, value = designators.popitem(last=False) # type: ignore 

32 except KeyError as exc: 

33 raise OutOfDesignators from exc 

34 

35 if key == target: 

36 return value