| 885 | return subpattern |
| 886 | |
| 887 | def _parse_flags(source, state, char): |
| 888 | sourceget = source.get |
| 889 | add_flags = 0 |
| 890 | del_flags = 0 |
| 891 | if char != "-": |
| 892 | while True: |
| 893 | flag = FLAGS[char] |
| 894 | if source.istext: |
| 895 | if char == 'L': |
| 896 | msg = "bad inline flags: cannot use 'L' flag with a str pattern" |
| 897 | raise source.error(msg) |
| 898 | else: |
| 899 | if char == 'u': |
| 900 | msg = "bad inline flags: cannot use 'u' flag with a bytes pattern" |
| 901 | raise source.error(msg) |
| 902 | add_flags |= flag |
| 903 | if (flag & TYPE_FLAGS) and (add_flags & TYPE_FLAGS) != flag: |
| 904 | msg = "bad inline flags: flags 'a', 'u' and 'L' are incompatible" |
| 905 | raise source.error(msg) |
| 906 | char = sourceget() |
| 907 | if char is None: |
| 908 | raise source.error("missing -, : or )") |
| 909 | if char in ")-:": |
| 910 | break |
| 911 | if char not in FLAGS: |
| 912 | msg = "unknown flag" if char.isalpha() else "missing -, : or )" |
| 913 | raise source.error(msg, len(char)) |
| 914 | if char == ")": |
| 915 | state.flags |= add_flags |
| 916 | return None |
| 917 | if add_flags & GLOBAL_FLAGS: |
| 918 | raise source.error("bad inline flags: cannot turn on global flag", 1) |
| 919 | if char == "-": |
| 920 | char = sourceget() |
| 921 | if char is None: |
| 922 | raise source.error("missing flag") |
| 923 | if char not in FLAGS: |
| 924 | msg = "unknown flag" if char.isalpha() else "missing flag" |
| 925 | raise source.error(msg, len(char)) |
| 926 | while True: |
| 927 | flag = FLAGS[char] |
| 928 | if flag & TYPE_FLAGS: |
| 929 | msg = "bad inline flags: cannot turn off flags 'a', 'u' and 'L'" |
| 930 | raise source.error(msg) |
| 931 | del_flags |= flag |
| 932 | char = sourceget() |
| 933 | if char is None: |
| 934 | raise source.error("missing :") |
| 935 | if char == ":": |
| 936 | break |
| 937 | if char not in FLAGS: |
| 938 | msg = "unknown flag" if char.isalpha() else "missing :" |
| 939 | raise source.error(msg, len(char)) |
| 940 | assert char == ":" |
| 941 | if del_flags & GLOBAL_FLAGS: |
| 942 | raise source.error("bad inline flags: cannot turn off global flag", 1) |
| 943 | if add_flags & del_flags: |
| 944 | raise source.error("bad inline flags: flag turned on and off", 1) |