(s, size, errors, final=False)
| 868 | |
| 869 | |
| 870 | def PyUnicode_DecodeUTF7(s, size, errors, final=False): |
| 871 | if size == 0: |
| 872 | return [], 0 |
| 873 | |
| 874 | p = [] |
| 875 | inShift = False |
| 876 | base64bits = 0 |
| 877 | base64buffer = 0 |
| 878 | surrogate = 0 |
| 879 | startinpos = 0 |
| 880 | shiftOutStart = 0 |
| 881 | i = 0 |
| 882 | |
| 883 | while i < size: |
| 884 | ch = s[i] |
| 885 | if inShift: |
| 886 | if _IS_BASE64(ch): |
| 887 | base64buffer = (base64buffer << 6) | _FROM_BASE64(ch) |
| 888 | base64bits += 6 |
| 889 | i += 1 |
| 890 | if base64bits >= 16: |
| 891 | outCh = (base64buffer >> (base64bits - 16)) & 0xFFFF |
| 892 | base64bits -= 16 |
| 893 | base64buffer &= (1 << base64bits) - 1 |
| 894 | if surrogate: |
| 895 | if 0xDC00 <= outCh <= 0xDFFF: |
| 896 | ch2 = ( |
| 897 | 0x10000 |
| 898 | + ((surrogate - 0xD800) << 10) |
| 899 | + (outCh - 0xDC00) |
| 900 | ) |
| 901 | p.append(chr(ch2)) |
| 902 | surrogate = 0 |
| 903 | continue |
| 904 | else: |
| 905 | p.append(chr(surrogate)) |
| 906 | surrogate = 0 |
| 907 | if 0xD800 <= outCh <= 0xDBFF: |
| 908 | surrogate = outCh |
| 909 | else: |
| 910 | p.append(chr(outCh)) |
| 911 | else: |
| 912 | inShift = False |
| 913 | if base64bits > 0: |
| 914 | if base64bits >= 6: |
| 915 | i += 1 |
| 916 | errmsg = "partial character in shift sequence" |
| 917 | out, i = unicode_call_errorhandler( |
| 918 | errors, "utf-7", errmsg, s, startinpos, i |
| 919 | ) |
| 920 | p.append(out) |
| 921 | continue |
| 922 | else: |
| 923 | if base64buffer != 0: |
| 924 | i += 1 |
| 925 | errmsg = "non-zero padding bits in shift sequence" |
| 926 | out, i = unicode_call_errorhandler( |
| 927 | errors, "utf-7", errmsg, s, startinpos, i |
no test coverage detected