2 from __future__ import unicode_literals
22 import xml.etree.ElementTree
25 import collections.abc as compat_collections_abc
27 import collections as compat_collections_abc
30 import urllib.request as compat_urllib_request
31 except ImportError: # Python 2
32 import urllib2 as compat_urllib_request
35 import urllib.error as compat_urllib_error
36 except ImportError: # Python 2
37 import urllib2 as compat_urllib_error
40 import urllib.parse as compat_urllib_parse
41 except ImportError: # Python 2
42 import urllib as compat_urllib_parse
45 from urllib.parse import urlparse as compat_urllib_parse_urlparse
46 except ImportError: # Python 2
47 from urlparse import urlparse as compat_urllib_parse_urlparse
50 import urllib.parse as compat_urlparse
51 except ImportError: # Python 2
52 import urlparse as compat_urlparse
55 import urllib.response as compat_urllib_response
56 except ImportError: # Python 2
57 import urllib as compat_urllib_response
60 import http.cookiejar as compat_cookiejar
61 except ImportError: # Python 2
62 import cookielib as compat_cookiejar
64 if sys.version_info[0] == 2:
65 class compat_cookiejar_Cookie(compat_cookiejar.Cookie):
66 def __init__(self, version, name, value, *args, **kwargs):
67 if isinstance(name, compat_str):
69 if isinstance(value, compat_str):
70 value = value.encode()
71 compat_cookiejar.Cookie.__init__(self, version, name, value, *args, **kwargs)
73 compat_cookiejar_Cookie = compat_cookiejar.Cookie
76 import http.cookies as compat_cookies
77 except ImportError: # Python 2
78 import Cookie as compat_cookies
80 if sys.version_info[0] == 2:
81 class compat_cookies_SimpleCookie(compat_cookies.SimpleCookie):
82 def load(self, rawdata):
83 if isinstance(rawdata, compat_str):
84 rawdata = str(rawdata)
85 return super(compat_cookies_SimpleCookie, self).load(rawdata)
87 compat_cookies_SimpleCookie = compat_cookies.SimpleCookie
90 import html.entities as compat_html_entities
91 except ImportError: # Python 2
92 import htmlentitydefs as compat_html_entities
95 compat_html_entities_html5 = compat_html_entities.html5
96 except AttributeError:
97 # Copied from CPython 3.5.1 html/entities.py
98 compat_html_entities_html5 = {
107 'acE;': '\u223e\u0333',
121 'Afr;': '\U0001d504',
122 'afr;': '\U0001d51e',
127 'alefsym;': '\u2135',
142 'andslope;': '\u2a58',
148 'angmsdaa;': '\u29a8',
149 'angmsdab;': '\u29a9',
150 'angmsdac;': '\u29aa',
151 'angmsdad;': '\u29ab',
152 'angmsdae;': '\u29ac',
153 'angmsdaf;': '\u29ad',
154 'angmsdag;': '\u29ae',
155 'angmsdah;': '\u29af',
157 'angrtvb;': '\u22be',
158 'angrtvbd;': '\u299d',
161 'angzarr;': '\u237c',
164 'Aopf;': '\U0001d538',
165 'aopf;': '\U0001d552',
172 'ApplyFunction;': '\u2061',
174 'approxeq;': '\u224a',
179 'Ascr;': '\U0001d49c',
180 'ascr;': '\U0001d4b6',
184 'asympeq;': '\u224d',
193 'awconint;': '\u2233',
195 'backcong;': '\u224c',
196 'backepsilon;': '\u03f6',
197 'backprime;': '\u2035',
198 'backsim;': '\u223d',
199 'backsimeq;': '\u22cd',
200 'Backslash;': '\u2216',
205 'barwedge;': '\u2305',
207 'bbrktbrk;': '\u23b6',
213 'Because;': '\u2235',
214 'because;': '\u2235',
215 'bemptyv;': '\u29b0',
218 'Bernoullis;': '\u212c',
222 'between;': '\u226c',
223 'Bfr;': '\U0001d505',
224 'bfr;': '\U0001d51f',
226 'bigcirc;': '\u25ef',
228 'bigodot;': '\u2a00',
229 'bigoplus;': '\u2a01',
230 'bigotimes;': '\u2a02',
231 'bigsqcup;': '\u2a06',
232 'bigstar;': '\u2605',
233 'bigtriangledown;': '\u25bd',
234 'bigtriangleup;': '\u25b3',
235 'biguplus;': '\u2a04',
237 'bigwedge;': '\u22c0',
239 'blacklozenge;': '\u29eb',
240 'blacksquare;': '\u25aa',
241 'blacktriangle;': '\u25b4',
242 'blacktriangledown;': '\u25be',
243 'blacktriangleleft;': '\u25c2',
244 'blacktriangleright;': '\u25b8',
251 'bnequiv;': '\u2261\u20e5',
254 'Bopf;': '\U0001d539',
255 'bopf;': '\U0001d553',
278 'boxminus;': '\u229f',
279 'boxplus;': '\u229e',
280 'boxtimes;': '\u22a0',
309 'bscr;': '\U0001d4b7',
315 'bsolhsub;': '\u27c8',
328 'capbrcup;': '\u2a49',
332 'CapitalDifferentialD;': '\u2145',
333 'caps;': '\u2229\ufe00',
336 'Cayleys;': '\u212d',
346 'Cconint;': '\u2230',
348 'ccupssm;': '\u2a50',
354 'cemptyv;': '\u29b2',
357 'CenterDot;': '\xb7',
358 'centerdot;': '\xb7',
360 'cfr;': '\U0001d520',
364 'checkmark;': '\u2713',
370 'circlearrowleft;': '\u21ba',
371 'circlearrowright;': '\u21bb',
372 'circledast;': '\u229b',
373 'circledcirc;': '\u229a',
374 'circleddash;': '\u229d',
375 'CircleDot;': '\u2299',
377 'circledS;': '\u24c8',
378 'CircleMinus;': '\u2296',
379 'CirclePlus;': '\u2295',
380 'CircleTimes;': '\u2297',
383 'cirfnint;': '\u2a10',
385 'cirscir;': '\u29c2',
386 'ClockwiseContourIntegral;': '\u2232',
387 'CloseCurlyDoubleQuote;': '\u201d',
388 'CloseCurlyQuote;': '\u2019',
390 'clubsuit;': '\u2663',
395 'coloneq;': '\u2254',
400 'complement;': '\u2201',
401 'complexes;': '\u2102',
403 'congdot;': '\u2a6d',
404 'Congruent;': '\u2261',
407 'ContourIntegral;': '\u222e',
409 'copf;': '\U0001d554',
411 'Coproduct;': '\u2210',
417 'CounterClockwiseContourIntegral;': '\u2233',
421 'Cscr;': '\U0001d49e',
422 'cscr;': '\U0001d4b8',
428 'cudarrl;': '\u2938',
429 'cudarrr;': '\u2935',
433 'cularrp;': '\u293d',
436 'cupbrcap;': '\u2a48',
442 'cups;': '\u222a\ufe00',
444 'curarrm;': '\u293c',
445 'curlyeqprec;': '\u22de',
446 'curlyeqsucc;': '\u22df',
447 'curlyvee;': '\u22ce',
448 'curlywedge;': '\u22cf',
451 'curvearrowleft;': '\u21b6',
452 'curvearrowright;': '\u21b7',
455 'cwconint;': '\u2232',
467 'dbkarow;': '\u290f',
475 'ddagger;': '\u2021',
477 'DDotrahd;': '\u2911',
478 'ddotseq;': '\u2a77',
484 'demptyv;': '\u29b1',
486 'Dfr;': '\U0001d507',
487 'dfr;': '\U0001d521',
491 'DiacriticalAcute;': '\xb4',
492 'DiacriticalDot;': '\u02d9',
493 'DiacriticalDoubleAcute;': '\u02dd',
494 'DiacriticalGrave;': '`',
495 'DiacriticalTilde;': '\u02dc',
497 'Diamond;': '\u22c4',
498 'diamond;': '\u22c4',
499 'diamondsuit;': '\u2666',
502 'DifferentialD;': '\u2146',
503 'digamma;': '\u03dd',
508 'divideontimes;': '\u22c7',
515 'Dopf;': '\U0001d53b',
516 'dopf;': '\U0001d555',
521 'doteqdot;': '\u2251',
522 'DotEqual;': '\u2250',
523 'dotminus;': '\u2238',
524 'dotplus;': '\u2214',
525 'dotsquare;': '\u22a1',
526 'doublebarwedge;': '\u2306',
527 'DoubleContourIntegral;': '\u222f',
528 'DoubleDot;': '\xa8',
529 'DoubleDownArrow;': '\u21d3',
530 'DoubleLeftArrow;': '\u21d0',
531 'DoubleLeftRightArrow;': '\u21d4',
532 'DoubleLeftTee;': '\u2ae4',
533 'DoubleLongLeftArrow;': '\u27f8',
534 'DoubleLongLeftRightArrow;': '\u27fa',
535 'DoubleLongRightArrow;': '\u27f9',
536 'DoubleRightArrow;': '\u21d2',
537 'DoubleRightTee;': '\u22a8',
538 'DoubleUpArrow;': '\u21d1',
539 'DoubleUpDownArrow;': '\u21d5',
540 'DoubleVerticalBar;': '\u2225',
541 'DownArrow;': '\u2193',
542 'Downarrow;': '\u21d3',
543 'downarrow;': '\u2193',
544 'DownArrowBar;': '\u2913',
545 'DownArrowUpArrow;': '\u21f5',
546 'DownBreve;': '\u0311',
547 'downdownarrows;': '\u21ca',
548 'downharpoonleft;': '\u21c3',
549 'downharpoonright;': '\u21c2',
550 'DownLeftRightVector;': '\u2950',
551 'DownLeftTeeVector;': '\u295e',
552 'DownLeftVector;': '\u21bd',
553 'DownLeftVectorBar;': '\u2956',
554 'DownRightTeeVector;': '\u295f',
555 'DownRightVector;': '\u21c1',
556 'DownRightVectorBar;': '\u2957',
557 'DownTee;': '\u22a4',
558 'DownTeeArrow;': '\u21a7',
559 'drbkarow;': '\u2910',
562 'Dscr;': '\U0001d49f',
563 'dscr;': '\U0001d4b9',
574 'dwangle;': '\u29a6',
577 'dzigrarr;': '\u27ff',
599 'Efr;': '\U0001d508',
600 'efr;': '\U0001d522',
609 'Element;': '\u2208',
610 'elinters;': '\u23e7',
617 'emptyset;': '\u2205',
618 'EmptySmallSquare;': '\u25fb',
620 'EmptyVerySmallSquare;': '\u25ab',
629 'Eopf;': '\U0001d53c',
630 'eopf;': '\U0001d556',
635 'Epsilon;': '\u0395',
636 'epsilon;': '\u03b5',
639 'eqcolon;': '\u2255',
641 'eqslantgtr;': '\u2a96',
642 'eqslantless;': '\u2a95',
645 'EqualTilde;': '\u2242',
647 'Equilibrium;': '\u21cc',
649 'equivDD;': '\u2a78',
650 'eqvparsl;': '\u29e5',
672 'expectation;': '\u2130',
673 'ExponentialE;': '\u2147',
674 'exponentiale;': '\u2147',
675 'fallingdotseq;': '\u2252',
682 'Ffr;': '\U0001d509',
683 'ffr;': '\U0001d523',
685 'FilledSmallSquare;': '\u25fc',
686 'FilledVerySmallSquare;': '\u25aa',
692 'Fopf;': '\U0001d53d',
693 'fopf;': '\U0001d557',
698 'Fouriertrf;': '\u2131',
699 'fpartint;': '\u2a0d',
721 'fscr;': '\U0001d4bb',
743 'geqslant;': '\u2a7e',
747 'gesdoto;': '\u2a82',
748 'gesdotol;': '\u2a84',
749 'gesl;': '\u22db\ufe00',
751 'Gfr;': '\U0001d50a',
752 'gfr;': '\U0001d524',
764 'gnapprox;': '\u2a8a',
770 'Gopf;': '\U0001d53e',
771 'gopf;': '\U0001d558',
773 'GreaterEqual;': '\u2265',
774 'GreaterEqualLess;': '\u22db',
775 'GreaterFullEqual;': '\u2267',
776 'GreaterGreater;': '\u2aa2',
777 'GreaterLess;': '\u2277',
778 'GreaterSlantEqual;': '\u2a7e',
779 'GreaterTilde;': '\u2273',
780 'Gscr;': '\U0001d4a2',
794 'gtquest;': '\u2a7c',
795 'gtrapprox;': '\u2a86',
798 'gtreqless;': '\u22db',
799 'gtreqqless;': '\u2a8c',
800 'gtrless;': '\u2277',
802 'gvertneqq;': '\u2269\ufe00',
803 'gvnE;': '\u2269\ufe00',
812 'harrcir;': '\u2948',
819 'heartsuit;': '\u2665',
823 'hfr;': '\U0001d525',
824 'HilbertSpace;': '\u210b',
825 'hksearow;': '\u2925',
826 'hkswarow;': '\u2926',
829 'hookleftarrow;': '\u21a9',
830 'hookrightarrow;': '\u21aa',
832 'hopf;': '\U0001d559',
834 'HorizontalLine;': '\u2500',
836 'hscr;': '\U0001d4bd',
840 'HumpDownHump;': '\u224e',
841 'HumpEqual;': '\u224f',
862 'ifr;': '\U0001d526',
878 'ImaginaryI;': '\u2148',
879 'imagline;': '\u2110',
880 'imagpart;': '\u2111',
884 'Implies;': '\u21d2',
888 'infintie;': '\u29dd',
893 'integers;': '\u2124',
894 'Integral;': '\u222b',
895 'intercal;': '\u22ba',
896 'Intersection;': '\u22c2',
897 'intlarhk;': '\u2a17',
898 'intprod;': '\u2a3c',
899 'InvisibleComma;': '\u2063',
900 'InvisibleTimes;': '\u2062',
905 'Iopf;': '\U0001d540',
906 'iopf;': '\U0001d55a',
913 'iscr;': '\U0001d4be',
915 'isindot;': '\u22f5',
933 'Jfr;': '\U0001d50d',
934 'jfr;': '\U0001d527',
936 'Jopf;': '\U0001d541',
937 'jopf;': '\U0001d55b',
938 'Jscr;': '\U0001d4a5',
939 'jscr;': '\U0001d4bf',
951 'Kfr;': '\U0001d50e',
952 'kfr;': '\U0001d528',
958 'Kopf;': '\U0001d542',
959 'kopf;': '\U0001d55c',
960 'Kscr;': '\U0001d4a6',
961 'kscr;': '\U0001d4c0',
965 'laemptyv;': '\u29b4',
974 'Laplacetrf;': '\u2112',
981 'larrbfs;': '\u291f',
986 'larrsim;': '\u2973',
992 'lates;': '\u2aad\ufe00',
999 'lbrksld;': '\u298f',
1000 'lbrkslu;': '\u298d',
1001 'Lcaron;': '\u013d',
1002 'lcaron;': '\u013e',
1003 'Lcedil;': '\u013b',
1004 'lcedil;': '\u013c',
1011 'ldquor;': '\u201e',
1012 'ldrdhar;': '\u2967',
1013 'ldrushar;': '\u294b',
1017 'LeftAngleBracket;': '\u27e8',
1018 'LeftArrow;': '\u2190',
1019 'Leftarrow;': '\u21d0',
1020 'leftarrow;': '\u2190',
1021 'LeftArrowBar;': '\u21e4',
1022 'LeftArrowRightArrow;': '\u21c6',
1023 'leftarrowtail;': '\u21a2',
1024 'LeftCeiling;': '\u2308',
1025 'LeftDoubleBracket;': '\u27e6',
1026 'LeftDownTeeVector;': '\u2961',
1027 'LeftDownVector;': '\u21c3',
1028 'LeftDownVectorBar;': '\u2959',
1029 'LeftFloor;': '\u230a',
1030 'leftharpoondown;': '\u21bd',
1031 'leftharpoonup;': '\u21bc',
1032 'leftleftarrows;': '\u21c7',
1033 'LeftRightArrow;': '\u2194',
1034 'Leftrightarrow;': '\u21d4',
1035 'leftrightarrow;': '\u2194',
1036 'leftrightarrows;': '\u21c6',
1037 'leftrightharpoons;': '\u21cb',
1038 'leftrightsquigarrow;': '\u21ad',
1039 'LeftRightVector;': '\u294e',
1040 'LeftTee;': '\u22a3',
1041 'LeftTeeArrow;': '\u21a4',
1042 'LeftTeeVector;': '\u295a',
1043 'leftthreetimes;': '\u22cb',
1044 'LeftTriangle;': '\u22b2',
1045 'LeftTriangleBar;': '\u29cf',
1046 'LeftTriangleEqual;': '\u22b4',
1047 'LeftUpDownVector;': '\u2951',
1048 'LeftUpTeeVector;': '\u2960',
1049 'LeftUpVector;': '\u21bf',
1050 'LeftUpVectorBar;': '\u2958',
1051 'LeftVector;': '\u21bc',
1052 'LeftVectorBar;': '\u2952',
1057 'leqslant;': '\u2a7d',
1060 'lesdot;': '\u2a7f',
1061 'lesdoto;': '\u2a81',
1062 'lesdotor;': '\u2a83',
1063 'lesg;': '\u22da\ufe00',
1064 'lesges;': '\u2a93',
1065 'lessapprox;': '\u2a85',
1066 'lessdot;': '\u22d6',
1067 'lesseqgtr;': '\u22da',
1068 'lesseqqgtr;': '\u2a8b',
1069 'LessEqualGreater;': '\u22da',
1070 'LessFullEqual;': '\u2266',
1071 'LessGreater;': '\u2276',
1072 'lessgtr;': '\u2276',
1073 'LessLess;': '\u2aa1',
1074 'lesssim;': '\u2272',
1075 'LessSlantEqual;': '\u2a7d',
1076 'LessTilde;': '\u2272',
1077 'lfisht;': '\u297c',
1078 'lfloor;': '\u230a',
1079 'Lfr;': '\U0001d50f',
1080 'lfr;': '\U0001d529',
1086 'lharul;': '\u296a',
1093 'llcorner;': '\u231e',
1094 'Lleftarrow;': '\u21da',
1095 'llhard;': '\u296b',
1097 'Lmidot;': '\u013f',
1098 'lmidot;': '\u0140',
1099 'lmoust;': '\u23b0',
1100 'lmoustache;': '\u23b0',
1102 'lnapprox;': '\u2a89',
1111 'LongLeftArrow;': '\u27f5',
1112 'Longleftarrow;': '\u27f8',
1113 'longleftarrow;': '\u27f5',
1114 'LongLeftRightArrow;': '\u27f7',
1115 'Longleftrightarrow;': '\u27fa',
1116 'longleftrightarrow;': '\u27f7',
1117 'longmapsto;': '\u27fc',
1118 'LongRightArrow;': '\u27f6',
1119 'Longrightarrow;': '\u27f9',
1120 'longrightarrow;': '\u27f6',
1121 'looparrowleft;': '\u21ab',
1122 'looparrowright;': '\u21ac',
1124 'Lopf;': '\U0001d543',
1125 'lopf;': '\U0001d55d',
1126 'loplus;': '\u2a2d',
1127 'lotimes;': '\u2a34',
1128 'lowast;': '\u2217',
1130 'LowerLeftArrow;': '\u2199',
1131 'LowerRightArrow;': '\u2198',
1133 'lozenge;': '\u25ca',
1136 'lparlt;': '\u2993',
1138 'lrcorner;': '\u231f',
1140 'lrhard;': '\u296d',
1143 'lsaquo;': '\u2039',
1145 'lscr;': '\U0001d4c1',
1153 'lsquor;': '\u201a',
1154 'Lstrok;': '\u0141',
1155 'lstrok;': '\u0142',
1164 'lthree;': '\u22cb',
1165 'ltimes;': '\u22c9',
1166 'ltlarr;': '\u2976',
1167 'ltquest;': '\u2a7b',
1171 'ltrPar;': '\u2996',
1172 'lurdshar;': '\u294a',
1173 'luruhar;': '\u2966',
1174 'lvertneqq;': '\u2268\ufe00',
1175 'lvnE;': '\u2268\ufe00',
1180 'maltese;': '\u2720',
1183 'mapsto;': '\u21a6',
1184 'mapstodown;': '\u21a7',
1185 'mapstoleft;': '\u21a4',
1186 'mapstoup;': '\u21a5',
1187 'marker;': '\u25ae',
1188 'mcomma;': '\u2a29',
1193 'measuredangle;': '\u2221',
1194 'MediumSpace;': '\u205f',
1195 'Mellintrf;': '\u2133',
1196 'Mfr;': '\U0001d510',
1197 'mfr;': '\U0001d52a',
1203 'midcir;': '\u2af0',
1207 'minusb;': '\u229f',
1208 'minusd;': '\u2238',
1209 'minusdu;': '\u2a2a',
1210 'MinusPlus;': '\u2213',
1213 'mnplus;': '\u2213',
1214 'models;': '\u22a7',
1215 'Mopf;': '\U0001d544',
1216 'mopf;': '\U0001d55e',
1219 'mscr;': '\U0001d4c2',
1220 'mstpos;': '\u223e',
1223 'multimap;': '\u22b8',
1226 'Nacute;': '\u0143',
1227 'nacute;': '\u0144',
1228 'nang;': '\u2220\u20d2',
1230 'napE;': '\u2a70\u0338',
1231 'napid;': '\u224b\u0338',
1233 'napprox;': '\u2249',
1235 'natural;': '\u266e',
1236 'naturals;': '\u2115',
1239 'nbump;': '\u224e\u0338',
1240 'nbumpe;': '\u224f\u0338',
1242 'Ncaron;': '\u0147',
1243 'ncaron;': '\u0148',
1244 'Ncedil;': '\u0145',
1245 'ncedil;': '\u0146',
1247 'ncongdot;': '\u2a6d\u0338',
1253 'nearhk;': '\u2924',
1256 'nearrow;': '\u2197',
1257 'nedot;': '\u2250\u0338',
1258 'NegativeMediumSpace;': '\u200b',
1259 'NegativeThickSpace;': '\u200b',
1260 'NegativeThinSpace;': '\u200b',
1261 'NegativeVeryThinSpace;': '\u200b',
1262 'nequiv;': '\u2262',
1263 'nesear;': '\u2928',
1264 'nesim;': '\u2242\u0338',
1265 'NestedGreaterGreater;': '\u226b',
1266 'NestedLessLess;': '\u226a',
1268 'nexist;': '\u2204',
1269 'nexists;': '\u2204',
1270 'Nfr;': '\U0001d511',
1271 'nfr;': '\U0001d52b',
1272 'ngE;': '\u2267\u0338',
1275 'ngeqq;': '\u2267\u0338',
1276 'ngeqslant;': '\u2a7e\u0338',
1277 'nges;': '\u2a7e\u0338',
1278 'nGg;': '\u22d9\u0338',
1280 'nGt;': '\u226b\u20d2',
1283 'nGtv;': '\u226b\u0338',
1296 'nlE;': '\u2266\u0338',
1298 'nLeftarrow;': '\u21cd',
1299 'nleftarrow;': '\u219a',
1300 'nLeftrightarrow;': '\u21ce',
1301 'nleftrightarrow;': '\u21ae',
1303 'nleqq;': '\u2266\u0338',
1304 'nleqslant;': '\u2a7d\u0338',
1305 'nles;': '\u2a7d\u0338',
1307 'nLl;': '\u22d8\u0338',
1309 'nLt;': '\u226a\u20d2',
1312 'nltrie;': '\u22ec',
1313 'nLtv;': '\u226a\u0338',
1315 'NoBreak;': '\u2060',
1316 'NonBreakingSpace;': '\xa0',
1318 'nopf;': '\U0001d55f',
1322 'NotCongruent;': '\u2262',
1323 'NotCupCap;': '\u226d',
1324 'NotDoubleVerticalBar;': '\u2226',
1325 'NotElement;': '\u2209',
1326 'NotEqual;': '\u2260',
1327 'NotEqualTilde;': '\u2242\u0338',
1328 'NotExists;': '\u2204',
1329 'NotGreater;': '\u226f',
1330 'NotGreaterEqual;': '\u2271',
1331 'NotGreaterFullEqual;': '\u2267\u0338',
1332 'NotGreaterGreater;': '\u226b\u0338',
1333 'NotGreaterLess;': '\u2279',
1334 'NotGreaterSlantEqual;': '\u2a7e\u0338',
1335 'NotGreaterTilde;': '\u2275',
1336 'NotHumpDownHump;': '\u224e\u0338',
1337 'NotHumpEqual;': '\u224f\u0338',
1339 'notindot;': '\u22f5\u0338',
1340 'notinE;': '\u22f9\u0338',
1341 'notinva;': '\u2209',
1342 'notinvb;': '\u22f7',
1343 'notinvc;': '\u22f6',
1344 'NotLeftTriangle;': '\u22ea',
1345 'NotLeftTriangleBar;': '\u29cf\u0338',
1346 'NotLeftTriangleEqual;': '\u22ec',
1347 'NotLess;': '\u226e',
1348 'NotLessEqual;': '\u2270',
1349 'NotLessGreater;': '\u2278',
1350 'NotLessLess;': '\u226a\u0338',
1351 'NotLessSlantEqual;': '\u2a7d\u0338',
1352 'NotLessTilde;': '\u2274',
1353 'NotNestedGreaterGreater;': '\u2aa2\u0338',
1354 'NotNestedLessLess;': '\u2aa1\u0338',
1356 'notniva;': '\u220c',
1357 'notnivb;': '\u22fe',
1358 'notnivc;': '\u22fd',
1359 'NotPrecedes;': '\u2280',
1360 'NotPrecedesEqual;': '\u2aaf\u0338',
1361 'NotPrecedesSlantEqual;': '\u22e0',
1362 'NotReverseElement;': '\u220c',
1363 'NotRightTriangle;': '\u22eb',
1364 'NotRightTriangleBar;': '\u29d0\u0338',
1365 'NotRightTriangleEqual;': '\u22ed',
1366 'NotSquareSubset;': '\u228f\u0338',
1367 'NotSquareSubsetEqual;': '\u22e2',
1368 'NotSquareSuperset;': '\u2290\u0338',
1369 'NotSquareSupersetEqual;': '\u22e3',
1370 'NotSubset;': '\u2282\u20d2',
1371 'NotSubsetEqual;': '\u2288',
1372 'NotSucceeds;': '\u2281',
1373 'NotSucceedsEqual;': '\u2ab0\u0338',
1374 'NotSucceedsSlantEqual;': '\u22e1',
1375 'NotSucceedsTilde;': '\u227f\u0338',
1376 'NotSuperset;': '\u2283\u20d2',
1377 'NotSupersetEqual;': '\u2289',
1378 'NotTilde;': '\u2241',
1379 'NotTildeEqual;': '\u2244',
1380 'NotTildeFullEqual;': '\u2247',
1381 'NotTildeTilde;': '\u2249',
1382 'NotVerticalBar;': '\u2224',
1384 'nparallel;': '\u2226',
1385 'nparsl;': '\u2afd\u20e5',
1386 'npart;': '\u2202\u0338',
1387 'npolint;': '\u2a14',
1389 'nprcue;': '\u22e0',
1390 'npre;': '\u2aaf\u0338',
1392 'npreceq;': '\u2aaf\u0338',
1395 'nrarrc;': '\u2933\u0338',
1396 'nrarrw;': '\u219d\u0338',
1397 'nRightarrow;': '\u21cf',
1398 'nrightarrow;': '\u219b',
1400 'nrtrie;': '\u22ed',
1402 'nsccue;': '\u22e1',
1403 'nsce;': '\u2ab0\u0338',
1404 'Nscr;': '\U0001d4a9',
1405 'nscr;': '\U0001d4c3',
1406 'nshortmid;': '\u2224',
1407 'nshortparallel;': '\u2226',
1410 'nsimeq;': '\u2244',
1413 'nsqsube;': '\u22e2',
1414 'nsqsupe;': '\u22e3',
1416 'nsubE;': '\u2ac5\u0338',
1418 'nsubset;': '\u2282\u20d2',
1419 'nsubseteq;': '\u2288',
1420 'nsubseteqq;': '\u2ac5\u0338',
1422 'nsucceq;': '\u2ab0\u0338',
1424 'nsupE;': '\u2ac6\u0338',
1426 'nsupset;': '\u2283\u20d2',
1427 'nsupseteq;': '\u2289',
1428 'nsupseteqq;': '\u2ac6\u0338',
1435 'ntriangleleft;': '\u22ea',
1436 'ntrianglelefteq;': '\u22ec',
1437 'ntriangleright;': '\u22eb',
1438 'ntrianglerighteq;': '\u22ed',
1442 'numero;': '\u2116',
1444 'nvap;': '\u224d\u20d2',
1445 'nVDash;': '\u22af',
1446 'nVdash;': '\u22ae',
1447 'nvDash;': '\u22ad',
1448 'nvdash;': '\u22ac',
1449 'nvge;': '\u2265\u20d2',
1451 'nvHarr;': '\u2904',
1452 'nvinfin;': '\u29de',
1453 'nvlArr;': '\u2902',
1454 'nvle;': '\u2264\u20d2',
1456 'nvltrie;': '\u22b4\u20d2',
1457 'nvrArr;': '\u2903',
1458 'nvrtrie;': '\u22b5\u20d2',
1459 'nvsim;': '\u223c\u20d2',
1460 'nwarhk;': '\u2923',
1463 'nwarrow;': '\u2196',
1464 'nwnear;': '\u2927',
1478 'Odblac;': '\u0150',
1479 'odblac;': '\u0151',
1482 'odsold;': '\u29bc',
1486 'Ofr;': '\U0001d512',
1487 'ofr;': '\U0001d52c',
1499 'olcross;': '\u29bb',
1506 'Omicron;': '\u039f',
1507 'omicron;': '\u03bf',
1509 'ominus;': '\u2296',
1510 'Oopf;': '\U0001d546',
1511 'oopf;': '\U0001d560',
1513 'OpenCurlyDoubleQuote;': '\u201c',
1514 'OpenCurlyQuote;': '\u2018',
1522 'orderof;': '\u2134',
1527 'origof;': '\u22b6',
1529 'orslope;': '\u2a57',
1532 'Oscr;': '\U0001d4aa',
1543 'Otimes;': '\u2a37',
1544 'otimes;': '\u2297',
1545 'otimesas;': '\u2a36',
1551 'OverBar;': '\u203e',
1552 'OverBrace;': '\u23de',
1553 'OverBracket;': '\u23b4',
1554 'OverParenthesis;': '\u23dc',
1558 'parallel;': '\u2225',
1559 'parsim;': '\u2af3',
1562 'PartialD;': '\u2202',
1567 'permil;': '\u2030',
1569 'pertenk;': '\u2031',
1570 'Pfr;': '\U0001d513',
1571 'pfr;': '\U0001d52d',
1575 'phmmat;': '\u2133',
1579 'pitchfork;': '\u22d4',
1581 'planck;': '\u210f',
1582 'planckh;': '\u210e',
1583 'plankv;': '\u210f',
1585 'plusacir;': '\u2a23',
1587 'pluscir;': '\u2a22',
1588 'plusdo;': '\u2214',
1589 'plusdu;': '\u2a25',
1591 'PlusMinus;': '\xb1',
1594 'plussim;': '\u2a26',
1595 'plustwo;': '\u2a27',
1597 'Poincareplane;': '\u210c',
1598 'pointint;': '\u2a15',
1600 'popf;': '\U0001d561',
1610 'precapprox;': '\u2ab7',
1611 'preccurlyeq;': '\u227c',
1612 'Precedes;': '\u227a',
1613 'PrecedesEqual;': '\u2aaf',
1614 'PrecedesSlantEqual;': '\u227c',
1615 'PrecedesTilde;': '\u227e',
1616 'preceq;': '\u2aaf',
1617 'precnapprox;': '\u2ab9',
1618 'precneqq;': '\u2ab5',
1619 'precnsim;': '\u22e8',
1620 'precsim;': '\u227e',
1623 'primes;': '\u2119',
1626 'prnsim;': '\u22e8',
1628 'Product;': '\u220f',
1629 'profalar;': '\u232e',
1630 'profline;': '\u2312',
1631 'profsurf;': '\u2313',
1633 'Proportion;': '\u2237',
1634 'Proportional;': '\u221d',
1635 'propto;': '\u221d',
1637 'prurel;': '\u22b0',
1638 'Pscr;': '\U0001d4ab',
1639 'pscr;': '\U0001d4c5',
1642 'puncsp;': '\u2008',
1643 'Qfr;': '\U0001d514',
1644 'qfr;': '\U0001d52e',
1647 'qopf;': '\U0001d562',
1648 'qprime;': '\u2057',
1649 'Qscr;': '\U0001d4ac',
1650 'qscr;': '\U0001d4c6',
1651 'quaternions;': '\u210d',
1652 'quatint;': '\u2a16',
1654 'questeq;': '\u225f',
1660 'race;': '\u223d\u0331',
1661 'Racute;': '\u0154',
1662 'racute;': '\u0155',
1664 'raemptyv;': '\u29b3',
1669 'rangle;': '\u27e9',
1675 'rarrap;': '\u2975',
1677 'rarrbfs;': '\u2920',
1679 'rarrfs;': '\u291e',
1680 'rarrhk;': '\u21aa',
1681 'rarrlp;': '\u21ac',
1682 'rarrpl;': '\u2945',
1683 'rarrsim;': '\u2974',
1684 'Rarrtl;': '\u2916',
1685 'rarrtl;': '\u21a3',
1687 'rAtail;': '\u291c',
1688 'ratail;': '\u291a',
1690 'rationals;': '\u211a',
1698 'rbrksld;': '\u298e',
1699 'rbrkslu;': '\u2990',
1700 'Rcaron;': '\u0158',
1701 'rcaron;': '\u0159',
1702 'Rcedil;': '\u0156',
1703 'rcedil;': '\u0157',
1709 'rdldhar;': '\u2969',
1711 'rdquor;': '\u201d',
1715 'realine;': '\u211b',
1716 'realpart;': '\u211c',
1723 'ReverseElement;': '\u220b',
1724 'ReverseEquilibrium;': '\u21cb',
1725 'ReverseUpEquilibrium;': '\u296f',
1726 'rfisht;': '\u297d',
1727 'rfloor;': '\u230b',
1729 'rfr;': '\U0001d52f',
1733 'rharul;': '\u296c',
1737 'RightAngleBracket;': '\u27e9',
1738 'RightArrow;': '\u2192',
1739 'Rightarrow;': '\u21d2',
1740 'rightarrow;': '\u2192',
1741 'RightArrowBar;': '\u21e5',
1742 'RightArrowLeftArrow;': '\u21c4',
1743 'rightarrowtail;': '\u21a3',
1744 'RightCeiling;': '\u2309',
1745 'RightDoubleBracket;': '\u27e7',
1746 'RightDownTeeVector;': '\u295d',
1747 'RightDownVector;': '\u21c2',
1748 'RightDownVectorBar;': '\u2955',
1749 'RightFloor;': '\u230b',
1750 'rightharpoondown;': '\u21c1',
1751 'rightharpoonup;': '\u21c0',
1752 'rightleftarrows;': '\u21c4',
1753 'rightleftharpoons;': '\u21cc',
1754 'rightrightarrows;': '\u21c9',
1755 'rightsquigarrow;': '\u219d',
1756 'RightTee;': '\u22a2',
1757 'RightTeeArrow;': '\u21a6',
1758 'RightTeeVector;': '\u295b',
1759 'rightthreetimes;': '\u22cc',
1760 'RightTriangle;': '\u22b3',
1761 'RightTriangleBar;': '\u29d0',
1762 'RightTriangleEqual;': '\u22b5',
1763 'RightUpDownVector;': '\u294f',
1764 'RightUpTeeVector;': '\u295c',
1765 'RightUpVector;': '\u21be',
1766 'RightUpVectorBar;': '\u2954',
1767 'RightVector;': '\u21c0',
1768 'RightVectorBar;': '\u2953',
1770 'risingdotseq;': '\u2253',
1774 'rmoust;': '\u23b1',
1775 'rmoustache;': '\u23b1',
1782 'ropf;': '\U0001d563',
1783 'roplus;': '\u2a2e',
1784 'rotimes;': '\u2a35',
1785 'RoundImplies;': '\u2970',
1787 'rpargt;': '\u2994',
1788 'rppolint;': '\u2a12',
1790 'Rrightarrow;': '\u21db',
1791 'rsaquo;': '\u203a',
1793 'rscr;': '\U0001d4c7',
1798 'rsquor;': '\u2019',
1799 'rthree;': '\u22cc',
1800 'rtimes;': '\u22ca',
1804 'rtriltri;': '\u29ce',
1805 'RuleDelayed;': '\u29f4',
1806 'ruluhar;': '\u2968',
1808 'Sacute;': '\u015a',
1809 'sacute;': '\u015b',
1814 'Scaron;': '\u0160',
1815 'scaron;': '\u0161',
1819 'Scedil;': '\u015e',
1820 'scedil;': '\u015f',
1825 'scnsim;': '\u22e9',
1826 'scpolint;': '\u2a13',
1833 'searhk;': '\u2925',
1836 'searrow;': '\u2198',
1840 'seswar;': '\u2929',
1841 'setminus;': '\u2216',
1844 'Sfr;': '\U0001d516',
1845 'sfr;': '\U0001d530',
1846 'sfrown;': '\u2322',
1848 'SHCHcy;': '\u0429',
1849 'shchcy;': '\u0449',
1852 'ShortDownArrow;': '\u2193',
1853 'ShortLeftArrow;': '\u2190',
1854 'shortmid;': '\u2223',
1855 'shortparallel;': '\u2225',
1856 'ShortRightArrow;': '\u2192',
1857 'ShortUpArrow;': '\u2191',
1862 'sigmaf;': '\u03c2',
1863 'sigmav;': '\u03c2',
1865 'simdot;': '\u2a6a',
1873 'simplus;': '\u2a24',
1874 'simrarr;': '\u2972',
1876 'SmallCircle;': '\u2218',
1877 'smallsetminus;': '\u2216',
1878 'smashp;': '\u2a33',
1879 'smeparsl;': '\u29e4',
1884 'smtes;': '\u2aac\ufe00',
1885 'SOFTcy;': '\u042c',
1886 'softcy;': '\u044c',
1889 'solbar;': '\u233f',
1890 'Sopf;': '\U0001d54a',
1891 'sopf;': '\U0001d564',
1892 'spades;': '\u2660',
1893 'spadesuit;': '\u2660',
1896 'sqcaps;': '\u2293\ufe00',
1898 'sqcups;': '\u2294\ufe00',
1901 'sqsube;': '\u2291',
1902 'sqsubset;': '\u228f',
1903 'sqsubseteq;': '\u2291',
1905 'sqsupe;': '\u2292',
1906 'sqsupset;': '\u2290',
1907 'sqsupseteq;': '\u2292',
1909 'Square;': '\u25a1',
1910 'square;': '\u25a1',
1911 'SquareIntersection;': '\u2293',
1912 'SquareSubset;': '\u228f',
1913 'SquareSubsetEqual;': '\u2291',
1914 'SquareSuperset;': '\u2290',
1915 'SquareSupersetEqual;': '\u2292',
1916 'SquareUnion;': '\u2294',
1917 'squarf;': '\u25aa',
1920 'Sscr;': '\U0001d4ae',
1921 'sscr;': '\U0001d4c8',
1922 'ssetmn;': '\u2216',
1923 'ssmile;': '\u2323',
1924 'sstarf;': '\u22c6',
1928 'straightepsilon;': '\u03f5',
1929 'straightphi;': '\u03d5',
1933 'subdot;': '\u2abd',
1936 'subedot;': '\u2ac3',
1937 'submult;': '\u2ac1',
1940 'subplus;': '\u2abf',
1941 'subrarr;': '\u2979',
1942 'Subset;': '\u22d0',
1943 'subset;': '\u2282',
1944 'subseteq;': '\u2286',
1945 'subseteqq;': '\u2ac5',
1946 'SubsetEqual;': '\u2286',
1947 'subsetneq;': '\u228a',
1948 'subsetneqq;': '\u2acb',
1949 'subsim;': '\u2ac7',
1950 'subsub;': '\u2ad5',
1951 'subsup;': '\u2ad3',
1953 'succapprox;': '\u2ab8',
1954 'succcurlyeq;': '\u227d',
1955 'Succeeds;': '\u227b',
1956 'SucceedsEqual;': '\u2ab0',
1957 'SucceedsSlantEqual;': '\u227d',
1958 'SucceedsTilde;': '\u227f',
1959 'succeq;': '\u2ab0',
1960 'succnapprox;': '\u2aba',
1961 'succneqq;': '\u2ab6',
1962 'succnsim;': '\u22e9',
1963 'succsim;': '\u227f',
1964 'SuchThat;': '\u220b',
1976 'supdot;': '\u2abe',
1977 'supdsub;': '\u2ad8',
1980 'supedot;': '\u2ac4',
1981 'Superset;': '\u2283',
1982 'SupersetEqual;': '\u2287',
1983 'suphsol;': '\u27c9',
1984 'suphsub;': '\u2ad7',
1985 'suplarr;': '\u297b',
1986 'supmult;': '\u2ac2',
1989 'supplus;': '\u2ac0',
1990 'Supset;': '\u22d1',
1991 'supset;': '\u2283',
1992 'supseteq;': '\u2287',
1993 'supseteqq;': '\u2ac6',
1994 'supsetneq;': '\u228b',
1995 'supsetneqq;': '\u2acc',
1996 'supsim;': '\u2ac8',
1997 'supsub;': '\u2ad4',
1998 'supsup;': '\u2ad6',
1999 'swarhk;': '\u2926',
2002 'swarrow;': '\u2199',
2003 'swnwar;': '\u292a',
2007 'target;': '\u2316',
2011 'Tcaron;': '\u0164',
2012 'tcaron;': '\u0165',
2013 'Tcedil;': '\u0162',
2014 'tcedil;': '\u0163',
2018 'telrec;': '\u2315',
2019 'Tfr;': '\U0001d517',
2020 'tfr;': '\U0001d531',
2021 'there4;': '\u2234',
2022 'Therefore;': '\u2234',
2023 'therefore;': '\u2234',
2026 'thetasym;': '\u03d1',
2027 'thetav;': '\u03d1',
2028 'thickapprox;': '\u2248',
2029 'thicksim;': '\u223c',
2030 'ThickSpace;': '\u205f\u200a',
2031 'thinsp;': '\u2009',
2032 'ThinSpace;': '\u2009',
2034 'thksim;': '\u223c',
2041 'TildeEqual;': '\u2243',
2042 'TildeFullEqual;': '\u2245',
2043 'TildeTilde;': '\u2248',
2046 'timesb;': '\u22a0',
2047 'timesbar;': '\u2a31',
2048 'timesd;': '\u2a30',
2052 'topbot;': '\u2336',
2053 'topcir;': '\u2af1',
2054 'Topf;': '\U0001d54b',
2055 'topf;': '\U0001d565',
2056 'topfork;': '\u2ada',
2058 'tprime;': '\u2034',
2061 'triangle;': '\u25b5',
2062 'triangledown;': '\u25bf',
2063 'triangleleft;': '\u25c3',
2064 'trianglelefteq;': '\u22b4',
2065 'triangleq;': '\u225c',
2066 'triangleright;': '\u25b9',
2067 'trianglerighteq;': '\u22b5',
2068 'tridot;': '\u25ec',
2070 'triminus;': '\u2a3a',
2071 'TripleDot;': '\u20db',
2072 'triplus;': '\u2a39',
2074 'tritime;': '\u2a3b',
2075 'trpezium;': '\u23e2',
2076 'Tscr;': '\U0001d4af',
2077 'tscr;': '\U0001d4c9',
2082 'Tstrok;': '\u0166',
2083 'tstrok;': '\u0167',
2085 'twoheadleftarrow;': '\u219e',
2086 'twoheadrightarrow;': '\u21a0',
2094 'Uarrocir;': '\u2949',
2097 'Ubreve;': '\u016c',
2098 'ubreve;': '\u016d',
2106 'Udblac;': '\u0170',
2107 'udblac;': '\u0171',
2109 'ufisht;': '\u297e',
2110 'Ufr;': '\U0001d518',
2111 'ufr;': '\U0001d532',
2120 'ulcorn;': '\u231c',
2121 'ulcorner;': '\u231c',
2122 'ulcrop;': '\u230f',
2129 'UnderBrace;': '\u23df',
2130 'UnderBracket;': '\u23b5',
2131 'UnderParenthesis;': '\u23dd',
2133 'UnionPlus;': '\u228e',
2136 'Uopf;': '\U0001d54c',
2137 'uopf;': '\U0001d566',
2138 'UpArrow;': '\u2191',
2139 'Uparrow;': '\u21d1',
2140 'uparrow;': '\u2191',
2141 'UpArrowBar;': '\u2912',
2142 'UpArrowDownArrow;': '\u21c5',
2143 'UpDownArrow;': '\u2195',
2144 'Updownarrow;': '\u21d5',
2145 'updownarrow;': '\u2195',
2146 'UpEquilibrium;': '\u296e',
2147 'upharpoonleft;': '\u21bf',
2148 'upharpoonright;': '\u21be',
2150 'UpperLeftArrow;': '\u2196',
2151 'UpperRightArrow;': '\u2197',
2155 'Upsilon;': '\u03a5',
2156 'upsilon;': '\u03c5',
2158 'UpTeeArrow;': '\u21a5',
2159 'upuparrows;': '\u21c8',
2160 'urcorn;': '\u231d',
2161 'urcorner;': '\u231d',
2162 'urcrop;': '\u230e',
2166 'Uscr;': '\U0001d4b0',
2167 'uscr;': '\U0001d4ca',
2169 'Utilde;': '\u0168',
2170 'utilde;': '\u0169',
2178 'uwangle;': '\u29a7',
2179 'vangrt;': '\u299c',
2180 'varepsilon;': '\u03f5',
2181 'varkappa;': '\u03f0',
2182 'varnothing;': '\u2205',
2183 'varphi;': '\u03d5',
2185 'varpropto;': '\u221d',
2188 'varrho;': '\u03f1',
2189 'varsigma;': '\u03c2',
2190 'varsubsetneq;': '\u228a\ufe00',
2191 'varsubsetneqq;': '\u2acb\ufe00',
2192 'varsupsetneq;': '\u228b\ufe00',
2193 'varsupsetneqq;': '\u2acc\ufe00',
2194 'vartheta;': '\u03d1',
2195 'vartriangleleft;': '\u22b2',
2196 'vartriangleright;': '\u22b3',
2206 'Vdashl;': '\u2ae6',
2209 'veebar;': '\u22bb',
2211 'vellip;': '\u22ee',
2212 'Verbar;': '\u2016',
2216 'VerticalBar;': '\u2223',
2217 'VerticalLine;': '|',
2218 'VerticalSeparator;': '\u2758',
2219 'VerticalTilde;': '\u2240',
2220 'VeryThinSpace;': '\u200a',
2221 'Vfr;': '\U0001d519',
2222 'vfr;': '\U0001d533',
2224 'vnsub;': '\u2282\u20d2',
2225 'vnsup;': '\u2283\u20d2',
2226 'Vopf;': '\U0001d54d',
2227 'vopf;': '\U0001d567',
2230 'Vscr;': '\U0001d4b1',
2231 'vscr;': '\U0001d4cb',
2232 'vsubnE;': '\u2acb\ufe00',
2233 'vsubne;': '\u228a\ufe00',
2234 'vsupnE;': '\u2acc\ufe00',
2235 'vsupne;': '\u228b\ufe00',
2236 'Vvdash;': '\u22aa',
2237 'vzigzag;': '\u299a',
2240 'wedbar;': '\u2a5f',
2243 'wedgeq;': '\u2259',
2244 'weierp;': '\u2118',
2245 'Wfr;': '\U0001d51a',
2246 'wfr;': '\U0001d534',
2247 'Wopf;': '\U0001d54e',
2248 'wopf;': '\U0001d568',
2251 'wreath;': '\u2240',
2252 'Wscr;': '\U0001d4b2',
2253 'wscr;': '\U0001d4cc',
2258 'Xfr;': '\U0001d51b',
2259 'xfr;': '\U0001d535',
2269 'Xopf;': '\U0001d54f',
2270 'xopf;': '\U0001d569',
2271 'xoplus;': '\u2a01',
2272 'xotime;': '\u2a02',
2275 'Xscr;': '\U0001d4b3',
2276 'xscr;': '\U0001d4cd',
2277 'xsqcup;': '\u2a06',
2278 'xuplus;': '\u2a04',
2281 'xwedge;': '\u22c0',
2294 'Yfr;': '\U0001d51c',
2295 'yfr;': '\U0001d536',
2298 'Yopf;': '\U0001d550',
2299 'yopf;': '\U0001d56a',
2300 'Yscr;': '\U0001d4b4',
2301 'yscr;': '\U0001d4ce',
2307 'Zacute;': '\u0179',
2308 'zacute;': '\u017a',
2309 'Zcaron;': '\u017d',
2310 'zcaron;': '\u017e',
2315 'zeetrf;': '\u2128',
2316 'ZeroWidthSpace;': '\u200b',
2320 'zfr;': '\U0001d537',
2323 'zigrarr;': '\u21dd',
2325 'zopf;': '\U0001d56b',
2326 'Zscr;': '\U0001d4b5',
2327 'zscr;': '\U0001d4cf',
2333 import http.client as compat_http_client
2334 except ImportError: # Python 2
2335 import httplib as compat_http_client
2338 from urllib.error import HTTPError as compat_HTTPError
2339 except ImportError: # Python 2
2340 from urllib2 import HTTPError as compat_HTTPError
2343 from urllib.request import urlretrieve as compat_urlretrieve
2344 except ImportError: # Python 2
2345 from urllib import urlretrieve as compat_urlretrieve
2348 from html.parser import HTMLParser as compat_HTMLParser
2349 except ImportError: # Python 2
2350 from HTMLParser import HTMLParser as compat_HTMLParser
2353 from HTMLParser import HTMLParseError as compat_HTMLParseError
2354 except ImportError: # Python <3.4
2356 from html.parser import HTMLParseError as compat_HTMLParseError
2357 except ImportError: # Python >3.4
2359 # HTMLParseError has been deprecated in Python 3.3 and removed in
2360 # Python 3.5. Introducing dummy exception for Python >3.5 for compatible
2361 # and uniform cross-version exception handling
2362 class compat_HTMLParseError(Exception):
2366 from subprocess import DEVNULL
2367 compat_subprocess_get_DEVNULL = lambda: DEVNULL
2369 compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
2372 import http.server as compat_http_server
2374 import BaseHTTPServer as compat_http_server
2377 compat_str = unicode # Python 2
2382 from urllib.parse import unquote_to_bytes as compat_urllib_parse_unquote_to_bytes
2383 from urllib.parse import unquote as compat_urllib_parse_unquote
2384 from urllib.parse import unquote_plus as compat_urllib_parse_unquote_plus
2385 except ImportError: # Python 2
2386 _asciire = (compat_urllib_parse._asciire if hasattr(compat_urllib_parse, '_asciire')
2387 else re.compile(r'([\x00-\x7f]+)'))
2389 # HACK: The following are the correct unquote_to_bytes, unquote and unquote_plus
2390 # implementations from cpython 3.4.3's stdlib. Python 2's version
2391 # is apparently broken (see https://github.com/ytdl-org/youtube-dl/pull/6244)
2393 def compat_urllib_parse_unquote_to_bytes(string):
2394 """unquote_to_bytes('abc%20def') -> b'abc def'."""
2395 # Note: strings are encoded as UTF-8. This is only an issue if it contains
2396 # unescaped non-ASCII characters, which URIs should not.
2398 # Is it a string-like object?
2401 if isinstance(string, compat_str):
2402 string = string.encode('utf-8')
2403 bits = string.split(b'%')
2408 for item in bits[1:]:
2410 append(compat_urllib_parse._hextochr[item[:2]])
2415 return b''.join(res)
2417 def compat_urllib_parse_unquote(string, encoding='utf-8', errors='replace'):
2418 """Replace %xx escapes by their single-character equivalent. The optional
2419 encoding and errors parameters specify how to decode percent-encoded
2420 sequences into Unicode characters, as accepted by the bytes.decode()
2422 By default, percent-encoded sequences are decoded with UTF-8, and invalid
2423 sequences are replaced by a placeholder character.
2425 unquote('abc%20def') -> 'abc def'.
2427 if '%' not in string:
2430 if encoding is None:
2434 bits = _asciire.split(string)
2437 for i in range(1, len(bits), 2):
2438 append(compat_urllib_parse_unquote_to_bytes(bits[i]).decode(encoding, errors))
2442 def compat_urllib_parse_unquote_plus(string, encoding='utf-8', errors='replace'):
2443 """Like unquote(), but also replace plus signs by spaces, as required for
2444 unquoting HTML form values.
2446 unquote_plus('%7e/abc+def') -> '~/abc def'
2448 string = string.replace('+', ' ')
2449 return compat_urllib_parse_unquote(string, encoding, errors)
2452 from urllib.parse import urlencode as compat_urllib_parse_urlencode
2453 except ImportError: # Python 2
2454 # Python 2 will choke in urlencode on mixture of byte and unicode strings.
2455 # Possible solutions are to either port it from python 3 with all
2456 # the friends or manually ensure input query contains only byte strings.
2457 # We will stick with latter thus recursively encoding the whole query.
2458 def compat_urllib_parse_urlencode(query, doseq=0, encoding='utf-8'):
2460 if isinstance(e, dict):
2462 elif isinstance(e, (list, tuple,)):
2463 list_e = encode_list(e)
2464 e = tuple(list_e) if isinstance(e, tuple) else list_e
2465 elif isinstance(e, compat_str):
2466 e = e.encode(encoding)
2470 return dict((encode_elem(k), encode_elem(v)) for k, v in d.items())
2473 return [encode_elem(e) for e in l]
2475 return compat_urllib_parse.urlencode(encode_elem(query), doseq=doseq)
2478 from urllib.request import DataHandler as compat_urllib_request_DataHandler
2479 except ImportError: # Python < 3.4
2480 # Ported from CPython 98774:1733b3bd46db, Lib/urllib/request.py
2481 class compat_urllib_request_DataHandler(compat_urllib_request.BaseHandler):
2482 def data_open(self, req):
2483 # data URLs as specified in RFC 2397.
2485 # ignores POSTed data
2488 # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
2489 # mediatype := [ type "/" subtype ] *( ";" parameter )
2491 # parameter := attribute "=" value
2492 url = req.get_full_url()
2494 scheme, data = url.split(':', 1)
2495 mediatype, data = data.split(',', 1)
2497 # even base64 encoded data URLs might be quoted so unquote in any case:
2498 data = compat_urllib_parse_unquote_to_bytes(data)
2499 if mediatype.endswith(';base64'):
2500 data = binascii.a2b_base64(data)
2501 mediatype = mediatype[:-7]
2504 mediatype = 'text/plain;charset=US-ASCII'
2506 headers = email.message_from_string(
2507 'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))
2509 return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url)
2512 compat_basestring = basestring # Python 2
2514 compat_basestring = str
2517 compat_chr = unichr # Python 2
2522 from xml.etree.ElementTree import ParseError as compat_xml_parse_error
2523 except ImportError: # Python 2.6
2524 from xml.parsers.expat import ExpatError as compat_xml_parse_error
2527 etree = xml.etree.ElementTree
2530 class _TreeBuilder(etree.TreeBuilder):
2531 def doctype(self, name, pubid, system):
2536 # xml.etree.ElementTree.Element is a method in Python <=2.6 and
2537 # the following will crash with:
2538 # TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
2539 isinstance(None, xml.etree.ElementTree.Element)
2540 from xml.etree.ElementTree import Element as compat_etree_Element
2541 except TypeError: # Python <=2.6
2542 from xml.etree.ElementTree import _ElementInterface as compat_etree_Element
2544 if sys.version_info[0] >= 3:
2545 def compat_etree_fromstring(text):
2546 return etree.XML(text, parser=etree.XMLParser(target=_TreeBuilder()))
2548 # python 2.x tries to encode unicode strings with ascii (see the
2549 # XMLParser._fixtext method)
2551 _etree_iter = etree.Element.iter
2552 except AttributeError: # Python <=2.6
2553 def _etree_iter(root):
2554 for el in root.findall('*'):
2556 for sub in _etree_iter(el):
2559 # on 2.6 XML doesn't have a parser argument, function copied from CPython
2561 def _XML(text, parser=None):
2563 parser = etree.XMLParser(target=_TreeBuilder())
2565 return parser.close()
2567 def _element_factory(*args, **kwargs):
2568 el = etree.Element(*args, **kwargs)
2569 for k, v in el.items():
2570 if isinstance(v, bytes):
2571 el.set(k, v.decode('utf-8'))
2574 def compat_etree_fromstring(text):
2575 doc = _XML(text, parser=etree.XMLParser(target=_TreeBuilder(element_factory=_element_factory)))
2576 for el in _etree_iter(doc):
2577 if el.text is not None and isinstance(el.text, bytes):
2578 el.text = el.text.decode('utf-8')
2581 if hasattr(etree, 'register_namespace'):
2582 compat_etree_register_namespace = etree.register_namespace
2584 def compat_etree_register_namespace(prefix, uri):
2585 """Register a namespace prefix.
2586 The registry is global, and any existing mapping for either the
2587 given prefix or the namespace URI will be removed.
2588 *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and
2589 attributes in this namespace will be serialized with prefix if possible.
2590 ValueError is raised if prefix is reserved or is invalid.
2592 if re.match(r"ns\d+$", prefix):
2593 raise ValueError("Prefix format reserved for internal use")
2594 for k, v in list(etree._namespace_map.items()):
2595 if k == uri or v == prefix:
2596 del etree._namespace_map[k]
2597 etree._namespace_map[uri] = prefix
2599 if sys.version_info < (2, 7):
2600 # Here comes the crazy part: In 2.6, if the xpath is a unicode,
2601 # .//node does not match if a node is a direct child of . !
2602 def compat_xpath(xpath):
2603 if isinstance(xpath, compat_str):
2604 xpath = xpath.encode('ascii')
2607 compat_xpath = lambda xpath: xpath
2610 from urllib.parse import parse_qs as compat_parse_qs
2611 except ImportError: # Python 2
2612 # HACK: The following is the correct parse_qs implementation from cpython 3's stdlib.
2613 # Python 2's version is apparently totally broken
2615 def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
2616 encoding='utf-8', errors='replace'):
2617 qs, _coerce_result = qs, compat_str
2618 pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
2620 for name_value in pairs:
2621 if not name_value and not strict_parsing:
2623 nv = name_value.split('=', 1)
2626 raise ValueError('bad query field: %r' % (name_value,))
2627 # Handle case of a control-name with no equal sign
2628 if keep_blank_values:
2632 if len(nv[1]) or keep_blank_values:
2633 name = nv[0].replace('+', ' ')
2634 name = compat_urllib_parse_unquote(
2635 name, encoding=encoding, errors=errors)
2636 name = _coerce_result(name)
2637 value = nv[1].replace('+', ' ')
2638 value = compat_urllib_parse_unquote(
2639 value, encoding=encoding, errors=errors)
2640 value = _coerce_result(value)
2641 r.append((name, value))
2644 def compat_parse_qs(qs, keep_blank_values=False, strict_parsing=False,
2645 encoding='utf-8', errors='replace'):
2647 pairs = _parse_qsl(qs, keep_blank_values, strict_parsing,
2648 encoding=encoding, errors=errors)
2649 for name, value in pairs:
2650 if name in parsed_result:
2651 parsed_result[name].append(value)
2653 parsed_result[name] = [value]
2654 return parsed_result
2657 compat_os_name = os._name if os.name == 'java' else os.name
2660 if compat_os_name == 'nt':
2661 def compat_shlex_quote(s):
2662 return s if re.match(r'^[-_\w./]+$', s) else '"%s"' % s.replace('"', '\\"')
2665 from shlex import quote as compat_shlex_quote
2666 except ImportError: # Python < 3.3
2667 def compat_shlex_quote(s):
2668 if re.match(r'^[-_\w./]+$', s):
2671 return "'" + s.replace("'", "'\"'\"'") + "'"
2675 args = shlex.split('ä¸æ–‡')
2676 assert (isinstance(args, list)
2677 and isinstance(args[0], compat_str)
2678 and args[0] == 'ä¸æ–‡')
2679 compat_shlex_split = shlex.split
2680 except (AssertionError, UnicodeEncodeError):
2681 # Working around shlex issue with unicode strings on some python 2
2682 # versions (see http://bugs.python.org/issue1548891)
2683 def compat_shlex_split(s, comments=False, posix=True):
2684 if isinstance(s, compat_str):
2685 s = s.encode('utf-8')
2686 return list(map(lambda s: s.decode('utf-8'), shlex.split(s, comments, posix)))
2696 if sys.version_info >= (3, 0):
2697 compat_getenv = os.getenv
2698 compat_expanduser = os.path.expanduser
2700 def compat_setenv(key, value, env=os.environ):
2703 # Environment variables should be decoded with filesystem encoding.
2704 # Otherwise it will fail if any non-ASCII characters present (see #3854 #3217 #2918)
2706 def compat_getenv(key, default=None):
2707 from .utils import get_filesystem_encoding
2708 env = os.getenv(key, default)
2710 env = env.decode(get_filesystem_encoding())
2713 def compat_setenv(key, value, env=os.environ):
2715 from .utils import get_filesystem_encoding
2716 return v.encode(get_filesystem_encoding()) if isinstance(v, compat_str) else v
2717 env[encode(key)] = encode(value)
2719 # HACK: The default implementations of os.path.expanduser from cpython do not decode
2720 # environment variables with filesystem encoding. We will work around this by
2721 # providing adjusted implementations.
2722 # The following are os.path.expanduser implementations from cpython 2.7.8 stdlib
2723 # for different platforms with correct environment variables decoding.
2725 if compat_os_name == 'posix':
2726 def compat_expanduser(path):
2727 """Expand ~ and ~user constructions. If user or $HOME is unknown,
2729 if not path.startswith('~'):
2731 i = path.find('/', 1)
2735 if 'HOME' not in os.environ:
2737 userhome = pwd.getpwuid(os.getuid()).pw_dir
2739 userhome = compat_getenv('HOME')
2743 pwent = pwd.getpwnam(path[1:i])
2746 userhome = pwent.pw_dir
2747 userhome = userhome.rstrip('/')
2748 return (userhome + path[i:]) or '/'
2749 elif compat_os_name in ('nt', 'ce'):
2750 def compat_expanduser(path):
2751 """Expand ~ and ~user constructs.
2753 If user or $HOME is unknown, do nothing."""
2757 while i < n and path[i] not in '/\\':
2760 if 'HOME' in os.environ:
2761 userhome = compat_getenv('HOME')
2762 elif 'USERPROFILE' in os.environ:
2763 userhome = compat_getenv('USERPROFILE')
2764 elif 'HOMEPATH' not in os.environ:
2768 drive = compat_getenv('HOMEDRIVE')
2771 userhome = os.path.join(drive, compat_getenv('HOMEPATH'))
2774 userhome = os.path.join(os.path.dirname(userhome), path[1:i])
2776 return userhome + path[i:]
2778 compat_expanduser = os.path.expanduser
2781 if compat_os_name == 'nt' and sys.version_info < (3, 8):
2782 # os.path.realpath on Windows does not follow symbolic links
2783 # prior to Python 3.8 (see https://bugs.python.org/issue9949)
2784 def compat_realpath(path):
2785 while os.path.islink(path):
2786 path = os.path.abspath(os.readlink(path))
2789 compat_realpath = os.path.realpath
2792 if sys.version_info < (3, 0):
2793 def compat_print(s):
2794 from .utils import preferredencoding
2795 print(s.encode(preferredencoding(), 'xmlcharrefreplace'))
2797 def compat_print(s):
2798 assert isinstance(s, compat_str)
2802 if sys.version_info < (3, 0) and sys.platform == 'win32':
2803 def compat_getpass(prompt, *args, **kwargs):
2804 if isinstance(prompt, compat_str):
2805 from .utils import preferredencoding
2806 prompt = prompt.encode(preferredencoding())
2807 return getpass.getpass(prompt, *args, **kwargs)
2809 compat_getpass = getpass.getpass
2812 compat_input = raw_input
2813 except NameError: # Python 3
2814 compat_input = input
2816 # Python < 2.6.5 require kwargs to be bytes
2820 _testfunc(**{'x': 0})
2822 def compat_kwargs(kwargs):
2823 return dict((bytes(k), v) for k, v in kwargs.items())
2825 compat_kwargs = lambda kwargs: kwargs
2829 compat_numeric_types = (int, float, long, complex)
2830 except NameError: # Python 3
2831 compat_numeric_types = (int, float, complex)
2835 compat_integer_types = (int, long)
2836 except NameError: # Python 3
2837 compat_integer_types = (int, )
2840 if sys.version_info < (2, 7):
2841 def compat_socket_create_connection(address, timeout, source_address=None):
2842 host, port = address
2844 for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
2845 af, socktype, proto, canonname, sa = res
2848 sock = socket.socket(af, socktype, proto)
2849 sock.settimeout(timeout)
2851 sock.bind(source_address)
2854 except socket.error as _:
2856 if sock is not None:
2861 raise socket.error('getaddrinfo returns an empty list')
2863 compat_socket_create_connection = socket.create_connection
2866 # Fix https://github.com/ytdl-org/youtube-dl/issues/4223
2867 # See http://bugs.python.org/issue9161 for what is broken
2868 def workaround_optparse_bug9161():
2869 op = optparse.OptionParser()
2870 og = optparse.OptionGroup(op, 'foo')
2874 real_add_option = optparse.OptionGroup.add_option
2876 def _compat_add_option(self, *args, **kwargs):
2878 v.encode('ascii', 'replace') if isinstance(v, compat_str)
2880 bargs = [enc(a) for a in args]
2882 (k, enc(v)) for k, v in kwargs.items())
2883 return real_add_option(self, *bargs, **bkwargs)
2884 optparse.OptionGroup.add_option = _compat_add_option
2887 if hasattr(shutil, 'get_terminal_size'): # Python >= 3.3
2888 compat_get_terminal_size = shutil.get_terminal_size
2890 _terminal_size = collections.namedtuple('terminal_size', ['columns', 'lines'])
2892 def compat_get_terminal_size(fallback=(80, 24)):
2893 columns = compat_getenv('COLUMNS')
2895 columns = int(columns)
2898 lines = compat_getenv('LINES')
2904 if columns is None or lines is None or columns <= 0 or lines <= 0:
2906 sp = subprocess.Popen(
2908 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2909 out, err = sp.communicate()
2910 _lines, _columns = map(int, out.split())
2912 _columns, _lines = _terminal_size(*fallback)
2914 if columns is None or columns <= 0:
2916 if lines is None or lines <= 0:
2918 return _terminal_size(columns, lines)
2921 itertools.count(start=0, step=1)
2922 compat_itertools_count = itertools.count
2923 except TypeError: # Python 2.6
2924 def compat_itertools_count(start=0, step=1):
2930 if sys.version_info >= (3, 0):
2931 from tokenize import tokenize as compat_tokenize_tokenize
2933 from tokenize import generate_tokens as compat_tokenize_tokenize
2937 struct.pack('!I', 0)
2939 # In Python 2.6 and 2.7.x < 2.7.7, struct requires a bytes argument
2940 # See https://bugs.python.org/issue19099
2941 def compat_struct_pack(spec, *args):
2942 if isinstance(spec, compat_str):
2943 spec = spec.encode('ascii')
2944 return struct.pack(spec, *args)
2946 def compat_struct_unpack(spec, *args):
2947 if isinstance(spec, compat_str):
2948 spec = spec.encode('ascii')
2949 return struct.unpack(spec, *args)
2951 class compat_Struct(struct.Struct):
2952 def __init__(self, fmt):
2953 if isinstance(fmt, compat_str):
2954 fmt = fmt.encode('ascii')
2955 super(compat_Struct, self).__init__(fmt)
2957 compat_struct_pack = struct.pack
2958 compat_struct_unpack = struct.unpack
2959 if platform.python_implementation() == 'IronPython' and sys.version_info < (2, 7, 8):
2960 class compat_Struct(struct.Struct):
2961 def unpack(self, string):
2962 if not isinstance(string, buffer): # noqa: F821
2963 string = buffer(string) # noqa: F821
2964 return super(compat_Struct, self).unpack(string)
2966 compat_Struct = struct.Struct
2969 # compat_map/filter() returning an iterator, supposedly the
2970 # same versioning as for zip below
2972 from future_builtins import map as compat_map
2975 from itertools import imap as compat_map
2980 from future_builtins import filter as compat_filter
2983 from itertools import ifilter as compat_filter
2985 compat_filter = filter
2989 from future_builtins import zip as compat_zip
2990 except ImportError: # not 2.6+ or is 3.x
2992 from itertools import izip as compat_zip # < 2.5 or 3.x
2997 if sys.version_info < (3, 3):
2998 def compat_b64decode(s, *args, **kwargs):
2999 if isinstance(s, compat_str):
3000 s = s.encode('ascii')
3001 return base64.b64decode(s, *args, **kwargs)
3003 compat_b64decode = base64.b64decode
3006 if platform.python_implementation() == 'PyPy' and sys.pypy_version_info < (5, 4, 0):
3007 # PyPy2 prior to version 5.4.0 expects byte strings as Windows function
3008 # names, see the original PyPy issue [1] and the youtube-dl one [2].
3009 # 1. https://bitbucket.org/pypy/pypy/issues/2360/windows-ctypescdll-typeerror-function-name
3010 # 2. https://github.com/ytdl-org/youtube-dl/pull/4392
3011 def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
3012 real = ctypes.WINFUNCTYPE(*args, **kwargs)
3014 def resf(tpl, *args, **kwargs):
3016 return real((str(funcname), dll), *args, **kwargs)
3020 def compat_ctypes_WINFUNCTYPE(*args, **kwargs):
3021 return ctypes.WINFUNCTYPE(*args, **kwargs)
3025 'compat_HTMLParseError',
3026 'compat_HTMLParser',
3030 'compat_basestring',
3032 'compat_collections_abc',
3034 'compat_cookiejar_Cookie',
3036 'compat_cookies_SimpleCookie',
3037 'compat_ctypes_WINFUNCTYPE',
3038 'compat_etree_Element',
3039 'compat_etree_fromstring',
3040 'compat_etree_register_namespace',
3041 'compat_expanduser',
3043 'compat_get_terminal_size',
3046 'compat_html_entities',
3047 'compat_html_entities_html5',
3048 'compat_http_client',
3049 'compat_http_server',
3051 'compat_integer_types',
3052 'compat_itertools_count',
3055 'compat_numeric_types',
3062 'compat_shlex_quote',
3063 'compat_shlex_split',
3064 'compat_socket_create_connection',
3066 'compat_struct_pack',
3067 'compat_struct_unpack',
3068 'compat_subprocess_get_DEVNULL',
3069 'compat_tokenize_tokenize',
3070 'compat_urllib_error',
3071 'compat_urllib_parse',
3072 'compat_urllib_parse_unquote',
3073 'compat_urllib_parse_unquote_plus',
3074 'compat_urllib_parse_unquote_to_bytes',
3075 'compat_urllib_parse_urlencode',
3076 'compat_urllib_parse_urlparse',
3077 'compat_urllib_request',
3078 'compat_urllib_request_DataHandler',
3079 'compat_urllib_response',
3081 'compat_urlretrieve',
3082 'compat_xml_parse_error',
3085 'workaround_optparse_bug9161',