_match_abbrev(s : string, wordmap : {string : Option}) -> string Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError.
(s, wordmap)
| 1640 | |
| 1641 | |
| 1642 | def _match_abbrev(s, wordmap): |
| 1643 | """_match_abbrev(s : string, wordmap : {string : Option}) -> string |
| 1644 | |
| 1645 | Return the string key in 'wordmap' for which 's' is an unambiguous |
| 1646 | abbreviation. If 's' is found to be ambiguous or doesn't match any of |
| 1647 | 'words', raise BadOptionError. |
| 1648 | """ |
| 1649 | # Is there an exact match? |
| 1650 | if s in wordmap: |
| 1651 | return s |
| 1652 | else: |
| 1653 | # Isolate all words with s as a prefix. |
| 1654 | possibilities = [word for word in wordmap.keys() |
| 1655 | if word.startswith(s)] |
| 1656 | # No exact match, so there had better be just one possibility. |
| 1657 | if len(possibilities) == 1: |
| 1658 | return possibilities[0] |
| 1659 | elif not possibilities: |
| 1660 | raise BadOptionError(s) |
| 1661 | else: |
| 1662 | # More than one possible completion: ambiguous prefix. |
| 1663 | possibilities.sort() |
| 1664 | raise AmbiguousOptionError(s, possibilities) |
| 1665 | |
| 1666 | |
| 1667 | # Some day, there might be many Option classes. As of Optik 1.3, the |
searching dependent graphs…