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