2 from __future__
import unicode_literals
22 import xml
.etree
.ElementTree
26 import urllib
.request
as compat_urllib_request
27 except ImportError: # Python 2
28 import urllib2
as compat_urllib_request
31 import urllib
.error
as compat_urllib_error
32 except ImportError: # Python 2
33 import urllib2
as compat_urllib_error
36 import urllib
.parse
as compat_urllib_parse
37 except ImportError: # Python 2
38 import urllib
as compat_urllib_parse
41 import urllib
.parse
as compat_urlparse
42 except ImportError: # Python 2
43 import urlparse
as compat_urlparse
46 from urllib
.parse
import urlparse
as compat_urllib_parse_urlparse
47 except ImportError: # Python 2
48 from urlparse
import urlparse
as compat_urllib_parse_urlparse
51 from urllib
.parse
import urlunparse
as compat_urllib_parse_urlunparse
52 except ImportError: # Python 2
53 from urlparse
import urlunparse
as compat_urllib_parse_urlunparse
56 import urllib
.response
as compat_urllib_response
57 except ImportError: # Python 2
58 import urllib
as compat_urllib_response
61 import http
.cookiejar
as compat_cookiejar
62 except ImportError: # Python 2
63 import cookielib
as compat_cookiejar
65 if sys
.version_info
[0] == 2:
66 class compat_cookiejar_Cookie(compat_cookiejar
.Cookie
):
67 def __init__(self
, version
, name
, value
, *args
, **kwargs
):
68 if isinstance(name
, compat_str
):
70 if isinstance(value
, compat_str
):
71 value
= value
.encode()
72 compat_cookiejar
.Cookie
.__init
__(self
, version
, name
, value
, *args
, **kwargs
)
74 compat_cookiejar_Cookie
= compat_cookiejar
.Cookie
77 import http
.cookies
as compat_cookies
78 except ImportError: # Python 2
79 import Cookie
as compat_cookies
82 import html
.entities
as compat_html_entities
83 except ImportError: # Python 2
84 import htmlentitydefs
as compat_html_entities
87 compat_html_entities_html5
= compat_html_entities
.html5
88 except AttributeError:
89 # Copied from CPython 3.5.1 html/entities.py
90 compat_html_entities_html5
= {
99 'acE;': '\u223e\u0333',
113 'Afr;': '\U0001d504',
114 'afr;': '\U0001d51e',
119 'alefsym;': '\u2135',
134 'andslope;': '\u2a58',
140 'angmsdaa;': '\u29a8',
141 'angmsdab;': '\u29a9',
142 'angmsdac;': '\u29aa',
143 'angmsdad;': '\u29ab',
144 'angmsdae;': '\u29ac',
145 'angmsdaf;': '\u29ad',
146 'angmsdag;': '\u29ae',
147 'angmsdah;': '\u29af',
149 'angrtvb;': '\u22be',
150 'angrtvbd;': '\u299d',
153 'angzarr;': '\u237c',
156 'Aopf;': '\U0001d538',
157 'aopf;': '\U0001d552',
164 'ApplyFunction;': '\u2061',
166 'approxeq;': '\u224a',
171 'Ascr;': '\U0001d49c',
172 'ascr;': '\U0001d4b6',
176 'asympeq;': '\u224d',
185 'awconint;': '\u2233',
187 'backcong;': '\u224c',
188 'backepsilon;': '\u03f6',
189 'backprime;': '\u2035',
190 'backsim;': '\u223d',
191 'backsimeq;': '\u22cd',
192 'Backslash;': '\u2216',
197 'barwedge;': '\u2305',
199 'bbrktbrk;': '\u23b6',
205 'Because;': '\u2235',
206 'because;': '\u2235',
207 'bemptyv;': '\u29b0',
210 'Bernoullis;': '\u212c',
214 'between;': '\u226c',
215 'Bfr;': '\U0001d505',
216 'bfr;': '\U0001d51f',
218 'bigcirc;': '\u25ef',
220 'bigodot;': '\u2a00',
221 'bigoplus;': '\u2a01',
222 'bigotimes;': '\u2a02',
223 'bigsqcup;': '\u2a06',
224 'bigstar;': '\u2605',
225 'bigtriangledown;': '\u25bd',
226 'bigtriangleup;': '\u25b3',
227 'biguplus;': '\u2a04',
229 'bigwedge;': '\u22c0',
231 'blacklozenge;': '\u29eb',
232 'blacksquare;': '\u25aa',
233 'blacktriangle;': '\u25b4',
234 'blacktriangledown;': '\u25be',
235 'blacktriangleleft;': '\u25c2',
236 'blacktriangleright;': '\u25b8',
243 'bnequiv;': '\u2261\u20e5',
246 'Bopf;': '\U0001d539',
247 'bopf;': '\U0001d553',
270 'boxminus;': '\u229f',
271 'boxplus;': '\u229e',
272 'boxtimes;': '\u22a0',
301 'bscr;': '\U0001d4b7',
307 'bsolhsub;': '\u27c8',
320 'capbrcup;': '\u2a49',
324 'CapitalDifferentialD;': '\u2145',
325 'caps;': '\u2229\ufe00',
328 'Cayleys;': '\u212d',
338 'Cconint;': '\u2230',
340 'ccupssm;': '\u2a50',
346 'cemptyv;': '\u29b2',
349 'CenterDot;': '\xb7',
350 'centerdot;': '\xb7',
352 'cfr;': '\U0001d520',
356 'checkmark;': '\u2713',
362 'circlearrowleft;': '\u21ba',
363 'circlearrowright;': '\u21bb',
364 'circledast;': '\u229b',
365 'circledcirc;': '\u229a',
366 'circleddash;': '\u229d',
367 'CircleDot;': '\u2299',
369 'circledS;': '\u24c8',
370 'CircleMinus;': '\u2296',
371 'CirclePlus;': '\u2295',
372 'CircleTimes;': '\u2297',
375 'cirfnint;': '\u2a10',
377 'cirscir;': '\u29c2',
378 'ClockwiseContourIntegral;': '\u2232',
379 'CloseCurlyDoubleQuote;': '\u201d',
380 'CloseCurlyQuote;': '\u2019',
382 'clubsuit;': '\u2663',
387 'coloneq;': '\u2254',
392 'complement;': '\u2201',
393 'complexes;': '\u2102',
395 'congdot;': '\u2a6d',
396 'Congruent;': '\u2261',
399 'ContourIntegral;': '\u222e',
401 'copf;': '\U0001d554',
403 'Coproduct;': '\u2210',
409 'CounterClockwiseContourIntegral;': '\u2233',
413 'Cscr;': '\U0001d49e',
414 'cscr;': '\U0001d4b8',
420 'cudarrl;': '\u2938',
421 'cudarrr;': '\u2935',
425 'cularrp;': '\u293d',
428 'cupbrcap;': '\u2a48',
434 'cups;': '\u222a\ufe00',
436 'curarrm;': '\u293c',
437 'curlyeqprec;': '\u22de',
438 'curlyeqsucc;': '\u22df',
439 'curlyvee;': '\u22ce',
440 'curlywedge;': '\u22cf',
443 'curvearrowleft;': '\u21b6',
444 'curvearrowright;': '\u21b7',
447 'cwconint;': '\u2232',
459 'dbkarow;': '\u290f',
467 'ddagger;': '\u2021',
469 'DDotrahd;': '\u2911',
470 'ddotseq;': '\u2a77',
476 'demptyv;': '\u29b1',
478 'Dfr;': '\U0001d507',
479 'dfr;': '\U0001d521',
483 'DiacriticalAcute;': '\xb4',
484 'DiacriticalDot;': '\u02d9',
485 'DiacriticalDoubleAcute;': '\u02dd',
486 'DiacriticalGrave;': '`',
487 'DiacriticalTilde;': '\u02dc',
489 'Diamond;': '\u22c4',
490 'diamond;': '\u22c4',
491 'diamondsuit;': '\u2666',
494 'DifferentialD;': '\u2146',
495 'digamma;': '\u03dd',
500 'divideontimes;': '\u22c7',
507 'Dopf;': '\U0001d53b',
508 'dopf;': '\U0001d555',
513 'doteqdot;': '\u2251',
514 'DotEqual;': '\u2250',
515 'dotminus;': '\u2238',
516 'dotplus;': '\u2214',
517 'dotsquare;': '\u22a1',
518 'doublebarwedge;': '\u2306',
519 'DoubleContourIntegral;': '\u222f',
520 'DoubleDot;': '\xa8',
521 'DoubleDownArrow;': '\u21d3',
522 'DoubleLeftArrow;': '\u21d0',
523 'DoubleLeftRightArrow;': '\u21d4',
524 'DoubleLeftTee;': '\u2ae4',
525 'DoubleLongLeftArrow;': '\u27f8',
526 'DoubleLongLeftRightArrow;': '\u27fa',
527 'DoubleLongRightArrow;': '\u27f9',
528 'DoubleRightArrow;': '\u21d2',
529 'DoubleRightTee;': '\u22a8',
530 'DoubleUpArrow;': '\u21d1',
531 'DoubleUpDownArrow;': '\u21d5',
532 'DoubleVerticalBar;': '\u2225',
533 'DownArrow;': '\u2193',
534 'Downarrow;': '\u21d3',
535 'downarrow;': '\u2193',
536 'DownArrowBar;': '\u2913',
537 'DownArrowUpArrow;': '\u21f5',
538 'DownBreve;': '\u0311',
539 'downdownarrows;': '\u21ca',
540 'downharpoonleft;': '\u21c3',
541 'downharpoonright;': '\u21c2',
542 'DownLeftRightVector;': '\u2950',
543 'DownLeftTeeVector;': '\u295e',
544 'DownLeftVector;': '\u21bd',
545 'DownLeftVectorBar;': '\u2956',
546 'DownRightTeeVector;': '\u295f',
547 'DownRightVector;': '\u21c1',
548 'DownRightVectorBar;': '\u2957',
549 'DownTee;': '\u22a4',
550 'DownTeeArrow;': '\u21a7',
551 'drbkarow;': '\u2910',
554 'Dscr;': '\U0001d49f',
555 'dscr;': '\U0001d4b9',
566 'dwangle;': '\u29a6',
569 'dzigrarr;': '\u27ff',
591 'Efr;': '\U0001d508',
592 'efr;': '\U0001d522',
601 'Element;': '\u2208',
602 'elinters;': '\u23e7',
609 'emptyset;': '\u2205',
610 'EmptySmallSquare;': '\u25fb',
612 'EmptyVerySmallSquare;': '\u25ab',
621 'Eopf;': '\U0001d53c',
622 'eopf;': '\U0001d556',
627 'Epsilon;': '\u0395',
628 'epsilon;': '\u03b5',
631 'eqcolon;': '\u2255',
633 'eqslantgtr;': '\u2a96',
634 'eqslantless;': '\u2a95',
637 'EqualTilde;': '\u2242',
639 'Equilibrium;': '\u21cc',
641 'equivDD;': '\u2a78',
642 'eqvparsl;': '\u29e5',
664 'expectation;': '\u2130',
665 'ExponentialE;': '\u2147',
666 'exponentiale;': '\u2147',
667 'fallingdotseq;': '\u2252',
674 'Ffr;': '\U0001d509',
675 'ffr;': '\U0001d523',
677 'FilledSmallSquare;': '\u25fc',
678 'FilledVerySmallSquare;': '\u25aa',
684 'Fopf;': '\U0001d53d',
685 'fopf;': '\U0001d557',
690 'Fouriertrf;': '\u2131',
691 'fpartint;': '\u2a0d',
713 'fscr;': '\U0001d4bb',
735 'geqslant;': '\u2a7e',
739 'gesdoto;': '\u2a82',
740 'gesdotol;': '\u2a84',
741 'gesl;': '\u22db\ufe00',
743 'Gfr;': '\U0001d50a',
744 'gfr;': '\U0001d524',
756 'gnapprox;': '\u2a8a',
762 'Gopf;': '\U0001d53e',
763 'gopf;': '\U0001d558',
765 'GreaterEqual;': '\u2265',
766 'GreaterEqualLess;': '\u22db',
767 'GreaterFullEqual;': '\u2267',
768 'GreaterGreater;': '\u2aa2',
769 'GreaterLess;': '\u2277',
770 'GreaterSlantEqual;': '\u2a7e',
771 'GreaterTilde;': '\u2273',
772 'Gscr;': '\U0001d4a2',
786 'gtquest;': '\u2a7c',
787 'gtrapprox;': '\u2a86',
790 'gtreqless;': '\u22db',
791 'gtreqqless;': '\u2a8c',
792 'gtrless;': '\u2277',
794 'gvertneqq;': '\u2269\ufe00',
795 'gvnE;': '\u2269\ufe00',
804 'harrcir;': '\u2948',
811 'heartsuit;': '\u2665',
815 'hfr;': '\U0001d525',
816 'HilbertSpace;': '\u210b',
817 'hksearow;': '\u2925',
818 'hkswarow;': '\u2926',
821 'hookleftarrow;': '\u21a9',
822 'hookrightarrow;': '\u21aa',
824 'hopf;': '\U0001d559',
826 'HorizontalLine;': '\u2500',
828 'hscr;': '\U0001d4bd',
832 'HumpDownHump;': '\u224e',
833 'HumpEqual;': '\u224f',
854 'ifr;': '\U0001d526',
870 'ImaginaryI;': '\u2148',
871 'imagline;': '\u2110',
872 'imagpart;': '\u2111',
876 'Implies;': '\u21d2',
880 'infintie;': '\u29dd',
885 'integers;': '\u2124',
886 'Integral;': '\u222b',
887 'intercal;': '\u22ba',
888 'Intersection;': '\u22c2',
889 'intlarhk;': '\u2a17',
890 'intprod;': '\u2a3c',
891 'InvisibleComma;': '\u2063',
892 'InvisibleTimes;': '\u2062',
897 'Iopf;': '\U0001d540',
898 'iopf;': '\U0001d55a',
905 'iscr;': '\U0001d4be',
907 'isindot;': '\u22f5',
925 'Jfr;': '\U0001d50d',
926 'jfr;': '\U0001d527',
928 'Jopf;': '\U0001d541',
929 'jopf;': '\U0001d55b',
930 'Jscr;': '\U0001d4a5',
931 'jscr;': '\U0001d4bf',
943 'Kfr;': '\U0001d50e',
944 'kfr;': '\U0001d528',
950 'Kopf;': '\U0001d542',
951 'kopf;': '\U0001d55c',
952 'Kscr;': '\U0001d4a6',
953 'kscr;': '\U0001d4c0',
957 'laemptyv;': '\u29b4',
966 'Laplacetrf;': '\u2112',
973 'larrbfs;': '\u291f',
978 'larrsim;': '\u2973',
984 'lates;': '\u2aad\ufe00',
991 'lbrksld;': '\u298f',
992 'lbrkslu;': '\u298d',
1003 'ldquor;': '\u201e',
1004 'ldrdhar;': '\u2967',
1005 'ldrushar;': '\u294b',
1009 'LeftAngleBracket;': '\u27e8',
1010 'LeftArrow;': '\u2190',
1011 'Leftarrow;': '\u21d0',
1012 'leftarrow;': '\u2190',
1013 'LeftArrowBar;': '\u21e4',
1014 'LeftArrowRightArrow;': '\u21c6',
1015 'leftarrowtail;': '\u21a2',
1016 'LeftCeiling;': '\u2308',
1017 'LeftDoubleBracket;': '\u27e6',
1018 'LeftDownTeeVector;': '\u2961',
1019 'LeftDownVector;': '\u21c3',
1020 'LeftDownVectorBar;': '\u2959',
1021 'LeftFloor;': '\u230a',
1022 'leftharpoondown;': '\u21bd',
1023 'leftharpoonup;': '\u21bc',
1024 'leftleftarrows;': '\u21c7',
1025 'LeftRightArrow;': '\u2194',
1026 'Leftrightarrow;': '\u21d4',
1027 'leftrightarrow;': '\u2194',
1028 'leftrightarrows;': '\u21c6',
1029 'leftrightharpoons;': '\u21cb',
1030 'leftrightsquigarrow;': '\u21ad',
1031 'LeftRightVector;': '\u294e',
1032 'LeftTee;': '\u22a3',
1033 'LeftTeeArrow;': '\u21a4',
1034 'LeftTeeVector;': '\u295a',
1035 'leftthreetimes;': '\u22cb',
1036 'LeftTriangle;': '\u22b2',
1037 'LeftTriangleBar;': '\u29cf',
1038 'LeftTriangleEqual;': '\u22b4',
1039 'LeftUpDownVector;': '\u2951',
1040 'LeftUpTeeVector;': '\u2960',
1041 'LeftUpVector;': '\u21bf',
1042 'LeftUpVectorBar;': '\u2958',
1043 'LeftVector;': '\u21bc',
1044 'LeftVectorBar;': '\u2952',
1049 'leqslant;': '\u2a7d',
1052 'lesdot;': '\u2a7f',
1053 'lesdoto;': '\u2a81',
1054 'lesdotor;': '\u2a83',
1055 'lesg;': '\u22da\ufe00',
1056 'lesges;': '\u2a93',
1057 'lessapprox;': '\u2a85',
1058 'lessdot;': '\u22d6',
1059 'lesseqgtr;': '\u22da',
1060 'lesseqqgtr;': '\u2a8b',
1061 'LessEqualGreater;': '\u22da',
1062 'LessFullEqual;': '\u2266',
1063 'LessGreater;': '\u2276',
1064 'lessgtr;': '\u2276',
1065 'LessLess;': '\u2aa1',
1066 'lesssim;': '\u2272',
1067 'LessSlantEqual;': '\u2a7d',
1068 'LessTilde;': '\u2272',
1069 'lfisht;': '\u297c',
1070 'lfloor;': '\u230a',
1071 'Lfr;': '\U0001d50f',
1072 'lfr;': '\U0001d529',
1078 'lharul;': '\u296a',
1085 'llcorner;': '\u231e',
1086 'Lleftarrow;': '\u21da',
1087 'llhard;': '\u296b',
1089 'Lmidot;': '\u013f',
1090 'lmidot;': '\u0140',
1091 'lmoust;': '\u23b0',
1092 'lmoustache;': '\u23b0',
1094 'lnapprox;': '\u2a89',
1103 'LongLeftArrow;': '\u27f5',
1104 'Longleftarrow;': '\u27f8',
1105 'longleftarrow;': '\u27f5',
1106 'LongLeftRightArrow;': '\u27f7',
1107 'Longleftrightarrow;': '\u27fa',
1108 'longleftrightarrow;': '\u27f7',
1109 'longmapsto;': '\u27fc',
1110 'LongRightArrow;': '\u27f6',
1111 'Longrightarrow;': '\u27f9',
1112 'longrightarrow;': '\u27f6',
1113 'looparrowleft;': '\u21ab',
1114 'looparrowright;': '\u21ac',
1116 'Lopf;': '\U0001d543',
1117 'lopf;': '\U0001d55d',
1118 'loplus;': '\u2a2d',
1119 'lotimes;': '\u2a34',
1120 'lowast;': '\u2217',
1122 'LowerLeftArrow;': '\u2199',
1123 'LowerRightArrow;': '\u2198',
1125 'lozenge;': '\u25ca',
1128 'lparlt;': '\u2993',
1130 'lrcorner;': '\u231f',
1132 'lrhard;': '\u296d',
1135 'lsaquo;': '\u2039',
1137 'lscr;': '\U0001d4c1',
1145 'lsquor;': '\u201a',
1146 'Lstrok;': '\u0141',
1147 'lstrok;': '\u0142',
1156 'lthree;': '\u22cb',
1157 'ltimes;': '\u22c9',
1158 'ltlarr;': '\u2976',
1159 'ltquest;': '\u2a7b',
1163 'ltrPar;': '\u2996',
1164 'lurdshar;': '\u294a',
1165 'luruhar;': '\u2966',
1166 'lvertneqq;': '\u2268\ufe00',
1167 'lvnE;': '\u2268\ufe00',
1172 'maltese;': '\u2720',
1175 'mapsto;': '\u21a6',
1176 'mapstodown;': '\u21a7',
1177 'mapstoleft;': '\u21a4',
1178 'mapstoup;': '\u21a5',
1179 'marker;': '\u25ae',
1180 'mcomma;': '\u2a29',
1185 'measuredangle;': '\u2221',
1186 'MediumSpace;': '\u205f',
1187 'Mellintrf;': '\u2133',
1188 'Mfr;': '\U0001d510',
1189 'mfr;': '\U0001d52a',
1195 'midcir;': '\u2af0',
1199 'minusb;': '\u229f',
1200 'minusd;': '\u2238',
1201 'minusdu;': '\u2a2a',
1202 'MinusPlus;': '\u2213',
1205 'mnplus;': '\u2213',
1206 'models;': '\u22a7',
1207 'Mopf;': '\U0001d544',
1208 'mopf;': '\U0001d55e',
1211 'mscr;': '\U0001d4c2',
1212 'mstpos;': '\u223e',
1215 'multimap;': '\u22b8',
1218 'Nacute;': '\u0143',
1219 'nacute;': '\u0144',
1220 'nang;': '\u2220\u20d2',
1222 'napE;': '\u2a70\u0338',
1223 'napid;': '\u224b\u0338',
1225 'napprox;': '\u2249',
1227 'natural;': '\u266e',
1228 'naturals;': '\u2115',
1231 'nbump;': '\u224e\u0338',
1232 'nbumpe;': '\u224f\u0338',
1234 'Ncaron;': '\u0147',
1235 'ncaron;': '\u0148',
1236 'Ncedil;': '\u0145',
1237 'ncedil;': '\u0146',
1239 'ncongdot;': '\u2a6d\u0338',
1245 'nearhk;': '\u2924',
1248 'nearrow;': '\u2197',
1249 'nedot;': '\u2250\u0338',
1250 'NegativeMediumSpace;': '\u200b',
1251 'NegativeThickSpace;': '\u200b',
1252 'NegativeThinSpace;': '\u200b',
1253 'NegativeVeryThinSpace;': '\u200b',
1254 'nequiv;': '\u2262',
1255 'nesear;': '\u2928',
1256 'nesim;': '\u2242\u0338',
1257 'NestedGreaterGreater;': '\u226b',
1258 'NestedLessLess;': '\u226a',
1260 'nexist;': '\u2204',
1261 'nexists;': '\u2204',
1262 'Nfr;': '\U0001d511',
1263 'nfr;': '\U0001d52b',
1264 'ngE;': '\u2267\u0338',
1267 'ngeqq;': '\u2267\u0338',
1268 'ngeqslant;': '\u2a7e\u0338',
1269 'nges;': '\u2a7e\u0338',
1270 'nGg;': '\u22d9\u0338',
1272 'nGt;': '\u226b\u20d2',
1275 'nGtv;': '\u226b\u0338',
1288 'nlE;': '\u2266\u0338',
1290 'nLeftarrow;': '\u21cd',
1291 'nleftarrow;': '\u219a',
1292 'nLeftrightarrow;': '\u21ce',
1293 'nleftrightarrow;': '\u21ae',
1295 'nleqq;': '\u2266\u0338',
1296 'nleqslant;': '\u2a7d\u0338',
1297 'nles;': '\u2a7d\u0338',
1299 'nLl;': '\u22d8\u0338',
1301 'nLt;': '\u226a\u20d2',
1304 'nltrie;': '\u22ec',
1305 'nLtv;': '\u226a\u0338',
1307 'NoBreak;': '\u2060',
1308 'NonBreakingSpace;': '\xa0',
1310 'nopf;': '\U0001d55f',
1314 'NotCongruent;': '\u2262',
1315 'NotCupCap;': '\u226d',
1316 'NotDoubleVerticalBar;': '\u2226',
1317 'NotElement;': '\u2209',
1318 'NotEqual;': '\u2260',
1319 'NotEqualTilde;': '\u2242\u0338',
1320 'NotExists;': '\u2204',
1321 'NotGreater;': '\u226f',
1322 'NotGreaterEqual;': '\u2271',
1323 'NotGreaterFullEqual;': '\u2267\u0338',
1324 'NotGreaterGreater;': '\u226b\u0338',
1325 'NotGreaterLess;': '\u2279',
1326 'NotGreaterSlantEqual;': '\u2a7e\u0338',
1327 'NotGreaterTilde;': '\u2275',
1328 'NotHumpDownHump;': '\u224e\u0338',
1329 'NotHumpEqual;': '\u224f\u0338',
1331 'notindot;': '\u22f5\u0338',
1332 'notinE;': '\u22f9\u0338',
1333 'notinva;': '\u2209',
1334 'notinvb;': '\u22f7',
1335 'notinvc;': '\u22f6',
1336 'NotLeftTriangle;': '\u22ea',
1337 'NotLeftTriangleBar;': '\u29cf\u0338',
1338 'NotLeftTriangleEqual;': '\u22ec',
1339 'NotLess;': '\u226e',
1340 'NotLessEqual;': '\u2270',
1341 'NotLessGreater;': '\u2278',
1342 'NotLessLess;': '\u226a\u0338',
1343 'NotLessSlantEqual;': '\u2a7d\u0338',
1344 'NotLessTilde;': '\u2274',
1345 'NotNestedGreaterGreater;': '\u2aa2\u0338',
1346 'NotNestedLessLess;': '\u2aa1\u0338',
1348 'notniva;': '\u220c',
1349 'notnivb;': '\u22fe',
1350 'notnivc;': '\u22fd',
1351 'NotPrecedes;': '\u2280',
1352 'NotPrecedesEqual;': '\u2aaf\u0338',
1353 'NotPrecedesSlantEqual;': '\u22e0',
1354 'NotReverseElement;': '\u220c',
1355 'NotRightTriangle;': '\u22eb',
1356 'NotRightTriangleBar;': '\u29d0\u0338',
1357 'NotRightTriangleEqual;': '\u22ed',
1358 'NotSquareSubset;': '\u228f\u0338',
1359 'NotSquareSubsetEqual;': '\u22e2',
1360 'NotSquareSuperset;': '\u2290\u0338',
1361 'NotSquareSupersetEqual;': '\u22e3',
1362 'NotSubset;': '\u2282\u20d2',
1363 'NotSubsetEqual;': '\u2288',
1364 'NotSucceeds;': '\u2281',
1365 'NotSucceedsEqual;': '\u2ab0\u0338',
1366 'NotSucceedsSlantEqual;': '\u22e1',
1367 'NotSucceedsTilde;': '\u227f\u0338',
1368 'NotSuperset;': '\u2283\u20d2',
1369 'NotSupersetEqual;': '\u2289',
1370 'NotTilde;': '\u2241',
1371 'NotTildeEqual;': '\u2244',
1372 'NotTildeFullEqual;': '\u2247',
1373 'NotTildeTilde;': '\u2249',
1374 'NotVerticalBar;': '\u2224',
1376 'nparallel;': '\u2226',
1377 'nparsl;': '\u2afd\u20e5',
1378 'npart;': '\u2202\u0338',
1379 'npolint;': '\u2a14',
1381 'nprcue;': '\u22e0',
1382 'npre;': '\u2aaf\u0338',
1384 'npreceq;': '\u2aaf\u0338',
1387 'nrarrc;': '\u2933\u0338',
1388 'nrarrw;': '\u219d\u0338',
1389 'nRightarrow;': '\u21cf',
1390 'nrightarrow;': '\u219b',
1392 'nrtrie;': '\u22ed',
1394 'nsccue;': '\u22e1',
1395 'nsce;': '\u2ab0\u0338',
1396 'Nscr;': '\U0001d4a9',
1397 'nscr;': '\U0001d4c3',
1398 'nshortmid;': '\u2224',
1399 'nshortparallel;': '\u2226',
1402 'nsimeq;': '\u2244',
1405 'nsqsube;': '\u22e2',
1406 'nsqsupe;': '\u22e3',
1408 'nsubE;': '\u2ac5\u0338',
1410 'nsubset;': '\u2282\u20d2',
1411 'nsubseteq;': '\u2288',
1412 'nsubseteqq;': '\u2ac5\u0338',
1414 'nsucceq;': '\u2ab0\u0338',
1416 'nsupE;': '\u2ac6\u0338',
1418 'nsupset;': '\u2283\u20d2',
1419 'nsupseteq;': '\u2289',
1420 'nsupseteqq;': '\u2ac6\u0338',
1427 'ntriangleleft;': '\u22ea',
1428 'ntrianglelefteq;': '\u22ec',
1429 'ntriangleright;': '\u22eb',
1430 'ntrianglerighteq;': '\u22ed',
1434 'numero;': '\u2116',
1436 'nvap;': '\u224d\u20d2',
1437 'nVDash;': '\u22af',
1438 'nVdash;': '\u22ae',
1439 'nvDash;': '\u22ad',
1440 'nvdash;': '\u22ac',
1441 'nvge;': '\u2265\u20d2',
1443 'nvHarr;': '\u2904',
1444 'nvinfin;': '\u29de',
1445 'nvlArr;': '\u2902',
1446 'nvle;': '\u2264\u20d2',
1448 'nvltrie;': '\u22b4\u20d2',
1449 'nvrArr;': '\u2903',
1450 'nvrtrie;': '\u22b5\u20d2',
1451 'nvsim;': '\u223c\u20d2',
1452 'nwarhk;': '\u2923',
1455 'nwarrow;': '\u2196',
1456 'nwnear;': '\u2927',
1470 'Odblac;': '\u0150',
1471 'odblac;': '\u0151',
1474 'odsold;': '\u29bc',
1478 'Ofr;': '\U0001d512',
1479 'ofr;': '\U0001d52c',
1491 'olcross;': '\u29bb',
1498 'Omicron;': '\u039f',
1499 'omicron;': '\u03bf',
1501 'ominus;': '\u2296',
1502 'Oopf;': '\U0001d546',
1503 'oopf;': '\U0001d560',
1505 'OpenCurlyDoubleQuote;': '\u201c',
1506 'OpenCurlyQuote;': '\u2018',
1514 'orderof;': '\u2134',
1519 'origof;': '\u22b6',
1521 'orslope;': '\u2a57',
1524 'Oscr;': '\U0001d4aa',
1535 'Otimes;': '\u2a37',
1536 'otimes;': '\u2297',
1537 'otimesas;': '\u2a36',
1543 'OverBar;': '\u203e',
1544 'OverBrace;': '\u23de',
1545 'OverBracket;': '\u23b4',
1546 'OverParenthesis;': '\u23dc',
1550 'parallel;': '\u2225',
1551 'parsim;': '\u2af3',
1554 'PartialD;': '\u2202',
1559 'permil;': '\u2030',
1561 'pertenk;': '\u2031',
1562 'Pfr;': '\U0001d513',
1563 'pfr;': '\U0001d52d',
1567 'phmmat;': '\u2133',
1571 'pitchfork;': '\u22d4',
1573 'planck;': '\u210f',
1574 'planckh;': '\u210e',
1575 'plankv;': '\u210f',
1577 'plusacir;': '\u2a23',
1579 'pluscir;': '\u2a22',
1580 'plusdo;': '\u2214',
1581 'plusdu;': '\u2a25',
1583 'PlusMinus;': '\xb1',
1586 'plussim;': '\u2a26',
1587 'plustwo;': '\u2a27',
1589 'Poincareplane;': '\u210c',
1590 'pointint;': '\u2a15',
1592 'popf;': '\U0001d561',
1602 'precapprox;': '\u2ab7',
1603 'preccurlyeq;': '\u227c',
1604 'Precedes;': '\u227a',
1605 'PrecedesEqual;': '\u2aaf',
1606 'PrecedesSlantEqual;': '\u227c',
1607 'PrecedesTilde;': '\u227e',
1608 'preceq;': '\u2aaf',
1609 'precnapprox;': '\u2ab9',
1610 'precneqq;': '\u2ab5',
1611 'precnsim;': '\u22e8',
1612 'precsim;': '\u227e',
1615 'primes;': '\u2119',
1618 'prnsim;': '\u22e8',
1620 'Product;': '\u220f',
1621 'profalar;': '\u232e',
1622 'profline;': '\u2312',
1623 'profsurf;': '\u2313',
1625 'Proportion;': '\u2237',
1626 'Proportional;': '\u221d',
1627 'propto;': '\u221d',
1629 'prurel;': '\u22b0',
1630 'Pscr;': '\U0001d4ab',
1631 'pscr;': '\U0001d4c5',
1634 'puncsp;': '\u2008',
1635 'Qfr;': '\U0001d514',
1636 'qfr;': '\U0001d52e',
1639 'qopf;': '\U0001d562',
1640 'qprime;': '\u2057',
1641 'Qscr;': '\U0001d4ac',
1642 'qscr;': '\U0001d4c6',
1643 'quaternions;': '\u210d',
1644 'quatint;': '\u2a16',
1646 'questeq;': '\u225f',
1652 'race;': '\u223d\u0331',
1653 'Racute;': '\u0154',
1654 'racute;': '\u0155',
1656 'raemptyv;': '\u29b3',
1661 'rangle;': '\u27e9',
1667 'rarrap;': '\u2975',
1669 'rarrbfs;': '\u2920',
1671 'rarrfs;': '\u291e',
1672 'rarrhk;': '\u21aa',
1673 'rarrlp;': '\u21ac',
1674 'rarrpl;': '\u2945',
1675 'rarrsim;': '\u2974',
1676 'Rarrtl;': '\u2916',
1677 'rarrtl;': '\u21a3',
1679 'rAtail;': '\u291c',
1680 'ratail;': '\u291a',
1682 'rationals;': '\u211a',
1690 'rbrksld;': '\u298e',
1691 'rbrkslu;': '\u2990',
1692 'Rcaron;': '\u0158',
1693 'rcaron;': '\u0159',
1694 'Rcedil;': '\u0156',
1695 'rcedil;': '\u0157',
1701 'rdldhar;': '\u2969',
1703 'rdquor;': '\u201d',
1707 'realine;': '\u211b',
1708 'realpart;': '\u211c',
1715 'ReverseElement;': '\u220b',
1716 'ReverseEquilibrium;': '\u21cb',
1717 'ReverseUpEquilibrium;': '\u296f',
1718 'rfisht;': '\u297d',
1719 'rfloor;': '\u230b',
1721 'rfr;': '\U0001d52f',
1725 'rharul;': '\u296c',
1729 'RightAngleBracket;': '\u27e9',
1730 'RightArrow;': '\u2192',
1731 'Rightarrow;': '\u21d2',
1732 'rightarrow;': '\u2192',
1733 'RightArrowBar;': '\u21e5',
1734 'RightArrowLeftArrow;': '\u21c4',
1735 'rightarrowtail;': '\u21a3',
1736 'RightCeiling;': '\u2309',
1737 'RightDoubleBracket;': '\u27e7',
1738 'RightDownTeeVector;': '\u295d',
1739 'RightDownVector;': '\u21c2',
1740 'RightDownVectorBar;': '\u2955',
1741 'RightFloor;': '\u230b',
1742 'rightharpoondown;': '\u21c1',
1743 'rightharpoonup;': '\u21c0',
1744 'rightleftarrows;': '\u21c4',
1745 'rightleftharpoons;': '\u21cc',
1746 'rightrightarrows;': '\u21c9',
1747 'rightsquigarrow;': '\u219d',
1748 'RightTee;': '\u22a2',
1749 'RightTeeArrow;': '\u21a6',
1750 'RightTeeVector;': '\u295b',
1751 'rightthreetimes;': '\u22cc',
1752 'RightTriangle;': '\u22b3',
1753 'RightTriangleBar;': '\u29d0',
1754 'RightTriangleEqual;': '\u22b5',
1755 'RightUpDownVector;': '\u294f',
1756 'RightUpTeeVector;': '\u295c',
1757 'RightUpVector;': '\u21be',
1758 'RightUpVectorBar;': '\u2954',
1759 'RightVector;': '\u21c0',
1760 'RightVectorBar;': '\u2953',
1762 'risingdotseq;': '\u2253',
1766 'rmoust;': '\u23b1',
1767 'rmoustache;': '\u23b1',
1774 'ropf;': '\U0001d563',
1775 'roplus;': '\u2a2e',
1776 'rotimes;': '\u2a35',
1777 'RoundImplies;': '\u2970',
1779 'rpargt;': '\u2994',
1780 'rppolint;': '\u2a12',
1782 'Rrightarrow;': '\u21db',
1783 'rsaquo;': '\u203a',
1785 'rscr;': '\U0001d4c7',
1790 'rsquor;': '\u2019',
1791 'rthree;': '\u22cc',
1792 'rtimes;': '\u22ca',
1796 'rtriltri;': '\u29ce',
1797 'RuleDelayed;': '\u29f4',
1798 'ruluhar;': '\u2968',
1800 'Sacute;': '\u015a',
1801 'sacute;': '\u015b',
1806 'Scaron;': '\u0160',
1807 'scaron;': '\u0161',
1811 'Scedil;': '\u015e',
1812 'scedil;': '\u015f',
1817 'scnsim;': '\u22e9',
1818 'scpolint;': '\u2a13',
1825 'searhk;': '\u2925',
1828 'searrow;': '\u2198',
1832 'seswar;': '\u2929',
1833 'setminus;': '\u2216',
1836 'Sfr;': '\U0001d516',
1837 'sfr;': '\U0001d530',
1838 'sfrown;': '\u2322',
1840 'SHCHcy;': '\u0429',
1841 'shchcy;': '\u0449',
1844 'ShortDownArrow;': '\u2193',
1845 'ShortLeftArrow;': '\u2190',
1846 'shortmid;': '\u2223',
1847 'shortparallel;': '\u2225',
1848 'ShortRightArrow;': '\u2192',
1849 'ShortUpArrow;': '\u2191',
1854 'sigmaf;': '\u03c2',
1855 'sigmav;': '\u03c2',
1857 'simdot;': '\u2a6a',
1865 'simplus;': '\u2a24',
1866 'simrarr;': '\u2972',
1868 'SmallCircle;': '\u2218',
1869 'smallsetminus;': '\u2216',
1870 'smashp;': '\u2a33',
1871 'smeparsl;': '\u29e4',
1876 'smtes;': '\u2aac\ufe00',
1877 'SOFTcy;': '\u042c',
1878 'softcy;': '\u044c',
1881 'solbar;': '\u233f',
1882 'Sopf;': '\U0001d54a',
1883 'sopf;': '\U0001d564',
1884 'spades;': '\u2660',
1885 'spadesuit;': '\u2660',
1888 'sqcaps;': '\u2293\ufe00',
1890 'sqcups;': '\u2294\ufe00',
1893 'sqsube;': '\u2291',
1894 'sqsubset;': '\u228f',
1895 'sqsubseteq;': '\u2291',
1897 'sqsupe;': '\u2292',
1898 'sqsupset;': '\u2290',
1899 'sqsupseteq;': '\u2292',
1901 'Square;': '\u25a1',
1902 'square;': '\u25a1',
1903 'SquareIntersection;': '\u2293',
1904 'SquareSubset;': '\u228f',
1905 'SquareSubsetEqual;': '\u2291',
1906 'SquareSuperset;': '\u2290',
1907 'SquareSupersetEqual;': '\u2292',
1908 'SquareUnion;': '\u2294',
1909 'squarf;': '\u25aa',
1912 'Sscr;': '\U0001d4ae',
1913 'sscr;': '\U0001d4c8',
1914 'ssetmn;': '\u2216',
1915 'ssmile;': '\u2323',
1916 'sstarf;': '\u22c6',
1920 'straightepsilon;': '\u03f5',
1921 'straightphi;': '\u03d5',
1925 'subdot;': '\u2abd',
1928 'subedot;': '\u2ac3',
1929 'submult;': '\u2ac1',
1932 'subplus;': '\u2abf',
1933 'subrarr;': '\u2979',
1934 'Subset;': '\u22d0',
1935 'subset;': '\u2282',
1936 'subseteq;': '\u2286',
1937 'subseteqq;': '\u2ac5',
1938 'SubsetEqual;': '\u2286',
1939 'subsetneq;': '\u228a',
1940 'subsetneqq;': '\u2acb',
1941 'subsim;': '\u2ac7',
1942 'subsub;': '\u2ad5',
1943 'subsup;': '\u2ad3',
1945 'succapprox;': '\u2ab8',
1946 'succcurlyeq;': '\u227d',
1947 'Succeeds;': '\u227b',
1948 'SucceedsEqual;': '\u2ab0',
1949 'SucceedsSlantEqual;': '\u227d',
1950 'SucceedsTilde;': '\u227f',
1951 'succeq;': '\u2ab0',
1952 'succnapprox;': '\u2aba',
1953 'succneqq;': '\u2ab6',
1954 'succnsim;': '\u22e9',
1955 'succsim;': '\u227f',
1956 'SuchThat;': '\u220b',
1968 'supdot;': '\u2abe',
1969 'supdsub;': '\u2ad8',
1972 'supedot;': '\u2ac4',
1973 'Superset;': '\u2283',
1974 'SupersetEqual;': '\u2287',
1975 'suphsol;': '\u27c9',
1976 'suphsub;': '\u2ad7',
1977 'suplarr;': '\u297b',
1978 'supmult;': '\u2ac2',
1981 'supplus;': '\u2ac0',
1982 'Supset;': '\u22d1',
1983 'supset;': '\u2283',
1984 'supseteq;': '\u2287',
1985 'supseteqq;': '\u2ac6',
1986 'supsetneq;': '\u228b',
1987 'supsetneqq;': '\u2acc',
1988 'supsim;': '\u2ac8',
1989 'supsub;': '\u2ad4',
1990 'supsup;': '\u2ad6',
1991 'swarhk;': '\u2926',
1994 'swarrow;': '\u2199',
1995 'swnwar;': '\u292a',
1999 'target;': '\u2316',
2003 'Tcaron;': '\u0164',
2004 'tcaron;': '\u0165',
2005 'Tcedil;': '\u0162',
2006 'tcedil;': '\u0163',
2010 'telrec;': '\u2315',
2011 'Tfr;': '\U0001d517',
2012 'tfr;': '\U0001d531',
2013 'there4;': '\u2234',
2014 'Therefore;': '\u2234',
2015 'therefore;': '\u2234',
2018 'thetasym;': '\u03d1',
2019 'thetav;': '\u03d1',
2020 'thickapprox;': '\u2248',
2021 'thicksim;': '\u223c',
2022 'ThickSpace;': '\u205f\u200a',
2023 'thinsp;': '\u2009',
2024 'ThinSpace;': '\u2009',
2026 'thksim;': '\u223c',
2033 'TildeEqual;': '\u2243',
2034 'TildeFullEqual;': '\u2245',
2035 'TildeTilde;': '\u2248',
2038 'timesb;': '\u22a0',
2039 'timesbar;': '\u2a31',
2040 'timesd;': '\u2a30',
2044 'topbot;': '\u2336',
2045 'topcir;': '\u2af1',
2046 'Topf;': '\U0001d54b',
2047 'topf;': '\U0001d565',
2048 'topfork;': '\u2ada',
2050 'tprime;': '\u2034',
2053 'triangle;': '\u25b5',
2054 'triangledown;': '\u25bf',
2055 'triangleleft;': '\u25c3',
2056 'trianglelefteq;': '\u22b4',
2057 'triangleq;': '\u225c',
2058 'triangleright;': '\u25b9',
2059 'trianglerighteq;': '\u22b5',
2060 'tridot;': '\u25ec',
2062 'triminus;': '\u2a3a',
2063 'TripleDot;': '\u20db',
2064 'triplus;': '\u2a39',
2066 'tritime;': '\u2a3b',
2067 'trpezium;': '\u23e2',
2068 'Tscr;': '\U0001d4af',
2069 'tscr;': '\U0001d4c9',
2074 'Tstrok;': '\u0166',
2075 'tstrok;': '\u0167',
2077 'twoheadleftarrow;': '\u219e',
2078 'twoheadrightarrow;': '\u21a0',
2086 'Uarrocir;': '\u2949',
2089 'Ubreve;': '\u016c',
2090 'ubreve;': '\u016d',
2098 'Udblac;': '\u0170',
2099 'udblac;': '\u0171',
2101 'ufisht;': '\u297e',
2102 'Ufr;': '\U0001d518',
2103 'ufr;': '\U0001d532',
2112 'ulcorn;': '\u231c',
2113 'ulcorner;': '\u231c',
2114 'ulcrop;': '\u230f',
2121 'UnderBrace;': '\u23df',
2122 'UnderBracket;': '\u23b5',
2123 'UnderParenthesis;': '\u23dd',
2125 'UnionPlus;': '\u228e',
2128 'Uopf;': '\U0001d54c',
2129 'uopf;': '\U0001d566',
2130 'UpArrow;': '\u2191',
2131 'Uparrow;': '\u21d1',
2132 'uparrow;': '\u2191',
2133 'UpArrowBar;': '\u2912',
2134 'UpArrowDownArrow;': '\u21c5',
2135 'UpDownArrow;': '\u2195',
2136 'Updownarrow;': '\u21d5',
2137 'updownarrow;': '\u2195',
2138 'UpEquilibrium;': '\u296e',
2139 'upharpoonleft;': '\u21bf',
2140 'upharpoonright;': '\u21be',
2142 'UpperLeftArrow;': '\u2196',
2143 'UpperRightArrow;': '\u2197',
2147 'Upsilon;': '\u03a5',
2148 'upsilon;': '\u03c5',
2150 'UpTeeArrow;': '\u21a5',
2151 'upuparrows;': '\u21c8',
2152 'urcorn;': '\u231d',
2153 'urcorner;': '\u231d',
2154 'urcrop;': '\u230e',
2158 'Uscr;': '\U0001d4b0',
2159 'uscr;': '\U0001d4ca',
2161 'Utilde;': '\u0168',
2162 'utilde;': '\u0169',
2170 'uwangle;': '\u29a7',
2171 'vangrt;': '\u299c',
2172 'varepsilon;': '\u03f5',
2173 'varkappa;': '\u03f0',
2174 'varnothing;': '\u2205',
2175 'varphi;': '\u03d5',
2177 'varpropto;': '\u221d',
2180 'varrho;': '\u03f1',
2181 'varsigma;': '\u03c2',
2182 'varsubsetneq;': '\u228a\ufe00',
2183 'varsubsetneqq;': '\u2acb\ufe00',
2184 'varsupsetneq;': '\u228b\ufe00',
2185 'varsupsetneqq;': '\u2acc\ufe00',
2186 'vartheta;': '\u03d1',
2187 'vartriangleleft;': '\u22b2',
2188 'vartriangleright;': '\u22b3',
2198 'Vdashl;': '\u2ae6',
2201 'veebar;': '\u22bb',
2203 'vellip;': '\u22ee',
2204 'Verbar;': '\u2016',
2208 'VerticalBar;': '\u2223',
2209 'VerticalLine;': '|',
2210 'VerticalSeparator;': '\u2758',
2211 'VerticalTilde;': '\u2240',
2212 'VeryThinSpace;': '\u200a',
2213 'Vfr;': '\U0001d519',
2214 'vfr;': '\U0001d533',
2216 'vnsub;': '\u2282\u20d2',
2217 'vnsup;': '\u2283\u20d2',
2218 'Vopf;': '\U0001d54d',
2219 'vopf;': '\U0001d567',
2222 'Vscr;': '\U0001d4b1',
2223 'vscr;': '\U0001d4cb',
2224 'vsubnE;': '\u2acb\ufe00',
2225 'vsubne;': '\u228a\ufe00',
2226 'vsupnE;': '\u2acc\ufe00',
2227 'vsupne;': '\u228b\ufe00',
2228 'Vvdash;': '\u22aa',
2229 'vzigzag;': '\u299a',
2232 'wedbar;': '\u2a5f',
2235 'wedgeq;': '\u2259',
2236 'weierp;': '\u2118',
2237 'Wfr;': '\U0001d51a',
2238 'wfr;': '\U0001d534',
2239 'Wopf;': '\U0001d54e',
2240 'wopf;': '\U0001d568',
2243 'wreath;': '\u2240',
2244 'Wscr;': '\U0001d4b2',
2245 'wscr;': '\U0001d4cc',
2250 'Xfr;': '\U0001d51b',
2251 'xfr;': '\U0001d535',
2261 'Xopf;': '\U0001d54f',
2262 'xopf;': '\U0001d569',
2263 'xoplus;': '\u2a01',
2264 'xotime;': '\u2a02',
2267 'Xscr;': '\U0001d4b3',
2268 'xscr;': '\U0001d4cd',
2269 'xsqcup;': '\u2a06',
2270 'xuplus;': '\u2a04',
2273 'xwedge;': '\u22c0',
2286 'Yfr;': '\U0001d51c',
2287 'yfr;': '\U0001d536',
2290 'Yopf;': '\U0001d550',
2291 'yopf;': '\U0001d56a',
2292 'Yscr;': '\U0001d4b4',
2293 'yscr;': '\U0001d4ce',
2299 'Zacute;': '\u0179',
2300 'zacute;': '\u017a',
2301 'Zcaron;': '\u017d',
2302 'zcaron;': '\u017e',
2307 'zeetrf;': '\u2128',
2308 'ZeroWidthSpace;': '\u200b',
2312 'zfr;': '\U0001d537',
2315 'zigrarr;': '\u21dd',
2317 'zopf;': '\U0001d56b',
2318 'Zscr;': '\U0001d4b5',
2319 'zscr;': '\U0001d4cf',
2325 import http
.client
as compat_http_client
2326 except ImportError: # Python 2
2327 import httplib
as compat_http_client
2330 from urllib
.error
import HTTPError
as compat_HTTPError
2331 except ImportError: # Python 2
2332 from urllib2
import HTTPError
as compat_HTTPError
2335 from urllib
.request
import urlretrieve
as compat_urlretrieve
2336 except ImportError: # Python 2
2337 from urllib
import urlretrieve
as compat_urlretrieve
2340 from html
.parser
import HTMLParser
as compat_HTMLParser
2341 except ImportError: # Python 2
2342 from HTMLParser
import HTMLParser
as compat_HTMLParser
2345 from HTMLParser
import HTMLParseError
as compat_HTMLParseError
2346 except ImportError: # Python <3.4
2348 from html
.parser
import HTMLParseError
as compat_HTMLParseError
2349 except ImportError: # Python >3.4
2351 # HTMLParseError has been deprecated in Python 3.3 and removed in
2352 # Python 3.5. Introducing dummy exception for Python >3.5 for compatible
2353 # and uniform cross-version exception handling
2354 class compat_HTMLParseError(Exception):
2358 from subprocess
import DEVNULL
2359 compat_subprocess_get_DEVNULL
= lambda: DEVNULL
2361 compat_subprocess_get_DEVNULL
= lambda: open(os
.path
.devnull
, 'w')
2364 import http
.server
as compat_http_server
2366 import BaseHTTPServer
as compat_http_server
2369 compat_str
= unicode # Python 2
2374 from urllib
.parse
import quote
as compat_urllib_parse_quote
2375 from urllib
.parse
import quote_plus
as compat_urllib_parse_quote_plus
2376 except ImportError: # Python 2
2377 def compat_urllib_parse_quote(string
, safe
='/'):
2378 return compat_urllib_parse
.quote(
2379 string
.encode('utf-8'),
2382 def compat_urllib_parse_quote_plus(string
, safe
=''):
2383 return compat_urllib_parse
.quote_plus(
2384 string
.encode('utf-8'),
2388 from urllib
.parse
import unquote_to_bytes
as compat_urllib_parse_unquote_to_bytes
2389 from urllib
.parse
import unquote
as compat_urllib_parse_unquote
2390 from urllib
.parse
import unquote_plus
as compat_urllib_parse_unquote_plus
2391 except ImportError: # Python 2
2392 _asciire
= (compat_urllib_parse
._asciire
if hasattr(compat_urllib_parse
, '_asciire')
2393 else re
.compile(r
'([\x00-\x7f]+)'))
2395 # HACK: The following are the correct unquote_to_bytes, unquote and unquote_plus
2396 # implementations from cpython 3.4.3's stdlib. Python 2's version
2397 # is apparently broken (see https://github.com/ytdl-org/youtube-dl/pull/6244)
2399 def compat_urllib_parse_unquote_to_bytes(string
):
2400 """unquote_to_bytes('abc%20def') -> b'abc def'."""
2401 # Note: strings are encoded as UTF-8. This is only an issue if it contains
2402 # unescaped non-ASCII characters, which URIs should not.
2404 # Is it a string-like object?
2407 if isinstance(string
, compat_str
):
2408 string
= string
.encode('utf-8')
2409 bits
= string
.split(b
'%')
2414 for item
in bits
[1:]:
2416 append(compat_urllib_parse
._hextochr
[item
[:2]])
2421 return b
''.join(res
)
2423 def compat_urllib_parse_unquote(string
, encoding
='utf-8', errors
='replace'):
2424 """Replace %xx escapes by their single-character equivalent. The optional
2425 encoding and errors parameters specify how to decode percent-encoded
2426 sequences into Unicode characters, as accepted by the bytes.decode()
2428 By default, percent-encoded sequences are decoded with UTF-8, and invalid
2429 sequences are replaced by a placeholder character.
2431 unquote('abc%20def') -> 'abc def'.
2433 if '%' not in string
:
2436 if encoding
is None:
2440 bits
= _asciire
.split(string
)
2443 for i
in range(1, len(bits
), 2):
2444 append(compat_urllib_parse_unquote_to_bytes(bits
[i
]).decode(encoding
, errors
))
2448 def compat_urllib_parse_unquote_plus(string
, encoding
='utf-8', errors
='replace'):
2449 """Like unquote(), but also replace plus signs by spaces, as required for
2450 unquoting HTML form values.
2452 unquote_plus('%7e/abc+def') -> '~/abc def'
2454 string
= string
.replace('+', ' ')
2455 return compat_urllib_parse_unquote(string
, encoding
, errors
)
2458 from urllib
.parse
import urlencode
as compat_urllib_parse_urlencode
2459 except ImportError: # Python 2
2460 # Python 2 will choke in urlencode on mixture of byte and unicode strings.
2461 # Possible solutions are to either port it from python 3 with all
2462 # the friends or manually ensure input query contains only byte strings.
2463 # We will stick with latter thus recursively encoding the whole query.
2464 def compat_urllib_parse_urlencode(query
, doseq
=0, encoding
='utf-8'):
2466 if isinstance(e
, dict):
2468 elif isinstance(e
, (list, tuple,)):
2469 list_e
= encode_list(e
)
2470 e
= tuple(list_e
) if isinstance(e
, tuple) else list_e
2471 elif isinstance(e
, compat_str
):
2472 e
= e
.encode(encoding
)
2476 return dict((encode_elem(k
), encode_elem(v
)) for k
, v
in d
.items())
2479 return [encode_elem(e
) for e
in l
]
2481 return compat_urllib_parse
.urlencode(encode_elem(query
), doseq
=doseq
)
2484 from urllib
.request
import DataHandler
as compat_urllib_request_DataHandler
2485 except ImportError: # Python < 3.4
2486 # Ported from CPython 98774:1733b3bd46db, Lib/urllib/request.py
2487 class compat_urllib_request_DataHandler(compat_urllib_request
.BaseHandler
):
2488 def data_open(self
, req
):
2489 # data URLs as specified in RFC 2397.
2491 # ignores POSTed data
2494 # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data
2495 # mediatype := [ type "/" subtype ] *( ";" parameter )
2497 # parameter := attribute "=" value
2498 url
= req
.get_full_url()
2500 scheme
, data
= url
.split(':', 1)
2501 mediatype
, data
= data
.split(',', 1)
2503 # even base64 encoded data URLs might be quoted so unquote in any case:
2504 data
= compat_urllib_parse_unquote_to_bytes(data
)
2505 if mediatype
.endswith(';base64'):
2506 data
= binascii
.a2b_base64(data
)
2507 mediatype
= mediatype
[:-7]
2510 mediatype
= 'text/plain;charset=US-ASCII'
2512 headers
= email
.message_from_string(
2513 'Content-type: %s\nContent-length: %d\n' % (mediatype
, len(data
)))
2515 return compat_urllib_response
.addinfourl(io
.BytesIO(data
), headers
, url
)
2518 compat_basestring
= basestring
# Python 2
2520 compat_basestring
= str
2523 compat_chr
= unichr # Python 2
2528 from xml
.etree
.ElementTree
import ParseError
as compat_xml_parse_error
2529 except ImportError: # Python 2.6
2530 from xml
.parsers
.expat
import ExpatError
as compat_xml_parse_error
2533 etree
= xml
.etree
.ElementTree
2536 class _TreeBuilder(etree
.TreeBuilder
):
2537 def doctype(self
, name
, pubid
, system
):
2542 # xml.etree.ElementTree.Element is a method in Python <=2.6 and
2543 # the following will crash with:
2544 # TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
2545 isinstance(None, xml
.etree
.ElementTree
.Element
)
2546 from xml
.etree
.ElementTree
import Element
as compat_etree_Element
2547 except TypeError: # Python <=2.6
2548 from xml
.etree
.ElementTree
import _ElementInterface
as compat_etree_Element
2550 if sys
.version_info
[0] >= 3:
2551 def compat_etree_fromstring(text
):
2552 return etree
.XML(text
, parser
=etree
.XMLParser(target
=_TreeBuilder()))
2554 # python 2.x tries to encode unicode strings with ascii (see the
2555 # XMLParser._fixtext method)
2557 _etree_iter
= etree
.Element
.iter
2558 except AttributeError: # Python <=2.6
2559 def _etree_iter(root
):
2560 for el
in root
.findall('*'):
2562 for sub
in _etree_iter(el
):
2565 # on 2.6 XML doesn't have a parser argument, function copied from CPython
2567 def _XML(text
, parser
=None):
2569 parser
= etree
.XMLParser(target
=_TreeBuilder())
2571 return parser
.close()
2573 def _element_factory(*args
, **kwargs
):
2574 el
= etree
.Element(*args
, **kwargs
)
2575 for k
, v
in el
.items():
2576 if isinstance(v
, bytes):
2577 el
.set(k
, v
.decode('utf-8'))
2580 def compat_etree_fromstring(text
):
2581 doc
= _XML(text
, parser
=etree
.XMLParser(target
=_TreeBuilder(element_factory
=_element_factory
)))
2582 for el
in _etree_iter(doc
):
2583 if el
.text
is not None and isinstance(el
.text
, bytes):
2584 el
.text
= el
.text
.decode('utf-8')
2587 if hasattr(etree
, 'register_namespace'):
2588 compat_etree_register_namespace
= etree
.register_namespace
2590 def compat_etree_register_namespace(prefix
, uri
):
2591 """Register a namespace prefix.
2592 The registry is global, and any existing mapping for either the
2593 given prefix or the namespace URI will be removed.
2594 *prefix* is the namespace prefix, *uri* is a namespace uri. Tags and
2595 attributes in this namespace will be serialized with prefix if possible.
2596 ValueError is raised if prefix is reserved or is invalid.
2598 if re
.match(r
"ns\d+$", prefix
):
2599 raise ValueError("Prefix format reserved for internal use")
2600 for k
, v
in list(etree
._namespace
_map
.items()):
2601 if k
== uri
or v
== prefix
:
2602 del etree
._namespace
_map
[k
]
2603 etree
._namespace
_map
[uri
] = prefix
2605 if sys
.version_info
< (2, 7):
2606 # Here comes the crazy part: In 2.6, if the xpath is a unicode,
2607 # .//node does not match if a node is a direct child of . !
2608 def compat_xpath(xpath
):
2609 if isinstance(xpath
, compat_str
):
2610 xpath
= xpath
.encode('ascii')
2613 compat_xpath
= lambda xpath
: xpath
2616 from urllib
.parse
import parse_qs
as compat_parse_qs
2617 except ImportError: # Python 2
2618 # HACK: The following is the correct parse_qs implementation from cpython 3's stdlib.
2619 # Python 2's version is apparently totally broken
2621 def _parse_qsl(qs
, keep_blank_values
=False, strict_parsing
=False,
2622 encoding
='utf-8', errors
='replace'):
2623 qs
, _coerce_result
= qs
, compat_str
2624 pairs
= [s2
for s1
in qs
.split('&') for s2
in s1
.split(';')]
2626 for name_value
in pairs
:
2627 if not name_value
and not strict_parsing
:
2629 nv
= name_value
.split('=', 1)
2632 raise ValueError('bad query field: %r' % (name_value
,))
2633 # Handle case of a control-name with no equal sign
2634 if keep_blank_values
:
2638 if len(nv
[1]) or keep_blank_values
:
2639 name
= nv
[0].replace('+', ' ')
2640 name
= compat_urllib_parse_unquote(
2641 name
, encoding
=encoding
, errors
=errors
)
2642 name
= _coerce_result(name
)
2643 value
= nv
[1].replace('+', ' ')
2644 value
= compat_urllib_parse_unquote(
2645 value
, encoding
=encoding
, errors
=errors
)
2646 value
= _coerce_result(value
)
2647 r
.append((name
, value
))
2650 def compat_parse_qs(qs
, keep_blank_values
=False, strict_parsing
=False,
2651 encoding
='utf-8', errors
='replace'):
2653 pairs
= _parse_qsl(qs
, keep_blank_values
, strict_parsing
,
2654 encoding
=encoding
, errors
=errors
)
2655 for name
, value
in pairs
:
2656 if name
in parsed_result
:
2657 parsed_result
[name
].append(value
)
2659 parsed_result
[name
] = [value
]
2660 return parsed_result
2663 compat_os_name
= os
._name
if os
.name
== 'java' else os
.name
2666 if compat_os_name
== 'nt':
2667 def compat_shlex_quote(s
):
2668 return s
if re
.match(r
'^[-_\w./]+$', s
) else '"%s"' % s
.replace('"', '\\"')
2671 from shlex
import quote
as compat_shlex_quote
2672 except ImportError: # Python < 3.3
2673 def compat_shlex_quote(s
):
2674 if re
.match(r
'^[-_\w./]+$', s
):
2677 return "'" + s
.replace("'", "'\"'\"'") + "'"
2681 args
= shlex
.split('ä¸æ–‡')
2682 assert (isinstance(args
, list)
2683 and isinstance(args
[0], compat_str
)
2684 and args
[0] == 'ä¸æ–‡')
2685 compat_shlex_split
= shlex
.split
2686 except (AssertionError, UnicodeEncodeError):
2687 # Working around shlex issue with unicode strings on some python 2
2688 # versions (see http://bugs.python.org/issue1548891)
2689 def compat_shlex_split(s
, comments
=False, posix
=True):
2690 if isinstance(s
, compat_str
):
2691 s
= s
.encode('utf-8')
2692 return list(map(lambda s
: s
.decode('utf-8'), shlex
.split(s
, comments
, posix
)))
2702 if sys
.version_info
>= (3, 0):
2703 compat_getenv
= os
.getenv
2704 compat_expanduser
= os
.path
.expanduser
2706 def compat_setenv(key
, value
, env
=os
.environ
):
2709 # Environment variables should be decoded with filesystem encoding.
2710 # Otherwise it will fail if any non-ASCII characters present (see #3854 #3217 #2918)
2712 def compat_getenv(key
, default
=None):
2713 from .utils
import get_filesystem_encoding
2714 env
= os
.getenv(key
, default
)
2716 env
= env
.decode(get_filesystem_encoding())
2719 def compat_setenv(key
, value
, env
=os
.environ
):
2721 from .utils
import get_filesystem_encoding
2722 return v
.encode(get_filesystem_encoding()) if isinstance(v
, compat_str
) else v
2723 env
[encode(key
)] = encode(value
)
2725 # HACK: The default implementations of os.path.expanduser from cpython do not decode
2726 # environment variables with filesystem encoding. We will work around this by
2727 # providing adjusted implementations.
2728 # The following are os.path.expanduser implementations from cpython 2.7.8 stdlib
2729 # for different platforms with correct environment variables decoding.
2731 if compat_os_name
== 'posix':
2732 def compat_expanduser(path
):
2733 """Expand ~ and ~user constructions. If user or $HOME is unknown,
2735 if not path
.startswith('~'):
2737 i
= path
.find('/', 1)
2741 if 'HOME' not in os
.environ
:
2743 userhome
= pwd
.getpwuid(os
.getuid()).pw_dir
2745 userhome
= compat_getenv('HOME')
2749 pwent
= pwd
.getpwnam(path
[1:i
])
2752 userhome
= pwent
.pw_dir
2753 userhome
= userhome
.rstrip('/')
2754 return (userhome
+ path
[i
:]) or '/'
2755 elif compat_os_name
in ('nt', 'ce'):
2756 def compat_expanduser(path
):
2757 """Expand ~ and ~user constructs.
2759 If user or $HOME is unknown, do nothing."""
2763 while i
< n
and path
[i
] not in '/\\':
2766 if 'HOME' in os
.environ
:
2767 userhome
= compat_getenv('HOME')
2768 elif 'USERPROFILE' in os
.environ
:
2769 userhome
= compat_getenv('USERPROFILE')
2770 elif 'HOMEPATH' not in os
.environ
:
2774 drive
= compat_getenv('HOMEDRIVE')
2777 userhome
= os
.path
.join(drive
, compat_getenv('HOMEPATH'))
2780 userhome
= os
.path
.join(os
.path
.dirname(userhome
), path
[1:i
])
2782 return userhome
+ path
[i
:]
2784 compat_expanduser
= os
.path
.expanduser
2787 if compat_os_name
== 'nt' and sys
.version_info
< (3, 8):
2788 # os.path.realpath on Windows does not follow symbolic links
2789 # prior to Python 3.8 (see https://bugs.python.org/issue9949)
2790 def compat_realpath(path
):
2791 while os
.path
.islink(path
):
2792 path
= os
.path
.abspath(os
.readlink(path
))
2795 compat_realpath
= os
.path
.realpath
2798 if sys
.version_info
< (3, 0):
2799 def compat_print(s
):
2800 from .utils
import preferredencoding
2801 print(s
.encode(preferredencoding(), 'xmlcharrefreplace'))
2803 def compat_print(s
):
2804 assert isinstance(s
, compat_str
)
2808 if sys
.version_info
< (3, 0) and sys
.platform
== 'win32':
2809 def compat_getpass(prompt
, *args
, **kwargs
):
2810 if isinstance(prompt
, compat_str
):
2811 from .utils
import preferredencoding
2812 prompt
= prompt
.encode(preferredencoding())
2813 return getpass
.getpass(prompt
, *args
, **kwargs
)
2815 compat_getpass
= getpass
.getpass
2818 compat_input
= raw_input
2819 except NameError: # Python 3
2820 compat_input
= input
2822 # Python < 2.6.5 require kwargs to be bytes
2826 _testfunc(**{'x': 0}
)
2828 def compat_kwargs(kwargs
):
2829 return dict((bytes(k
), v
) for k
, v
in kwargs
.items())
2831 compat_kwargs
= lambda kwargs
: kwargs
2835 compat_numeric_types
= (int, float, long, complex)
2836 except NameError: # Python 3
2837 compat_numeric_types
= (int, float, complex)
2841 compat_integer_types
= (int, long)
2842 except NameError: # Python 3
2843 compat_integer_types
= (int, )
2846 if sys
.version_info
< (2, 7):
2847 def compat_socket_create_connection(address
, timeout
, source_address
=None):
2848 host
, port
= address
2850 for res
in socket
.getaddrinfo(host
, port
, 0, socket
.SOCK_STREAM
):
2851 af
, socktype
, proto
, canonname
, sa
= res
2854 sock
= socket
.socket(af
, socktype
, proto
)
2855 sock
.settimeout(timeout
)
2857 sock
.bind(source_address
)
2860 except socket
.error
as _
:
2862 if sock
is not None:
2867 raise socket
.error('getaddrinfo returns an empty list')
2869 compat_socket_create_connection
= socket
.create_connection
2872 # Fix https://github.com/ytdl-org/youtube-dl/issues/4223
2873 # See http://bugs.python.org/issue9161 for what is broken
2874 def workaround_optparse_bug9161():
2875 op
= optparse
.OptionParser()
2876 og
= optparse
.OptionGroup(op
, 'foo')
2880 real_add_option
= optparse
.OptionGroup
.add_option
2882 def _compat_add_option(self
, *args
, **kwargs
):
2884 v
.encode('ascii', 'replace') if isinstance(v
, compat_str
)
2886 bargs
= [enc(a
) for a
in args
]
2888 (k
, enc(v
)) for k
, v
in kwargs
.items())
2889 return real_add_option(self
, *bargs
, **bkwargs
)
2890 optparse
.OptionGroup
.add_option
= _compat_add_option
2893 if hasattr(shutil
, 'get_terminal_size'): # Python >= 3.3
2894 compat_get_terminal_size
= shutil
.get_terminal_size
2896 _terminal_size
= collections
.namedtuple('terminal_size', ['columns', 'lines'])
2898 def compat_get_terminal_size(fallback
=(80, 24)):
2899 from .utils
import process_communicate_or_kill
2900 columns
= compat_getenv('COLUMNS')
2902 columns
= int(columns
)
2905 lines
= compat_getenv('LINES')
2911 if columns
is None or lines
is None or columns
<= 0 or lines
<= 0:
2913 sp
= subprocess
.Popen(
2915 stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
2916 out
, err
= process_communicate_or_kill(sp
)
2917 _lines
, _columns
= map(int, out
.split())
2919 _columns
, _lines
= _terminal_size(*fallback
)
2921 if columns
is None or columns
<= 0:
2923 if lines
is None or lines
<= 0:
2925 return _terminal_size(columns
, lines
)
2928 itertools
.count(start
=0, step
=1)
2929 compat_itertools_count
= itertools
.count
2930 except TypeError: # Python 2.6
2931 def compat_itertools_count(start
=0, step
=1):
2937 if sys
.version_info
>= (3, 0):
2938 from tokenize
import tokenize
as compat_tokenize_tokenize
2940 from tokenize
import generate_tokens
as compat_tokenize_tokenize
2944 struct
.pack('!I', 0)
2946 # In Python 2.6 and 2.7.x < 2.7.7, struct requires a bytes argument
2947 # See https://bugs.python.org/issue19099
2948 def compat_struct_pack(spec
, *args
):
2949 if isinstance(spec
, compat_str
):
2950 spec
= spec
.encode('ascii')
2951 return struct
.pack(spec
, *args
)
2953 def compat_struct_unpack(spec
, *args
):
2954 if isinstance(spec
, compat_str
):
2955 spec
= spec
.encode('ascii')
2956 return struct
.unpack(spec
, *args
)
2958 class compat_Struct(struct
.Struct
):
2959 def __init__(self
, fmt
):
2960 if isinstance(fmt
, compat_str
):
2961 fmt
= fmt
.encode('ascii')
2962 super(compat_Struct
, self
).__init
__(fmt
)
2964 compat_struct_pack
= struct
.pack
2965 compat_struct_unpack
= struct
.unpack
2966 if platform
.python_implementation() == 'IronPython' and sys
.version_info
< (2, 7, 8):
2967 class compat_Struct(struct
.Struct
):
2968 def unpack(self
, string
):
2969 if not isinstance(string
, buffer): # noqa: F821
2970 string
= buffer(string
) # noqa: F821
2971 return super(compat_Struct
, self
).unpack(string
)
2973 compat_Struct
= struct
.Struct
2977 from future_builtins
import zip as compat_zip
2978 except ImportError: # not 2.6+ or is 3.x
2980 from itertools
import izip
as compat_zip
# < 2.5 or 3.x
2985 if sys
.version_info
< (3, 3):
2986 def compat_b64decode(s
, *args
, **kwargs
):
2987 if isinstance(s
, compat_str
):
2988 s
= s
.encode('ascii')
2989 return base64
.b64decode(s
, *args
, **kwargs
)
2991 compat_b64decode
= base64
.b64decode
2994 if platform
.python_implementation() == 'PyPy' and sys
.pypy_version_info
< (5, 4, 0):
2995 # PyPy2 prior to version 5.4.0 expects byte strings as Windows function
2996 # names, see the original PyPy issue [1] and the youtube-dlc one [2].
2997 # 1. https://bitbucket.org/pypy/pypy/issues/2360/windows-ctypescdll-typeerror-function-name
2998 # 2. https://github.com/ytdl-org/youtube-dl/pull/4392
2999 def compat_ctypes_WINFUNCTYPE(*args
, **kwargs
):
3000 real
= ctypes
.WINFUNCTYPE(*args
, **kwargs
)
3002 def resf(tpl
, *args
, **kwargs
):
3004 return real((str(funcname
), dll
), *args
, **kwargs
)
3008 def compat_ctypes_WINFUNCTYPE(*args
, **kwargs
):
3009 return ctypes
.WINFUNCTYPE(*args
, **kwargs
)
3013 'compat_HTMLParseError',
3014 'compat_HTMLParser',
3018 'compat_basestring',
3021 'compat_cookiejar_Cookie',
3023 'compat_ctypes_WINFUNCTYPE',
3024 'compat_etree_Element',
3025 'compat_etree_fromstring',
3026 'compat_etree_register_namespace',
3027 'compat_expanduser',
3028 'compat_get_terminal_size',
3031 'compat_html_entities',
3032 'compat_html_entities_html5',
3033 'compat_http_client',
3034 'compat_http_server',
3036 'compat_integer_types',
3037 'compat_itertools_count',
3039 'compat_numeric_types',
3046 'compat_shlex_quote',
3047 'compat_shlex_split',
3048 'compat_socket_create_connection',
3050 'compat_struct_pack',
3051 'compat_struct_unpack',
3052 'compat_subprocess_get_DEVNULL',
3053 'compat_tokenize_tokenize',
3054 'compat_urllib_error',
3055 'compat_urllib_parse',
3056 'compat_urllib_parse_quote',
3057 'compat_urllib_parse_quote_plus',
3058 'compat_urllib_parse_unquote',
3059 'compat_urllib_parse_unquote_plus',
3060 'compat_urllib_parse_unquote_to_bytes',
3061 'compat_urllib_parse_urlencode',
3062 'compat_urllib_parse_urlparse',
3063 'compat_urllib_parse_urlunparse',
3064 'compat_urllib_request',
3065 'compat_urllib_request_DataHandler',
3066 'compat_urllib_response',
3068 'compat_urlretrieve',
3069 'compat_xml_parse_error',
3072 'workaround_optparse_bug9161',