MCPcopy Index your code
hub / github.com/RustPython/RustPython / PyUnicode_DecodeUTF7

Function PyUnicode_DecodeUTF7

Lib/_pycodecs.py:870–978  ·  view source on GitHub ↗
(s, size, errors, final=False)

Source from the content-addressed store, hash-verified

868
869
870def 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

Callers 1

utf_7_decodeFunction · 0.85

Calls 8

_IS_BASE64Function · 0.85
_FROM_BASE64Function · 0.85
chrFunction · 0.85
_DECODE_DIRECTFunction · 0.85
ordFunction · 0.85
lenFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected