Takes a string containing phone numbers separated by comma's and/or spaces and returns a list.
(*args, store_unparseable=True, prefix=False, **kwargs)
| 943 | |
| 944 | |
| 945 | def parse_phone_no(*args, store_unparseable=True, prefix=False, **kwargs): |
| 946 | """Takes a string containing phone numbers separated by comma's and/or |
| 947 | spaces and returns a list.""" |
| 948 | |
| 949 | result = [] |
| 950 | for arg in args: |
| 951 | if isinstance(arg, str) and arg: |
| 952 | result_ = ( |
| 953 | PHONE_NO_DETECTION_RE |
| 954 | if not prefix |
| 955 | else PHONE_NO_WPREFIX_DETECTION_RE |
| 956 | ).findall(arg) |
| 957 | if result_: |
| 958 | result += result_ |
| 959 | |
| 960 | elif not result_ and store_unparseable: |
| 961 | # we had content passed into us that was lost because it was |
| 962 | # so poorly formatted that it didn't even come close to |
| 963 | # meeting the regular expression we defined. We intentially |
| 964 | # keep it as part of our result set so that parsing done |
| 965 | # at a higher level can at least report this to the end user |
| 966 | # and hopefully give them some indication as to what they |
| 967 | # may have done wrong. |
| 968 | result += list(filter(bool, re.split(STRING_DELIMITERS, arg))) |
| 969 | |
| 970 | elif isinstance(arg, (set, list, tuple)): |
| 971 | # Use recursion to handle the list of phone numbers |
| 972 | result += parse_phone_no( |
| 973 | *arg, store_unparseable=store_unparseable, prefix=prefix |
| 974 | ) |
| 975 | |
| 976 | return result |
| 977 | |
| 978 | |
| 979 | def parse_call_sign(*args, store_unparseable=True, **kwargs): |
no test coverage detected
searching dependent graphs…