| 961 | return add_flags, del_flags |
| 962 | |
| 963 | def fix_flags(src, flags): |
| 964 | # Check and fix flags according to the type of pattern (str or bytes) |
| 965 | if isinstance(src, str): |
| 966 | if flags & SRE_FLAG_LOCALE: |
| 967 | raise ValueError("cannot use LOCALE flag with a str pattern") |
| 968 | if not flags & SRE_FLAG_ASCII: |
| 969 | flags |= SRE_FLAG_UNICODE |
| 970 | elif flags & SRE_FLAG_UNICODE: |
| 971 | raise ValueError("ASCII and UNICODE flags are incompatible") |
| 972 | else: |
| 973 | if flags & SRE_FLAG_UNICODE: |
| 974 | raise ValueError("cannot use UNICODE flag with a bytes pattern") |
| 975 | if flags & SRE_FLAG_LOCALE and flags & SRE_FLAG_ASCII: |
| 976 | raise ValueError("ASCII and LOCALE flags are incompatible") |
| 977 | return flags |
| 978 | |
| 979 | def parse(str, flags=0, state=None): |
| 980 | # parse 're' pattern into list of (opcode, argument) tuples |