Parses an integer. Args: text: The text to parse. is_signed: True if a signed integer must be parsed. is_long: True if a long integer must be parsed. Returns: The integer value. Raises: ValueError: Thrown Iff the text is not a valid integer.
(text, is_signed=False, is_long=False)
| 1657 | |
| 1658 | |
| 1659 | def ParseInteger(text, is_signed=False, is_long=False): |
| 1660 | """Parses an integer. |
| 1661 | |
| 1662 | Args: |
| 1663 | text: The text to parse. |
| 1664 | is_signed: True if a signed integer must be parsed. |
| 1665 | is_long: True if a long integer must be parsed. |
| 1666 | |
| 1667 | Returns: |
| 1668 | The integer value. |
| 1669 | |
| 1670 | Raises: |
| 1671 | ValueError: Thrown Iff the text is not a valid integer. |
| 1672 | """ |
| 1673 | # Do the actual parsing. Exception handling is propagated to caller. |
| 1674 | result = _ParseAbstractInteger(text) |
| 1675 | |
| 1676 | # Check if the integer is sane. Exceptions handled by callers. |
| 1677 | checker = _INTEGER_CHECKERS[2 * int(is_long) + int(is_signed)] |
| 1678 | checker.CheckValue(result) |
| 1679 | return result |
| 1680 | |
| 1681 | |
| 1682 | def _ParseAbstractInteger(text): |