Update coding style after pycodestyle 2.1.0
[youtube-dl] / youtube_dl / compat.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import binascii
5 import collections
6 import email
7 import getpass
8 import io
9 import optparse
10 import os
11 import re
12 import shlex
13 import shutil
14 import socket
15 import struct
16 import subprocess
17 import sys
18 import itertools
19 import xml.etree.ElementTree
20
21
22 try:
23     import urllib.request as compat_urllib_request
24 except ImportError:  # Python 2
25     import urllib2 as compat_urllib_request
26
27 try:
28     import urllib.error as compat_urllib_error
29 except ImportError:  # Python 2
30     import urllib2 as compat_urllib_error
31
32 try:
33     import urllib.parse as compat_urllib_parse
34 except ImportError:  # Python 2
35     import urllib as compat_urllib_parse
36
37 try:
38     from urllib.parse import urlparse as compat_urllib_parse_urlparse
39 except ImportError:  # Python 2
40     from urlparse import urlparse as compat_urllib_parse_urlparse
41
42 try:
43     import urllib.parse as compat_urlparse
44 except ImportError:  # Python 2
45     import urlparse as compat_urlparse
46
47 try:
48     import urllib.response as compat_urllib_response
49 except ImportError:  # Python 2
50     import urllib as compat_urllib_response
51
52 try:
53     import http.cookiejar as compat_cookiejar
54 except ImportError:  # Python 2
55     import cookielib as compat_cookiejar
56
57 try:
58     import http.cookies as compat_cookies
59 except ImportError:  # Python 2
60     import Cookie as compat_cookies
61
62 try:
63     import html.entities as compat_html_entities
64 except ImportError:  # Python 2
65     import htmlentitydefs as compat_html_entities
66
67 try:  # Python >= 3.3
68     compat_html_entities_html5 = compat_html_entities.html5
69 except AttributeError:
70     # Copied from CPython 3.5.1 html/entities.py
71     compat_html_entities_html5 = {
72         'Aacute': '\xc1',
73         'aacute': '\xe1',
74         'Aacute;': '\xc1',
75         'aacute;': '\xe1',
76         'Abreve;': '\u0102',
77         'abreve;': '\u0103',
78         'ac;': '\u223e',
79         'acd;': '\u223f',
80         'acE;': '\u223e\u0333',
81         'Acirc': '\xc2',
82         'acirc': '\xe2',
83         'Acirc;': '\xc2',
84         'acirc;': '\xe2',
85         'acute': '\xb4',
86         'acute;': '\xb4',
87         'Acy;': '\u0410',
88         'acy;': '\u0430',
89         'AElig': '\xc6',
90         'aelig': '\xe6',
91         'AElig;': '\xc6',
92         'aelig;': '\xe6',
93         'af;': '\u2061',
94         'Afr;': '\U0001d504',
95         'afr;': '\U0001d51e',
96         'Agrave': '\xc0',
97         'agrave': '\xe0',
98         'Agrave;': '\xc0',
99         'agrave;': '\xe0',
100         'alefsym;': '\u2135',
101         'aleph;': '\u2135',
102         'Alpha;': '\u0391',
103         'alpha;': '\u03b1',
104         'Amacr;': '\u0100',
105         'amacr;': '\u0101',
106         'amalg;': '\u2a3f',
107         'AMP': '&',
108         'amp': '&',
109         'AMP;': '&',
110         'amp;': '&',
111         'And;': '\u2a53',
112         'and;': '\u2227',
113         'andand;': '\u2a55',
114         'andd;': '\u2a5c',
115         'andslope;': '\u2a58',
116         'andv;': '\u2a5a',
117         'ang;': '\u2220',
118         'ange;': '\u29a4',
119         'angle;': '\u2220',
120         'angmsd;': '\u2221',
121         'angmsdaa;': '\u29a8',
122         'angmsdab;': '\u29a9',
123         'angmsdac;': '\u29aa',
124         'angmsdad;': '\u29ab',
125         'angmsdae;': '\u29ac',
126         'angmsdaf;': '\u29ad',
127         'angmsdag;': '\u29ae',
128         'angmsdah;': '\u29af',
129         'angrt;': '\u221f',
130         'angrtvb;': '\u22be',
131         'angrtvbd;': '\u299d',
132         'angsph;': '\u2222',
133         'angst;': '\xc5',
134         'angzarr;': '\u237c',
135         'Aogon;': '\u0104',
136         'aogon;': '\u0105',
137         'Aopf;': '\U0001d538',
138         'aopf;': '\U0001d552',
139         'ap;': '\u2248',
140         'apacir;': '\u2a6f',
141         'apE;': '\u2a70',
142         'ape;': '\u224a',
143         'apid;': '\u224b',
144         'apos;': "'",
145         'ApplyFunction;': '\u2061',
146         'approx;': '\u2248',
147         'approxeq;': '\u224a',
148         'Aring': '\xc5',
149         'aring': '\xe5',
150         'Aring;': '\xc5',
151         'aring;': '\xe5',
152         'Ascr;': '\U0001d49c',
153         'ascr;': '\U0001d4b6',
154         'Assign;': '\u2254',
155         'ast;': '*',
156         'asymp;': '\u2248',
157         'asympeq;': '\u224d',
158         'Atilde': '\xc3',
159         'atilde': '\xe3',
160         'Atilde;': '\xc3',
161         'atilde;': '\xe3',
162         'Auml': '\xc4',
163         'auml': '\xe4',
164         'Auml;': '\xc4',
165         'auml;': '\xe4',
166         'awconint;': '\u2233',
167         'awint;': '\u2a11',
168         'backcong;': '\u224c',
169         'backepsilon;': '\u03f6',
170         'backprime;': '\u2035',
171         'backsim;': '\u223d',
172         'backsimeq;': '\u22cd',
173         'Backslash;': '\u2216',
174         'Barv;': '\u2ae7',
175         'barvee;': '\u22bd',
176         'Barwed;': '\u2306',
177         'barwed;': '\u2305',
178         'barwedge;': '\u2305',
179         'bbrk;': '\u23b5',
180         'bbrktbrk;': '\u23b6',
181         'bcong;': '\u224c',
182         'Bcy;': '\u0411',
183         'bcy;': '\u0431',
184         'bdquo;': '\u201e',
185         'becaus;': '\u2235',
186         'Because;': '\u2235',
187         'because;': '\u2235',
188         'bemptyv;': '\u29b0',
189         'bepsi;': '\u03f6',
190         'bernou;': '\u212c',
191         'Bernoullis;': '\u212c',
192         'Beta;': '\u0392',
193         'beta;': '\u03b2',
194         'beth;': '\u2136',
195         'between;': '\u226c',
196         'Bfr;': '\U0001d505',
197         'bfr;': '\U0001d51f',
198         'bigcap;': '\u22c2',
199         'bigcirc;': '\u25ef',
200         'bigcup;': '\u22c3',
201         'bigodot;': '\u2a00',
202         'bigoplus;': '\u2a01',
203         'bigotimes;': '\u2a02',
204         'bigsqcup;': '\u2a06',
205         'bigstar;': '\u2605',
206         'bigtriangledown;': '\u25bd',
207         'bigtriangleup;': '\u25b3',
208         'biguplus;': '\u2a04',
209         'bigvee;': '\u22c1',
210         'bigwedge;': '\u22c0',
211         'bkarow;': '\u290d',
212         'blacklozenge;': '\u29eb',
213         'blacksquare;': '\u25aa',
214         'blacktriangle;': '\u25b4',
215         'blacktriangledown;': '\u25be',
216         'blacktriangleleft;': '\u25c2',
217         'blacktriangleright;': '\u25b8',
218         'blank;': '\u2423',
219         'blk12;': '\u2592',
220         'blk14;': '\u2591',
221         'blk34;': '\u2593',
222         'block;': '\u2588',
223         'bne;': '=\u20e5',
224         'bnequiv;': '\u2261\u20e5',
225         'bNot;': '\u2aed',
226         'bnot;': '\u2310',
227         'Bopf;': '\U0001d539',
228         'bopf;': '\U0001d553',
229         'bot;': '\u22a5',
230         'bottom;': '\u22a5',
231         'bowtie;': '\u22c8',
232         'boxbox;': '\u29c9',
233         'boxDL;': '\u2557',
234         'boxDl;': '\u2556',
235         'boxdL;': '\u2555',
236         'boxdl;': '\u2510',
237         'boxDR;': '\u2554',
238         'boxDr;': '\u2553',
239         'boxdR;': '\u2552',
240         'boxdr;': '\u250c',
241         'boxH;': '\u2550',
242         'boxh;': '\u2500',
243         'boxHD;': '\u2566',
244         'boxHd;': '\u2564',
245         'boxhD;': '\u2565',
246         'boxhd;': '\u252c',
247         'boxHU;': '\u2569',
248         'boxHu;': '\u2567',
249         'boxhU;': '\u2568',
250         'boxhu;': '\u2534',
251         'boxminus;': '\u229f',
252         'boxplus;': '\u229e',
253         'boxtimes;': '\u22a0',
254         'boxUL;': '\u255d',
255         'boxUl;': '\u255c',
256         'boxuL;': '\u255b',
257         'boxul;': '\u2518',
258         'boxUR;': '\u255a',
259         'boxUr;': '\u2559',
260         'boxuR;': '\u2558',
261         'boxur;': '\u2514',
262         'boxV;': '\u2551',
263         'boxv;': '\u2502',
264         'boxVH;': '\u256c',
265         'boxVh;': '\u256b',
266         'boxvH;': '\u256a',
267         'boxvh;': '\u253c',
268         'boxVL;': '\u2563',
269         'boxVl;': '\u2562',
270         'boxvL;': '\u2561',
271         'boxvl;': '\u2524',
272         'boxVR;': '\u2560',
273         'boxVr;': '\u255f',
274         'boxvR;': '\u255e',
275         'boxvr;': '\u251c',
276         'bprime;': '\u2035',
277         'Breve;': '\u02d8',
278         'breve;': '\u02d8',
279         'brvbar': '\xa6',
280         'brvbar;': '\xa6',
281         'Bscr;': '\u212c',
282         'bscr;': '\U0001d4b7',
283         'bsemi;': '\u204f',
284         'bsim;': '\u223d',
285         'bsime;': '\u22cd',
286         'bsol;': '\\',
287         'bsolb;': '\u29c5',
288         'bsolhsub;': '\u27c8',
289         'bull;': '\u2022',
290         'bullet;': '\u2022',
291         'bump;': '\u224e',
292         'bumpE;': '\u2aae',
293         'bumpe;': '\u224f',
294         'Bumpeq;': '\u224e',
295         'bumpeq;': '\u224f',
296         'Cacute;': '\u0106',
297         'cacute;': '\u0107',
298         'Cap;': '\u22d2',
299         'cap;': '\u2229',
300         'capand;': '\u2a44',
301         'capbrcup;': '\u2a49',
302         'capcap;': '\u2a4b',
303         'capcup;': '\u2a47',
304         'capdot;': '\u2a40',
305         'CapitalDifferentialD;': '\u2145',
306         'caps;': '\u2229\ufe00',
307         'caret;': '\u2041',
308         'caron;': '\u02c7',
309         'Cayleys;': '\u212d',
310         'ccaps;': '\u2a4d',
311         'Ccaron;': '\u010c',
312         'ccaron;': '\u010d',
313         'Ccedil': '\xc7',
314         'ccedil': '\xe7',
315         'Ccedil;': '\xc7',
316         'ccedil;': '\xe7',
317         'Ccirc;': '\u0108',
318         'ccirc;': '\u0109',
319         'Cconint;': '\u2230',
320         'ccups;': '\u2a4c',
321         'ccupssm;': '\u2a50',
322         'Cdot;': '\u010a',
323         'cdot;': '\u010b',
324         'cedil': '\xb8',
325         'cedil;': '\xb8',
326         'Cedilla;': '\xb8',
327         'cemptyv;': '\u29b2',
328         'cent': '\xa2',
329         'cent;': '\xa2',
330         'CenterDot;': '\xb7',
331         'centerdot;': '\xb7',
332         'Cfr;': '\u212d',
333         'cfr;': '\U0001d520',
334         'CHcy;': '\u0427',
335         'chcy;': '\u0447',
336         'check;': '\u2713',
337         'checkmark;': '\u2713',
338         'Chi;': '\u03a7',
339         'chi;': '\u03c7',
340         'cir;': '\u25cb',
341         'circ;': '\u02c6',
342         'circeq;': '\u2257',
343         'circlearrowleft;': '\u21ba',
344         'circlearrowright;': '\u21bb',
345         'circledast;': '\u229b',
346         'circledcirc;': '\u229a',
347         'circleddash;': '\u229d',
348         'CircleDot;': '\u2299',
349         'circledR;': '\xae',
350         'circledS;': '\u24c8',
351         'CircleMinus;': '\u2296',
352         'CirclePlus;': '\u2295',
353         'CircleTimes;': '\u2297',
354         'cirE;': '\u29c3',
355         'cire;': '\u2257',
356         'cirfnint;': '\u2a10',
357         'cirmid;': '\u2aef',
358         'cirscir;': '\u29c2',
359         'ClockwiseContourIntegral;': '\u2232',
360         'CloseCurlyDoubleQuote;': '\u201d',
361         'CloseCurlyQuote;': '\u2019',
362         'clubs;': '\u2663',
363         'clubsuit;': '\u2663',
364         'Colon;': '\u2237',
365         'colon;': ':',
366         'Colone;': '\u2a74',
367         'colone;': '\u2254',
368         'coloneq;': '\u2254',
369         'comma;': ',',
370         'commat;': '@',
371         'comp;': '\u2201',
372         'compfn;': '\u2218',
373         'complement;': '\u2201',
374         'complexes;': '\u2102',
375         'cong;': '\u2245',
376         'congdot;': '\u2a6d',
377         'Congruent;': '\u2261',
378         'Conint;': '\u222f',
379         'conint;': '\u222e',
380         'ContourIntegral;': '\u222e',
381         'Copf;': '\u2102',
382         'copf;': '\U0001d554',
383         'coprod;': '\u2210',
384         'Coproduct;': '\u2210',
385         'COPY': '\xa9',
386         'copy': '\xa9',
387         'COPY;': '\xa9',
388         'copy;': '\xa9',
389         'copysr;': '\u2117',
390         'CounterClockwiseContourIntegral;': '\u2233',
391         'crarr;': '\u21b5',
392         'Cross;': '\u2a2f',
393         'cross;': '\u2717',
394         'Cscr;': '\U0001d49e',
395         'cscr;': '\U0001d4b8',
396         'csub;': '\u2acf',
397         'csube;': '\u2ad1',
398         'csup;': '\u2ad0',
399         'csupe;': '\u2ad2',
400         'ctdot;': '\u22ef',
401         'cudarrl;': '\u2938',
402         'cudarrr;': '\u2935',
403         'cuepr;': '\u22de',
404         'cuesc;': '\u22df',
405         'cularr;': '\u21b6',
406         'cularrp;': '\u293d',
407         'Cup;': '\u22d3',
408         'cup;': '\u222a',
409         'cupbrcap;': '\u2a48',
410         'CupCap;': '\u224d',
411         'cupcap;': '\u2a46',
412         'cupcup;': '\u2a4a',
413         'cupdot;': '\u228d',
414         'cupor;': '\u2a45',
415         'cups;': '\u222a\ufe00',
416         'curarr;': '\u21b7',
417         'curarrm;': '\u293c',
418         'curlyeqprec;': '\u22de',
419         'curlyeqsucc;': '\u22df',
420         'curlyvee;': '\u22ce',
421         'curlywedge;': '\u22cf',
422         'curren': '\xa4',
423         'curren;': '\xa4',
424         'curvearrowleft;': '\u21b6',
425         'curvearrowright;': '\u21b7',
426         'cuvee;': '\u22ce',
427         'cuwed;': '\u22cf',
428         'cwconint;': '\u2232',
429         'cwint;': '\u2231',
430         'cylcty;': '\u232d',
431         'Dagger;': '\u2021',
432         'dagger;': '\u2020',
433         'daleth;': '\u2138',
434         'Darr;': '\u21a1',
435         'dArr;': '\u21d3',
436         'darr;': '\u2193',
437         'dash;': '\u2010',
438         'Dashv;': '\u2ae4',
439         'dashv;': '\u22a3',
440         'dbkarow;': '\u290f',
441         'dblac;': '\u02dd',
442         'Dcaron;': '\u010e',
443         'dcaron;': '\u010f',
444         'Dcy;': '\u0414',
445         'dcy;': '\u0434',
446         'DD;': '\u2145',
447         'dd;': '\u2146',
448         'ddagger;': '\u2021',
449         'ddarr;': '\u21ca',
450         'DDotrahd;': '\u2911',
451         'ddotseq;': '\u2a77',
452         'deg': '\xb0',
453         'deg;': '\xb0',
454         'Del;': '\u2207',
455         'Delta;': '\u0394',
456         'delta;': '\u03b4',
457         'demptyv;': '\u29b1',
458         'dfisht;': '\u297f',
459         'Dfr;': '\U0001d507',
460         'dfr;': '\U0001d521',
461         'dHar;': '\u2965',
462         'dharl;': '\u21c3',
463         'dharr;': '\u21c2',
464         'DiacriticalAcute;': '\xb4',
465         'DiacriticalDot;': '\u02d9',
466         'DiacriticalDoubleAcute;': '\u02dd',
467         'DiacriticalGrave;': '`',
468         'DiacriticalTilde;': '\u02dc',
469         'diam;': '\u22c4',
470         'Diamond;': '\u22c4',
471         'diamond;': '\u22c4',
472         'diamondsuit;': '\u2666',
473         'diams;': '\u2666',
474         'die;': '\xa8',
475         'DifferentialD;': '\u2146',
476         'digamma;': '\u03dd',
477         'disin;': '\u22f2',
478         'div;': '\xf7',
479         'divide': '\xf7',
480         'divide;': '\xf7',
481         'divideontimes;': '\u22c7',
482         'divonx;': '\u22c7',
483         'DJcy;': '\u0402',
484         'djcy;': '\u0452',
485         'dlcorn;': '\u231e',
486         'dlcrop;': '\u230d',
487         'dollar;': '$',
488         'Dopf;': '\U0001d53b',
489         'dopf;': '\U0001d555',
490         'Dot;': '\xa8',
491         'dot;': '\u02d9',
492         'DotDot;': '\u20dc',
493         'doteq;': '\u2250',
494         'doteqdot;': '\u2251',
495         'DotEqual;': '\u2250',
496         'dotminus;': '\u2238',
497         'dotplus;': '\u2214',
498         'dotsquare;': '\u22a1',
499         'doublebarwedge;': '\u2306',
500         'DoubleContourIntegral;': '\u222f',
501         'DoubleDot;': '\xa8',
502         'DoubleDownArrow;': '\u21d3',
503         'DoubleLeftArrow;': '\u21d0',
504         'DoubleLeftRightArrow;': '\u21d4',
505         'DoubleLeftTee;': '\u2ae4',
506         'DoubleLongLeftArrow;': '\u27f8',
507         'DoubleLongLeftRightArrow;': '\u27fa',
508         'DoubleLongRightArrow;': '\u27f9',
509         'DoubleRightArrow;': '\u21d2',
510         'DoubleRightTee;': '\u22a8',
511         'DoubleUpArrow;': '\u21d1',
512         'DoubleUpDownArrow;': '\u21d5',
513         'DoubleVerticalBar;': '\u2225',
514         'DownArrow;': '\u2193',
515         'Downarrow;': '\u21d3',
516         'downarrow;': '\u2193',
517         'DownArrowBar;': '\u2913',
518         'DownArrowUpArrow;': '\u21f5',
519         'DownBreve;': '\u0311',
520         'downdownarrows;': '\u21ca',
521         'downharpoonleft;': '\u21c3',
522         'downharpoonright;': '\u21c2',
523         'DownLeftRightVector;': '\u2950',
524         'DownLeftTeeVector;': '\u295e',
525         'DownLeftVector;': '\u21bd',
526         'DownLeftVectorBar;': '\u2956',
527         'DownRightTeeVector;': '\u295f',
528         'DownRightVector;': '\u21c1',
529         'DownRightVectorBar;': '\u2957',
530         'DownTee;': '\u22a4',
531         'DownTeeArrow;': '\u21a7',
532         'drbkarow;': '\u2910',
533         'drcorn;': '\u231f',
534         'drcrop;': '\u230c',
535         'Dscr;': '\U0001d49f',
536         'dscr;': '\U0001d4b9',
537         'DScy;': '\u0405',
538         'dscy;': '\u0455',
539         'dsol;': '\u29f6',
540         'Dstrok;': '\u0110',
541         'dstrok;': '\u0111',
542         'dtdot;': '\u22f1',
543         'dtri;': '\u25bf',
544         'dtrif;': '\u25be',
545         'duarr;': '\u21f5',
546         'duhar;': '\u296f',
547         'dwangle;': '\u29a6',
548         'DZcy;': '\u040f',
549         'dzcy;': '\u045f',
550         'dzigrarr;': '\u27ff',
551         'Eacute': '\xc9',
552         'eacute': '\xe9',
553         'Eacute;': '\xc9',
554         'eacute;': '\xe9',
555         'easter;': '\u2a6e',
556         'Ecaron;': '\u011a',
557         'ecaron;': '\u011b',
558         'ecir;': '\u2256',
559         'Ecirc': '\xca',
560         'ecirc': '\xea',
561         'Ecirc;': '\xca',
562         'ecirc;': '\xea',
563         'ecolon;': '\u2255',
564         'Ecy;': '\u042d',
565         'ecy;': '\u044d',
566         'eDDot;': '\u2a77',
567         'Edot;': '\u0116',
568         'eDot;': '\u2251',
569         'edot;': '\u0117',
570         'ee;': '\u2147',
571         'efDot;': '\u2252',
572         'Efr;': '\U0001d508',
573         'efr;': '\U0001d522',
574         'eg;': '\u2a9a',
575         'Egrave': '\xc8',
576         'egrave': '\xe8',
577         'Egrave;': '\xc8',
578         'egrave;': '\xe8',
579         'egs;': '\u2a96',
580         'egsdot;': '\u2a98',
581         'el;': '\u2a99',
582         'Element;': '\u2208',
583         'elinters;': '\u23e7',
584         'ell;': '\u2113',
585         'els;': '\u2a95',
586         'elsdot;': '\u2a97',
587         'Emacr;': '\u0112',
588         'emacr;': '\u0113',
589         'empty;': '\u2205',
590         'emptyset;': '\u2205',
591         'EmptySmallSquare;': '\u25fb',
592         'emptyv;': '\u2205',
593         'EmptyVerySmallSquare;': '\u25ab',
594         'emsp13;': '\u2004',
595         'emsp14;': '\u2005',
596         'emsp;': '\u2003',
597         'ENG;': '\u014a',
598         'eng;': '\u014b',
599         'ensp;': '\u2002',
600         'Eogon;': '\u0118',
601         'eogon;': '\u0119',
602         'Eopf;': '\U0001d53c',
603         'eopf;': '\U0001d556',
604         'epar;': '\u22d5',
605         'eparsl;': '\u29e3',
606         'eplus;': '\u2a71',
607         'epsi;': '\u03b5',
608         'Epsilon;': '\u0395',
609         'epsilon;': '\u03b5',
610         'epsiv;': '\u03f5',
611         'eqcirc;': '\u2256',
612         'eqcolon;': '\u2255',
613         'eqsim;': '\u2242',
614         'eqslantgtr;': '\u2a96',
615         'eqslantless;': '\u2a95',
616         'Equal;': '\u2a75',
617         'equals;': '=',
618         'EqualTilde;': '\u2242',
619         'equest;': '\u225f',
620         'Equilibrium;': '\u21cc',
621         'equiv;': '\u2261',
622         'equivDD;': '\u2a78',
623         'eqvparsl;': '\u29e5',
624         'erarr;': '\u2971',
625         'erDot;': '\u2253',
626         'Escr;': '\u2130',
627         'escr;': '\u212f',
628         'esdot;': '\u2250',
629         'Esim;': '\u2a73',
630         'esim;': '\u2242',
631         'Eta;': '\u0397',
632         'eta;': '\u03b7',
633         'ETH': '\xd0',
634         'eth': '\xf0',
635         'ETH;': '\xd0',
636         'eth;': '\xf0',
637         'Euml': '\xcb',
638         'euml': '\xeb',
639         'Euml;': '\xcb',
640         'euml;': '\xeb',
641         'euro;': '\u20ac',
642         'excl;': '!',
643         'exist;': '\u2203',
644         'Exists;': '\u2203',
645         'expectation;': '\u2130',
646         'ExponentialE;': '\u2147',
647         'exponentiale;': '\u2147',
648         'fallingdotseq;': '\u2252',
649         'Fcy;': '\u0424',
650         'fcy;': '\u0444',
651         'female;': '\u2640',
652         'ffilig;': '\ufb03',
653         'fflig;': '\ufb00',
654         'ffllig;': '\ufb04',
655         'Ffr;': '\U0001d509',
656         'ffr;': '\U0001d523',
657         'filig;': '\ufb01',
658         'FilledSmallSquare;': '\u25fc',
659         'FilledVerySmallSquare;': '\u25aa',
660         'fjlig;': 'fj',
661         'flat;': '\u266d',
662         'fllig;': '\ufb02',
663         'fltns;': '\u25b1',
664         'fnof;': '\u0192',
665         'Fopf;': '\U0001d53d',
666         'fopf;': '\U0001d557',
667         'ForAll;': '\u2200',
668         'forall;': '\u2200',
669         'fork;': '\u22d4',
670         'forkv;': '\u2ad9',
671         'Fouriertrf;': '\u2131',
672         'fpartint;': '\u2a0d',
673         'frac12': '\xbd',
674         'frac12;': '\xbd',
675         'frac13;': '\u2153',
676         'frac14': '\xbc',
677         'frac14;': '\xbc',
678         'frac15;': '\u2155',
679         'frac16;': '\u2159',
680         'frac18;': '\u215b',
681         'frac23;': '\u2154',
682         'frac25;': '\u2156',
683         'frac34': '\xbe',
684         'frac34;': '\xbe',
685         'frac35;': '\u2157',
686         'frac38;': '\u215c',
687         'frac45;': '\u2158',
688         'frac56;': '\u215a',
689         'frac58;': '\u215d',
690         'frac78;': '\u215e',
691         'frasl;': '\u2044',
692         'frown;': '\u2322',
693         'Fscr;': '\u2131',
694         'fscr;': '\U0001d4bb',
695         'gacute;': '\u01f5',
696         'Gamma;': '\u0393',
697         'gamma;': '\u03b3',
698         'Gammad;': '\u03dc',
699         'gammad;': '\u03dd',
700         'gap;': '\u2a86',
701         'Gbreve;': '\u011e',
702         'gbreve;': '\u011f',
703         'Gcedil;': '\u0122',
704         'Gcirc;': '\u011c',
705         'gcirc;': '\u011d',
706         'Gcy;': '\u0413',
707         'gcy;': '\u0433',
708         'Gdot;': '\u0120',
709         'gdot;': '\u0121',
710         'gE;': '\u2267',
711         'ge;': '\u2265',
712         'gEl;': '\u2a8c',
713         'gel;': '\u22db',
714         'geq;': '\u2265',
715         'geqq;': '\u2267',
716         'geqslant;': '\u2a7e',
717         'ges;': '\u2a7e',
718         'gescc;': '\u2aa9',
719         'gesdot;': '\u2a80',
720         'gesdoto;': '\u2a82',
721         'gesdotol;': '\u2a84',
722         'gesl;': '\u22db\ufe00',
723         'gesles;': '\u2a94',
724         'Gfr;': '\U0001d50a',
725         'gfr;': '\U0001d524',
726         'Gg;': '\u22d9',
727         'gg;': '\u226b',
728         'ggg;': '\u22d9',
729         'gimel;': '\u2137',
730         'GJcy;': '\u0403',
731         'gjcy;': '\u0453',
732         'gl;': '\u2277',
733         'gla;': '\u2aa5',
734         'glE;': '\u2a92',
735         'glj;': '\u2aa4',
736         'gnap;': '\u2a8a',
737         'gnapprox;': '\u2a8a',
738         'gnE;': '\u2269',
739         'gne;': '\u2a88',
740         'gneq;': '\u2a88',
741         'gneqq;': '\u2269',
742         'gnsim;': '\u22e7',
743         'Gopf;': '\U0001d53e',
744         'gopf;': '\U0001d558',
745         'grave;': '`',
746         'GreaterEqual;': '\u2265',
747         'GreaterEqualLess;': '\u22db',
748         'GreaterFullEqual;': '\u2267',
749         'GreaterGreater;': '\u2aa2',
750         'GreaterLess;': '\u2277',
751         'GreaterSlantEqual;': '\u2a7e',
752         'GreaterTilde;': '\u2273',
753         'Gscr;': '\U0001d4a2',
754         'gscr;': '\u210a',
755         'gsim;': '\u2273',
756         'gsime;': '\u2a8e',
757         'gsiml;': '\u2a90',
758         'GT': '>',
759         'gt': '>',
760         'GT;': '>',
761         'Gt;': '\u226b',
762         'gt;': '>',
763         'gtcc;': '\u2aa7',
764         'gtcir;': '\u2a7a',
765         'gtdot;': '\u22d7',
766         'gtlPar;': '\u2995',
767         'gtquest;': '\u2a7c',
768         'gtrapprox;': '\u2a86',
769         'gtrarr;': '\u2978',
770         'gtrdot;': '\u22d7',
771         'gtreqless;': '\u22db',
772         'gtreqqless;': '\u2a8c',
773         'gtrless;': '\u2277',
774         'gtrsim;': '\u2273',
775         'gvertneqq;': '\u2269\ufe00',
776         'gvnE;': '\u2269\ufe00',
777         'Hacek;': '\u02c7',
778         'hairsp;': '\u200a',
779         'half;': '\xbd',
780         'hamilt;': '\u210b',
781         'HARDcy;': '\u042a',
782         'hardcy;': '\u044a',
783         'hArr;': '\u21d4',
784         'harr;': '\u2194',
785         'harrcir;': '\u2948',
786         'harrw;': '\u21ad',
787         'Hat;': '^',
788         'hbar;': '\u210f',
789         'Hcirc;': '\u0124',
790         'hcirc;': '\u0125',
791         'hearts;': '\u2665',
792         'heartsuit;': '\u2665',
793         'hellip;': '\u2026',
794         'hercon;': '\u22b9',
795         'Hfr;': '\u210c',
796         'hfr;': '\U0001d525',
797         'HilbertSpace;': '\u210b',
798         'hksearow;': '\u2925',
799         'hkswarow;': '\u2926',
800         'hoarr;': '\u21ff',
801         'homtht;': '\u223b',
802         'hookleftarrow;': '\u21a9',
803         'hookrightarrow;': '\u21aa',
804         'Hopf;': '\u210d',
805         'hopf;': '\U0001d559',
806         'horbar;': '\u2015',
807         'HorizontalLine;': '\u2500',
808         'Hscr;': '\u210b',
809         'hscr;': '\U0001d4bd',
810         'hslash;': '\u210f',
811         'Hstrok;': '\u0126',
812         'hstrok;': '\u0127',
813         'HumpDownHump;': '\u224e',
814         'HumpEqual;': '\u224f',
815         'hybull;': '\u2043',
816         'hyphen;': '\u2010',
817         'Iacute': '\xcd',
818         'iacute': '\xed',
819         'Iacute;': '\xcd',
820         'iacute;': '\xed',
821         'ic;': '\u2063',
822         'Icirc': '\xce',
823         'icirc': '\xee',
824         'Icirc;': '\xce',
825         'icirc;': '\xee',
826         'Icy;': '\u0418',
827         'icy;': '\u0438',
828         'Idot;': '\u0130',
829         'IEcy;': '\u0415',
830         'iecy;': '\u0435',
831         'iexcl': '\xa1',
832         'iexcl;': '\xa1',
833         'iff;': '\u21d4',
834         'Ifr;': '\u2111',
835         'ifr;': '\U0001d526',
836         'Igrave': '\xcc',
837         'igrave': '\xec',
838         'Igrave;': '\xcc',
839         'igrave;': '\xec',
840         'ii;': '\u2148',
841         'iiiint;': '\u2a0c',
842         'iiint;': '\u222d',
843         'iinfin;': '\u29dc',
844         'iiota;': '\u2129',
845         'IJlig;': '\u0132',
846         'ijlig;': '\u0133',
847         'Im;': '\u2111',
848         'Imacr;': '\u012a',
849         'imacr;': '\u012b',
850         'image;': '\u2111',
851         'ImaginaryI;': '\u2148',
852         'imagline;': '\u2110',
853         'imagpart;': '\u2111',
854         'imath;': '\u0131',
855         'imof;': '\u22b7',
856         'imped;': '\u01b5',
857         'Implies;': '\u21d2',
858         'in;': '\u2208',
859         'incare;': '\u2105',
860         'infin;': '\u221e',
861         'infintie;': '\u29dd',
862         'inodot;': '\u0131',
863         'Int;': '\u222c',
864         'int;': '\u222b',
865         'intcal;': '\u22ba',
866         'integers;': '\u2124',
867         'Integral;': '\u222b',
868         'intercal;': '\u22ba',
869         'Intersection;': '\u22c2',
870         'intlarhk;': '\u2a17',
871         'intprod;': '\u2a3c',
872         'InvisibleComma;': '\u2063',
873         'InvisibleTimes;': '\u2062',
874         'IOcy;': '\u0401',
875         'iocy;': '\u0451',
876         'Iogon;': '\u012e',
877         'iogon;': '\u012f',
878         'Iopf;': '\U0001d540',
879         'iopf;': '\U0001d55a',
880         'Iota;': '\u0399',
881         'iota;': '\u03b9',
882         'iprod;': '\u2a3c',
883         'iquest': '\xbf',
884         'iquest;': '\xbf',
885         'Iscr;': '\u2110',
886         'iscr;': '\U0001d4be',
887         'isin;': '\u2208',
888         'isindot;': '\u22f5',
889         'isinE;': '\u22f9',
890         'isins;': '\u22f4',
891         'isinsv;': '\u22f3',
892         'isinv;': '\u2208',
893         'it;': '\u2062',
894         'Itilde;': '\u0128',
895         'itilde;': '\u0129',
896         'Iukcy;': '\u0406',
897         'iukcy;': '\u0456',
898         'Iuml': '\xcf',
899         'iuml': '\xef',
900         'Iuml;': '\xcf',
901         'iuml;': '\xef',
902         'Jcirc;': '\u0134',
903         'jcirc;': '\u0135',
904         'Jcy;': '\u0419',
905         'jcy;': '\u0439',
906         'Jfr;': '\U0001d50d',
907         'jfr;': '\U0001d527',
908         'jmath;': '\u0237',
909         'Jopf;': '\U0001d541',
910         'jopf;': '\U0001d55b',
911         'Jscr;': '\U0001d4a5',
912         'jscr;': '\U0001d4bf',
913         'Jsercy;': '\u0408',
914         'jsercy;': '\u0458',
915         'Jukcy;': '\u0404',
916         'jukcy;': '\u0454',
917         'Kappa;': '\u039a',
918         'kappa;': '\u03ba',
919         'kappav;': '\u03f0',
920         'Kcedil;': '\u0136',
921         'kcedil;': '\u0137',
922         'Kcy;': '\u041a',
923         'kcy;': '\u043a',
924         'Kfr;': '\U0001d50e',
925         'kfr;': '\U0001d528',
926         'kgreen;': '\u0138',
927         'KHcy;': '\u0425',
928         'khcy;': '\u0445',
929         'KJcy;': '\u040c',
930         'kjcy;': '\u045c',
931         'Kopf;': '\U0001d542',
932         'kopf;': '\U0001d55c',
933         'Kscr;': '\U0001d4a6',
934         'kscr;': '\U0001d4c0',
935         'lAarr;': '\u21da',
936         'Lacute;': '\u0139',
937         'lacute;': '\u013a',
938         'laemptyv;': '\u29b4',
939         'lagran;': '\u2112',
940         'Lambda;': '\u039b',
941         'lambda;': '\u03bb',
942         'Lang;': '\u27ea',
943         'lang;': '\u27e8',
944         'langd;': '\u2991',
945         'langle;': '\u27e8',
946         'lap;': '\u2a85',
947         'Laplacetrf;': '\u2112',
948         'laquo': '\xab',
949         'laquo;': '\xab',
950         'Larr;': '\u219e',
951         'lArr;': '\u21d0',
952         'larr;': '\u2190',
953         'larrb;': '\u21e4',
954         'larrbfs;': '\u291f',
955         'larrfs;': '\u291d',
956         'larrhk;': '\u21a9',
957         'larrlp;': '\u21ab',
958         'larrpl;': '\u2939',
959         'larrsim;': '\u2973',
960         'larrtl;': '\u21a2',
961         'lat;': '\u2aab',
962         'lAtail;': '\u291b',
963         'latail;': '\u2919',
964         'late;': '\u2aad',
965         'lates;': '\u2aad\ufe00',
966         'lBarr;': '\u290e',
967         'lbarr;': '\u290c',
968         'lbbrk;': '\u2772',
969         'lbrace;': '{',
970         'lbrack;': '[',
971         'lbrke;': '\u298b',
972         'lbrksld;': '\u298f',
973         'lbrkslu;': '\u298d',
974         'Lcaron;': '\u013d',
975         'lcaron;': '\u013e',
976         'Lcedil;': '\u013b',
977         'lcedil;': '\u013c',
978         'lceil;': '\u2308',
979         'lcub;': '{',
980         'Lcy;': '\u041b',
981         'lcy;': '\u043b',
982         'ldca;': '\u2936',
983         'ldquo;': '\u201c',
984         'ldquor;': '\u201e',
985         'ldrdhar;': '\u2967',
986         'ldrushar;': '\u294b',
987         'ldsh;': '\u21b2',
988         'lE;': '\u2266',
989         'le;': '\u2264',
990         'LeftAngleBracket;': '\u27e8',
991         'LeftArrow;': '\u2190',
992         'Leftarrow;': '\u21d0',
993         'leftarrow;': '\u2190',
994         'LeftArrowBar;': '\u21e4',
995         'LeftArrowRightArrow;': '\u21c6',
996         'leftarrowtail;': '\u21a2',
997         'LeftCeiling;': '\u2308',
998         'LeftDoubleBracket;': '\u27e6',
999         'LeftDownTeeVector;': '\u2961',
1000         'LeftDownVector;': '\u21c3',
1001         'LeftDownVectorBar;': '\u2959',
1002         'LeftFloor;': '\u230a',
1003         'leftharpoondown;': '\u21bd',
1004         'leftharpoonup;': '\u21bc',
1005         'leftleftarrows;': '\u21c7',
1006         'LeftRightArrow;': '\u2194',
1007         'Leftrightarrow;': '\u21d4',
1008         'leftrightarrow;': '\u2194',
1009         'leftrightarrows;': '\u21c6',
1010         'leftrightharpoons;': '\u21cb',
1011         'leftrightsquigarrow;': '\u21ad',
1012         'LeftRightVector;': '\u294e',
1013         'LeftTee;': '\u22a3',
1014         'LeftTeeArrow;': '\u21a4',
1015         'LeftTeeVector;': '\u295a',
1016         'leftthreetimes;': '\u22cb',
1017         'LeftTriangle;': '\u22b2',
1018         'LeftTriangleBar;': '\u29cf',
1019         'LeftTriangleEqual;': '\u22b4',
1020         'LeftUpDownVector;': '\u2951',
1021         'LeftUpTeeVector;': '\u2960',
1022         'LeftUpVector;': '\u21bf',
1023         'LeftUpVectorBar;': '\u2958',
1024         'LeftVector;': '\u21bc',
1025         'LeftVectorBar;': '\u2952',
1026         'lEg;': '\u2a8b',
1027         'leg;': '\u22da',
1028         'leq;': '\u2264',
1029         'leqq;': '\u2266',
1030         'leqslant;': '\u2a7d',
1031         'les;': '\u2a7d',
1032         'lescc;': '\u2aa8',
1033         'lesdot;': '\u2a7f',
1034         'lesdoto;': '\u2a81',
1035         'lesdotor;': '\u2a83',
1036         'lesg;': '\u22da\ufe00',
1037         'lesges;': '\u2a93',
1038         'lessapprox;': '\u2a85',
1039         'lessdot;': '\u22d6',
1040         'lesseqgtr;': '\u22da',
1041         'lesseqqgtr;': '\u2a8b',
1042         'LessEqualGreater;': '\u22da',
1043         'LessFullEqual;': '\u2266',
1044         'LessGreater;': '\u2276',
1045         'lessgtr;': '\u2276',
1046         'LessLess;': '\u2aa1',
1047         'lesssim;': '\u2272',
1048         'LessSlantEqual;': '\u2a7d',
1049         'LessTilde;': '\u2272',
1050         'lfisht;': '\u297c',
1051         'lfloor;': '\u230a',
1052         'Lfr;': '\U0001d50f',
1053         'lfr;': '\U0001d529',
1054         'lg;': '\u2276',
1055         'lgE;': '\u2a91',
1056         'lHar;': '\u2962',
1057         'lhard;': '\u21bd',
1058         'lharu;': '\u21bc',
1059         'lharul;': '\u296a',
1060         'lhblk;': '\u2584',
1061         'LJcy;': '\u0409',
1062         'ljcy;': '\u0459',
1063         'Ll;': '\u22d8',
1064         'll;': '\u226a',
1065         'llarr;': '\u21c7',
1066         'llcorner;': '\u231e',
1067         'Lleftarrow;': '\u21da',
1068         'llhard;': '\u296b',
1069         'lltri;': '\u25fa',
1070         'Lmidot;': '\u013f',
1071         'lmidot;': '\u0140',
1072         'lmoust;': '\u23b0',
1073         'lmoustache;': '\u23b0',
1074         'lnap;': '\u2a89',
1075         'lnapprox;': '\u2a89',
1076         'lnE;': '\u2268',
1077         'lne;': '\u2a87',
1078         'lneq;': '\u2a87',
1079         'lneqq;': '\u2268',
1080         'lnsim;': '\u22e6',
1081         'loang;': '\u27ec',
1082         'loarr;': '\u21fd',
1083         'lobrk;': '\u27e6',
1084         'LongLeftArrow;': '\u27f5',
1085         'Longleftarrow;': '\u27f8',
1086         'longleftarrow;': '\u27f5',
1087         'LongLeftRightArrow;': '\u27f7',
1088         'Longleftrightarrow;': '\u27fa',
1089         'longleftrightarrow;': '\u27f7',
1090         'longmapsto;': '\u27fc',
1091         'LongRightArrow;': '\u27f6',
1092         'Longrightarrow;': '\u27f9',
1093         'longrightarrow;': '\u27f6',
1094         'looparrowleft;': '\u21ab',
1095         'looparrowright;': '\u21ac',
1096         'lopar;': '\u2985',
1097         'Lopf;': '\U0001d543',
1098         'lopf;': '\U0001d55d',
1099         'loplus;': '\u2a2d',
1100         'lotimes;': '\u2a34',
1101         'lowast;': '\u2217',
1102         'lowbar;': '_',
1103         'LowerLeftArrow;': '\u2199',
1104         'LowerRightArrow;': '\u2198',
1105         'loz;': '\u25ca',
1106         'lozenge;': '\u25ca',
1107         'lozf;': '\u29eb',
1108         'lpar;': '(',
1109         'lparlt;': '\u2993',
1110         'lrarr;': '\u21c6',
1111         'lrcorner;': '\u231f',
1112         'lrhar;': '\u21cb',
1113         'lrhard;': '\u296d',
1114         'lrm;': '\u200e',
1115         'lrtri;': '\u22bf',
1116         'lsaquo;': '\u2039',
1117         'Lscr;': '\u2112',
1118         'lscr;': '\U0001d4c1',
1119         'Lsh;': '\u21b0',
1120         'lsh;': '\u21b0',
1121         'lsim;': '\u2272',
1122         'lsime;': '\u2a8d',
1123         'lsimg;': '\u2a8f',
1124         'lsqb;': '[',
1125         'lsquo;': '\u2018',
1126         'lsquor;': '\u201a',
1127         'Lstrok;': '\u0141',
1128         'lstrok;': '\u0142',
1129         'LT': '<',
1130         'lt': '<',
1131         'LT;': '<',
1132         'Lt;': '\u226a',
1133         'lt;': '<',
1134         'ltcc;': '\u2aa6',
1135         'ltcir;': '\u2a79',
1136         'ltdot;': '\u22d6',
1137         'lthree;': '\u22cb',
1138         'ltimes;': '\u22c9',
1139         'ltlarr;': '\u2976',
1140         'ltquest;': '\u2a7b',
1141         'ltri;': '\u25c3',
1142         'ltrie;': '\u22b4',
1143         'ltrif;': '\u25c2',
1144         'ltrPar;': '\u2996',
1145         'lurdshar;': '\u294a',
1146         'luruhar;': '\u2966',
1147         'lvertneqq;': '\u2268\ufe00',
1148         'lvnE;': '\u2268\ufe00',
1149         'macr': '\xaf',
1150         'macr;': '\xaf',
1151         'male;': '\u2642',
1152         'malt;': '\u2720',
1153         'maltese;': '\u2720',
1154         'Map;': '\u2905',
1155         'map;': '\u21a6',
1156         'mapsto;': '\u21a6',
1157         'mapstodown;': '\u21a7',
1158         'mapstoleft;': '\u21a4',
1159         'mapstoup;': '\u21a5',
1160         'marker;': '\u25ae',
1161         'mcomma;': '\u2a29',
1162         'Mcy;': '\u041c',
1163         'mcy;': '\u043c',
1164         'mdash;': '\u2014',
1165         'mDDot;': '\u223a',
1166         'measuredangle;': '\u2221',
1167         'MediumSpace;': '\u205f',
1168         'Mellintrf;': '\u2133',
1169         'Mfr;': '\U0001d510',
1170         'mfr;': '\U0001d52a',
1171         'mho;': '\u2127',
1172         'micro': '\xb5',
1173         'micro;': '\xb5',
1174         'mid;': '\u2223',
1175         'midast;': '*',
1176         'midcir;': '\u2af0',
1177         'middot': '\xb7',
1178         'middot;': '\xb7',
1179         'minus;': '\u2212',
1180         'minusb;': '\u229f',
1181         'minusd;': '\u2238',
1182         'minusdu;': '\u2a2a',
1183         'MinusPlus;': '\u2213',
1184         'mlcp;': '\u2adb',
1185         'mldr;': '\u2026',
1186         'mnplus;': '\u2213',
1187         'models;': '\u22a7',
1188         'Mopf;': '\U0001d544',
1189         'mopf;': '\U0001d55e',
1190         'mp;': '\u2213',
1191         'Mscr;': '\u2133',
1192         'mscr;': '\U0001d4c2',
1193         'mstpos;': '\u223e',
1194         'Mu;': '\u039c',
1195         'mu;': '\u03bc',
1196         'multimap;': '\u22b8',
1197         'mumap;': '\u22b8',
1198         'nabla;': '\u2207',
1199         'Nacute;': '\u0143',
1200         'nacute;': '\u0144',
1201         'nang;': '\u2220\u20d2',
1202         'nap;': '\u2249',
1203         'napE;': '\u2a70\u0338',
1204         'napid;': '\u224b\u0338',
1205         'napos;': '\u0149',
1206         'napprox;': '\u2249',
1207         'natur;': '\u266e',
1208         'natural;': '\u266e',
1209         'naturals;': '\u2115',
1210         'nbsp': '\xa0',
1211         'nbsp;': '\xa0',
1212         'nbump;': '\u224e\u0338',
1213         'nbumpe;': '\u224f\u0338',
1214         'ncap;': '\u2a43',
1215         'Ncaron;': '\u0147',
1216         'ncaron;': '\u0148',
1217         'Ncedil;': '\u0145',
1218         'ncedil;': '\u0146',
1219         'ncong;': '\u2247',
1220         'ncongdot;': '\u2a6d\u0338',
1221         'ncup;': '\u2a42',
1222         'Ncy;': '\u041d',
1223         'ncy;': '\u043d',
1224         'ndash;': '\u2013',
1225         'ne;': '\u2260',
1226         'nearhk;': '\u2924',
1227         'neArr;': '\u21d7',
1228         'nearr;': '\u2197',
1229         'nearrow;': '\u2197',
1230         'nedot;': '\u2250\u0338',
1231         'NegativeMediumSpace;': '\u200b',
1232         'NegativeThickSpace;': '\u200b',
1233         'NegativeThinSpace;': '\u200b',
1234         'NegativeVeryThinSpace;': '\u200b',
1235         'nequiv;': '\u2262',
1236         'nesear;': '\u2928',
1237         'nesim;': '\u2242\u0338',
1238         'NestedGreaterGreater;': '\u226b',
1239         'NestedLessLess;': '\u226a',
1240         'NewLine;': '\n',
1241         'nexist;': '\u2204',
1242         'nexists;': '\u2204',
1243         'Nfr;': '\U0001d511',
1244         'nfr;': '\U0001d52b',
1245         'ngE;': '\u2267\u0338',
1246         'nge;': '\u2271',
1247         'ngeq;': '\u2271',
1248         'ngeqq;': '\u2267\u0338',
1249         'ngeqslant;': '\u2a7e\u0338',
1250         'nges;': '\u2a7e\u0338',
1251         'nGg;': '\u22d9\u0338',
1252         'ngsim;': '\u2275',
1253         'nGt;': '\u226b\u20d2',
1254         'ngt;': '\u226f',
1255         'ngtr;': '\u226f',
1256         'nGtv;': '\u226b\u0338',
1257         'nhArr;': '\u21ce',
1258         'nharr;': '\u21ae',
1259         'nhpar;': '\u2af2',
1260         'ni;': '\u220b',
1261         'nis;': '\u22fc',
1262         'nisd;': '\u22fa',
1263         'niv;': '\u220b',
1264         'NJcy;': '\u040a',
1265         'njcy;': '\u045a',
1266         'nlArr;': '\u21cd',
1267         'nlarr;': '\u219a',
1268         'nldr;': '\u2025',
1269         'nlE;': '\u2266\u0338',
1270         'nle;': '\u2270',
1271         'nLeftarrow;': '\u21cd',
1272         'nleftarrow;': '\u219a',
1273         'nLeftrightarrow;': '\u21ce',
1274         'nleftrightarrow;': '\u21ae',
1275         'nleq;': '\u2270',
1276         'nleqq;': '\u2266\u0338',
1277         'nleqslant;': '\u2a7d\u0338',
1278         'nles;': '\u2a7d\u0338',
1279         'nless;': '\u226e',
1280         'nLl;': '\u22d8\u0338',
1281         'nlsim;': '\u2274',
1282         'nLt;': '\u226a\u20d2',
1283         'nlt;': '\u226e',
1284         'nltri;': '\u22ea',
1285         'nltrie;': '\u22ec',
1286         'nLtv;': '\u226a\u0338',
1287         'nmid;': '\u2224',
1288         'NoBreak;': '\u2060',
1289         'NonBreakingSpace;': '\xa0',
1290         'Nopf;': '\u2115',
1291         'nopf;': '\U0001d55f',
1292         'not': '\xac',
1293         'Not;': '\u2aec',
1294         'not;': '\xac',
1295         'NotCongruent;': '\u2262',
1296         'NotCupCap;': '\u226d',
1297         'NotDoubleVerticalBar;': '\u2226',
1298         'NotElement;': '\u2209',
1299         'NotEqual;': '\u2260',
1300         'NotEqualTilde;': '\u2242\u0338',
1301         'NotExists;': '\u2204',
1302         'NotGreater;': '\u226f',
1303         'NotGreaterEqual;': '\u2271',
1304         'NotGreaterFullEqual;': '\u2267\u0338',
1305         'NotGreaterGreater;': '\u226b\u0338',
1306         'NotGreaterLess;': '\u2279',
1307         'NotGreaterSlantEqual;': '\u2a7e\u0338',
1308         'NotGreaterTilde;': '\u2275',
1309         'NotHumpDownHump;': '\u224e\u0338',
1310         'NotHumpEqual;': '\u224f\u0338',
1311         'notin;': '\u2209',
1312         'notindot;': '\u22f5\u0338',
1313         'notinE;': '\u22f9\u0338',
1314         'notinva;': '\u2209',
1315         'notinvb;': '\u22f7',
1316         'notinvc;': '\u22f6',
1317         'NotLeftTriangle;': '\u22ea',
1318         'NotLeftTriangleBar;': '\u29cf\u0338',
1319         'NotLeftTriangleEqual;': '\u22ec',
1320         'NotLess;': '\u226e',
1321         'NotLessEqual;': '\u2270',
1322         'NotLessGreater;': '\u2278',
1323         'NotLessLess;': '\u226a\u0338',
1324         'NotLessSlantEqual;': '\u2a7d\u0338',
1325         'NotLessTilde;': '\u2274',
1326         'NotNestedGreaterGreater;': '\u2aa2\u0338',
1327         'NotNestedLessLess;': '\u2aa1\u0338',
1328         'notni;': '\u220c',
1329         'notniva;': '\u220c',
1330         'notnivb;': '\u22fe',
1331         'notnivc;': '\u22fd',
1332         'NotPrecedes;': '\u2280',
1333         'NotPrecedesEqual;': '\u2aaf\u0338',
1334         'NotPrecedesSlantEqual;': '\u22e0',
1335         'NotReverseElement;': '\u220c',
1336         'NotRightTriangle;': '\u22eb',
1337         'NotRightTriangleBar;': '\u29d0\u0338',
1338         'NotRightTriangleEqual;': '\u22ed',
1339         'NotSquareSubset;': '\u228f\u0338',
1340         'NotSquareSubsetEqual;': '\u22e2',
1341         'NotSquareSuperset;': '\u2290\u0338',
1342         'NotSquareSupersetEqual;': '\u22e3',
1343         'NotSubset;': '\u2282\u20d2',
1344         'NotSubsetEqual;': '\u2288',
1345         'NotSucceeds;': '\u2281',
1346         'NotSucceedsEqual;': '\u2ab0\u0338',
1347         'NotSucceedsSlantEqual;': '\u22e1',
1348         'NotSucceedsTilde;': '\u227f\u0338',
1349         'NotSuperset;': '\u2283\u20d2',
1350         'NotSupersetEqual;': '\u2289',
1351         'NotTilde;': '\u2241',
1352         'NotTildeEqual;': '\u2244',
1353         'NotTildeFullEqual;': '\u2247',
1354         'NotTildeTilde;': '\u2249',
1355         'NotVerticalBar;': '\u2224',
1356         'npar;': '\u2226',
1357         'nparallel;': '\u2226',
1358         'nparsl;': '\u2afd\u20e5',
1359         'npart;': '\u2202\u0338',
1360         'npolint;': '\u2a14',
1361         'npr;': '\u2280',
1362         'nprcue;': '\u22e0',
1363         'npre;': '\u2aaf\u0338',
1364         'nprec;': '\u2280',
1365         'npreceq;': '\u2aaf\u0338',
1366         'nrArr;': '\u21cf',
1367         'nrarr;': '\u219b',
1368         'nrarrc;': '\u2933\u0338',
1369         'nrarrw;': '\u219d\u0338',
1370         'nRightarrow;': '\u21cf',
1371         'nrightarrow;': '\u219b',
1372         'nrtri;': '\u22eb',
1373         'nrtrie;': '\u22ed',
1374         'nsc;': '\u2281',
1375         'nsccue;': '\u22e1',
1376         'nsce;': '\u2ab0\u0338',
1377         'Nscr;': '\U0001d4a9',
1378         'nscr;': '\U0001d4c3',
1379         'nshortmid;': '\u2224',
1380         'nshortparallel;': '\u2226',
1381         'nsim;': '\u2241',
1382         'nsime;': '\u2244',
1383         'nsimeq;': '\u2244',
1384         'nsmid;': '\u2224',
1385         'nspar;': '\u2226',
1386         'nsqsube;': '\u22e2',
1387         'nsqsupe;': '\u22e3',
1388         'nsub;': '\u2284',
1389         'nsubE;': '\u2ac5\u0338',
1390         'nsube;': '\u2288',
1391         'nsubset;': '\u2282\u20d2',
1392         'nsubseteq;': '\u2288',
1393         'nsubseteqq;': '\u2ac5\u0338',
1394         'nsucc;': '\u2281',
1395         'nsucceq;': '\u2ab0\u0338',
1396         'nsup;': '\u2285',
1397         'nsupE;': '\u2ac6\u0338',
1398         'nsupe;': '\u2289',
1399         'nsupset;': '\u2283\u20d2',
1400         'nsupseteq;': '\u2289',
1401         'nsupseteqq;': '\u2ac6\u0338',
1402         'ntgl;': '\u2279',
1403         'Ntilde': '\xd1',
1404         'ntilde': '\xf1',
1405         'Ntilde;': '\xd1',
1406         'ntilde;': '\xf1',
1407         'ntlg;': '\u2278',
1408         'ntriangleleft;': '\u22ea',
1409         'ntrianglelefteq;': '\u22ec',
1410         'ntriangleright;': '\u22eb',
1411         'ntrianglerighteq;': '\u22ed',
1412         'Nu;': '\u039d',
1413         'nu;': '\u03bd',
1414         'num;': '#',
1415         'numero;': '\u2116',
1416         'numsp;': '\u2007',
1417         'nvap;': '\u224d\u20d2',
1418         'nVDash;': '\u22af',
1419         'nVdash;': '\u22ae',
1420         'nvDash;': '\u22ad',
1421         'nvdash;': '\u22ac',
1422         'nvge;': '\u2265\u20d2',
1423         'nvgt;': '>\u20d2',
1424         'nvHarr;': '\u2904',
1425         'nvinfin;': '\u29de',
1426         'nvlArr;': '\u2902',
1427         'nvle;': '\u2264\u20d2',
1428         'nvlt;': '<\u20d2',
1429         'nvltrie;': '\u22b4\u20d2',
1430         'nvrArr;': '\u2903',
1431         'nvrtrie;': '\u22b5\u20d2',
1432         'nvsim;': '\u223c\u20d2',
1433         'nwarhk;': '\u2923',
1434         'nwArr;': '\u21d6',
1435         'nwarr;': '\u2196',
1436         'nwarrow;': '\u2196',
1437         'nwnear;': '\u2927',
1438         'Oacute': '\xd3',
1439         'oacute': '\xf3',
1440         'Oacute;': '\xd3',
1441         'oacute;': '\xf3',
1442         'oast;': '\u229b',
1443         'ocir;': '\u229a',
1444         'Ocirc': '\xd4',
1445         'ocirc': '\xf4',
1446         'Ocirc;': '\xd4',
1447         'ocirc;': '\xf4',
1448         'Ocy;': '\u041e',
1449         'ocy;': '\u043e',
1450         'odash;': '\u229d',
1451         'Odblac;': '\u0150',
1452         'odblac;': '\u0151',
1453         'odiv;': '\u2a38',
1454         'odot;': '\u2299',
1455         'odsold;': '\u29bc',
1456         'OElig;': '\u0152',
1457         'oelig;': '\u0153',
1458         'ofcir;': '\u29bf',
1459         'Ofr;': '\U0001d512',
1460         'ofr;': '\U0001d52c',
1461         'ogon;': '\u02db',
1462         'Ograve': '\xd2',
1463         'ograve': '\xf2',
1464         'Ograve;': '\xd2',
1465         'ograve;': '\xf2',
1466         'ogt;': '\u29c1',
1467         'ohbar;': '\u29b5',
1468         'ohm;': '\u03a9',
1469         'oint;': '\u222e',
1470         'olarr;': '\u21ba',
1471         'olcir;': '\u29be',
1472         'olcross;': '\u29bb',
1473         'oline;': '\u203e',
1474         'olt;': '\u29c0',
1475         'Omacr;': '\u014c',
1476         'omacr;': '\u014d',
1477         'Omega;': '\u03a9',
1478         'omega;': '\u03c9',
1479         'Omicron;': '\u039f',
1480         'omicron;': '\u03bf',
1481         'omid;': '\u29b6',
1482         'ominus;': '\u2296',
1483         'Oopf;': '\U0001d546',
1484         'oopf;': '\U0001d560',
1485         'opar;': '\u29b7',
1486         'OpenCurlyDoubleQuote;': '\u201c',
1487         'OpenCurlyQuote;': '\u2018',
1488         'operp;': '\u29b9',
1489         'oplus;': '\u2295',
1490         'Or;': '\u2a54',
1491         'or;': '\u2228',
1492         'orarr;': '\u21bb',
1493         'ord;': '\u2a5d',
1494         'order;': '\u2134',
1495         'orderof;': '\u2134',
1496         'ordf': '\xaa',
1497         'ordf;': '\xaa',
1498         'ordm': '\xba',
1499         'ordm;': '\xba',
1500         'origof;': '\u22b6',
1501         'oror;': '\u2a56',
1502         'orslope;': '\u2a57',
1503         'orv;': '\u2a5b',
1504         'oS;': '\u24c8',
1505         'Oscr;': '\U0001d4aa',
1506         'oscr;': '\u2134',
1507         'Oslash': '\xd8',
1508         'oslash': '\xf8',
1509         'Oslash;': '\xd8',
1510         'oslash;': '\xf8',
1511         'osol;': '\u2298',
1512         'Otilde': '\xd5',
1513         'otilde': '\xf5',
1514         'Otilde;': '\xd5',
1515         'otilde;': '\xf5',
1516         'Otimes;': '\u2a37',
1517         'otimes;': '\u2297',
1518         'otimesas;': '\u2a36',
1519         'Ouml': '\xd6',
1520         'ouml': '\xf6',
1521         'Ouml;': '\xd6',
1522         'ouml;': '\xf6',
1523         'ovbar;': '\u233d',
1524         'OverBar;': '\u203e',
1525         'OverBrace;': '\u23de',
1526         'OverBracket;': '\u23b4',
1527         'OverParenthesis;': '\u23dc',
1528         'par;': '\u2225',
1529         'para': '\xb6',
1530         'para;': '\xb6',
1531         'parallel;': '\u2225',
1532         'parsim;': '\u2af3',
1533         'parsl;': '\u2afd',
1534         'part;': '\u2202',
1535         'PartialD;': '\u2202',
1536         'Pcy;': '\u041f',
1537         'pcy;': '\u043f',
1538         'percnt;': '%',
1539         'period;': '.',
1540         'permil;': '\u2030',
1541         'perp;': '\u22a5',
1542         'pertenk;': '\u2031',
1543         'Pfr;': '\U0001d513',
1544         'pfr;': '\U0001d52d',
1545         'Phi;': '\u03a6',
1546         'phi;': '\u03c6',
1547         'phiv;': '\u03d5',
1548         'phmmat;': '\u2133',
1549         'phone;': '\u260e',
1550         'Pi;': '\u03a0',
1551         'pi;': '\u03c0',
1552         'pitchfork;': '\u22d4',
1553         'piv;': '\u03d6',
1554         'planck;': '\u210f',
1555         'planckh;': '\u210e',
1556         'plankv;': '\u210f',
1557         'plus;': '+',
1558         'plusacir;': '\u2a23',
1559         'plusb;': '\u229e',
1560         'pluscir;': '\u2a22',
1561         'plusdo;': '\u2214',
1562         'plusdu;': '\u2a25',
1563         'pluse;': '\u2a72',
1564         'PlusMinus;': '\xb1',
1565         'plusmn': '\xb1',
1566         'plusmn;': '\xb1',
1567         'plussim;': '\u2a26',
1568         'plustwo;': '\u2a27',
1569         'pm;': '\xb1',
1570         'Poincareplane;': '\u210c',
1571         'pointint;': '\u2a15',
1572         'Popf;': '\u2119',
1573         'popf;': '\U0001d561',
1574         'pound': '\xa3',
1575         'pound;': '\xa3',
1576         'Pr;': '\u2abb',
1577         'pr;': '\u227a',
1578         'prap;': '\u2ab7',
1579         'prcue;': '\u227c',
1580         'prE;': '\u2ab3',
1581         'pre;': '\u2aaf',
1582         'prec;': '\u227a',
1583         'precapprox;': '\u2ab7',
1584         'preccurlyeq;': '\u227c',
1585         'Precedes;': '\u227a',
1586         'PrecedesEqual;': '\u2aaf',
1587         'PrecedesSlantEqual;': '\u227c',
1588         'PrecedesTilde;': '\u227e',
1589         'preceq;': '\u2aaf',
1590         'precnapprox;': '\u2ab9',
1591         'precneqq;': '\u2ab5',
1592         'precnsim;': '\u22e8',
1593         'precsim;': '\u227e',
1594         'Prime;': '\u2033',
1595         'prime;': '\u2032',
1596         'primes;': '\u2119',
1597         'prnap;': '\u2ab9',
1598         'prnE;': '\u2ab5',
1599         'prnsim;': '\u22e8',
1600         'prod;': '\u220f',
1601         'Product;': '\u220f',
1602         'profalar;': '\u232e',
1603         'profline;': '\u2312',
1604         'profsurf;': '\u2313',
1605         'prop;': '\u221d',
1606         'Proportion;': '\u2237',
1607         'Proportional;': '\u221d',
1608         'propto;': '\u221d',
1609         'prsim;': '\u227e',
1610         'prurel;': '\u22b0',
1611         'Pscr;': '\U0001d4ab',
1612         'pscr;': '\U0001d4c5',
1613         'Psi;': '\u03a8',
1614         'psi;': '\u03c8',
1615         'puncsp;': '\u2008',
1616         'Qfr;': '\U0001d514',
1617         'qfr;': '\U0001d52e',
1618         'qint;': '\u2a0c',
1619         'Qopf;': '\u211a',
1620         'qopf;': '\U0001d562',
1621         'qprime;': '\u2057',
1622         'Qscr;': '\U0001d4ac',
1623         'qscr;': '\U0001d4c6',
1624         'quaternions;': '\u210d',
1625         'quatint;': '\u2a16',
1626         'quest;': '?',
1627         'questeq;': '\u225f',
1628         'QUOT': '"',
1629         'quot': '"',
1630         'QUOT;': '"',
1631         'quot;': '"',
1632         'rAarr;': '\u21db',
1633         'race;': '\u223d\u0331',
1634         'Racute;': '\u0154',
1635         'racute;': '\u0155',
1636         'radic;': '\u221a',
1637         'raemptyv;': '\u29b3',
1638         'Rang;': '\u27eb',
1639         'rang;': '\u27e9',
1640         'rangd;': '\u2992',
1641         'range;': '\u29a5',
1642         'rangle;': '\u27e9',
1643         'raquo': '\xbb',
1644         'raquo;': '\xbb',
1645         'Rarr;': '\u21a0',
1646         'rArr;': '\u21d2',
1647         'rarr;': '\u2192',
1648         'rarrap;': '\u2975',
1649         'rarrb;': '\u21e5',
1650         'rarrbfs;': '\u2920',
1651         'rarrc;': '\u2933',
1652         'rarrfs;': '\u291e',
1653         'rarrhk;': '\u21aa',
1654         'rarrlp;': '\u21ac',
1655         'rarrpl;': '\u2945',
1656         'rarrsim;': '\u2974',
1657         'Rarrtl;': '\u2916',
1658         'rarrtl;': '\u21a3',
1659         'rarrw;': '\u219d',
1660         'rAtail;': '\u291c',
1661         'ratail;': '\u291a',
1662         'ratio;': '\u2236',
1663         'rationals;': '\u211a',
1664         'RBarr;': '\u2910',
1665         'rBarr;': '\u290f',
1666         'rbarr;': '\u290d',
1667         'rbbrk;': '\u2773',
1668         'rbrace;': '}',
1669         'rbrack;': ']',
1670         'rbrke;': '\u298c',
1671         'rbrksld;': '\u298e',
1672         'rbrkslu;': '\u2990',
1673         'Rcaron;': '\u0158',
1674         'rcaron;': '\u0159',
1675         'Rcedil;': '\u0156',
1676         'rcedil;': '\u0157',
1677         'rceil;': '\u2309',
1678         'rcub;': '}',
1679         'Rcy;': '\u0420',
1680         'rcy;': '\u0440',
1681         'rdca;': '\u2937',
1682         'rdldhar;': '\u2969',
1683         'rdquo;': '\u201d',
1684         'rdquor;': '\u201d',
1685         'rdsh;': '\u21b3',
1686         'Re;': '\u211c',
1687         'real;': '\u211c',
1688         'realine;': '\u211b',
1689         'realpart;': '\u211c',
1690         'reals;': '\u211d',
1691         'rect;': '\u25ad',
1692         'REG': '\xae',
1693         'reg': '\xae',
1694         'REG;': '\xae',
1695         'reg;': '\xae',
1696         'ReverseElement;': '\u220b',
1697         'ReverseEquilibrium;': '\u21cb',
1698         'ReverseUpEquilibrium;': '\u296f',
1699         'rfisht;': '\u297d',
1700         'rfloor;': '\u230b',
1701         'Rfr;': '\u211c',
1702         'rfr;': '\U0001d52f',
1703         'rHar;': '\u2964',
1704         'rhard;': '\u21c1',
1705         'rharu;': '\u21c0',
1706         'rharul;': '\u296c',
1707         'Rho;': '\u03a1',
1708         'rho;': '\u03c1',
1709         'rhov;': '\u03f1',
1710         'RightAngleBracket;': '\u27e9',
1711         'RightArrow;': '\u2192',
1712         'Rightarrow;': '\u21d2',
1713         'rightarrow;': '\u2192',
1714         'RightArrowBar;': '\u21e5',
1715         'RightArrowLeftArrow;': '\u21c4',
1716         'rightarrowtail;': '\u21a3',
1717         'RightCeiling;': '\u2309',
1718         'RightDoubleBracket;': '\u27e7',
1719         'RightDownTeeVector;': '\u295d',
1720         'RightDownVector;': '\u21c2',
1721         'RightDownVectorBar;': '\u2955',
1722         'RightFloor;': '\u230b',
1723         'rightharpoondown;': '\u21c1',
1724         'rightharpoonup;': '\u21c0',
1725         'rightleftarrows;': '\u21c4',
1726         'rightleftharpoons;': '\u21cc',
1727         'rightrightarrows;': '\u21c9',
1728         'rightsquigarrow;': '\u219d',
1729         'RightTee;': '\u22a2',
1730         'RightTeeArrow;': '\u21a6',
1731         'RightTeeVector;': '\u295b',
1732         'rightthreetimes;': '\u22cc',
1733         'RightTriangle;': '\u22b3',
1734         'RightTriangleBar;': '\u29d0',
1735         'RightTriangleEqual;': '\u22b5',
1736         'RightUpDownVector;': '\u294f',
1737         'RightUpTeeVector;': '\u295c',
1738         'RightUpVector;': '\u21be',
1739         'RightUpVectorBar;': '\u2954',
1740         'RightVector;': '\u21c0',
1741         'RightVectorBar;': '\u2953',
1742         'ring;': '\u02da',
1743         'risingdotseq;': '\u2253',
1744         'rlarr;': '\u21c4',
1745         'rlhar;': '\u21cc',
1746         'rlm;': '\u200f',
1747         'rmoust;': '\u23b1',
1748         'rmoustache;': '\u23b1',
1749         'rnmid;': '\u2aee',
1750         'roang;': '\u27ed',
1751         'roarr;': '\u21fe',
1752         'robrk;': '\u27e7',
1753         'ropar;': '\u2986',
1754         'Ropf;': '\u211d',
1755         'ropf;': '\U0001d563',
1756         'roplus;': '\u2a2e',
1757         'rotimes;': '\u2a35',
1758         'RoundImplies;': '\u2970',
1759         'rpar;': ')',
1760         'rpargt;': '\u2994',
1761         'rppolint;': '\u2a12',
1762         'rrarr;': '\u21c9',
1763         'Rrightarrow;': '\u21db',
1764         'rsaquo;': '\u203a',
1765         'Rscr;': '\u211b',
1766         'rscr;': '\U0001d4c7',
1767         'Rsh;': '\u21b1',
1768         'rsh;': '\u21b1',
1769         'rsqb;': ']',
1770         'rsquo;': '\u2019',
1771         'rsquor;': '\u2019',
1772         'rthree;': '\u22cc',
1773         'rtimes;': '\u22ca',
1774         'rtri;': '\u25b9',
1775         'rtrie;': '\u22b5',
1776         'rtrif;': '\u25b8',
1777         'rtriltri;': '\u29ce',
1778         'RuleDelayed;': '\u29f4',
1779         'ruluhar;': '\u2968',
1780         'rx;': '\u211e',
1781         'Sacute;': '\u015a',
1782         'sacute;': '\u015b',
1783         'sbquo;': '\u201a',
1784         'Sc;': '\u2abc',
1785         'sc;': '\u227b',
1786         'scap;': '\u2ab8',
1787         'Scaron;': '\u0160',
1788         'scaron;': '\u0161',
1789         'sccue;': '\u227d',
1790         'scE;': '\u2ab4',
1791         'sce;': '\u2ab0',
1792         'Scedil;': '\u015e',
1793         'scedil;': '\u015f',
1794         'Scirc;': '\u015c',
1795         'scirc;': '\u015d',
1796         'scnap;': '\u2aba',
1797         'scnE;': '\u2ab6',
1798         'scnsim;': '\u22e9',
1799         'scpolint;': '\u2a13',
1800         'scsim;': '\u227f',
1801         'Scy;': '\u0421',
1802         'scy;': '\u0441',
1803         'sdot;': '\u22c5',
1804         'sdotb;': '\u22a1',
1805         'sdote;': '\u2a66',
1806         'searhk;': '\u2925',
1807         'seArr;': '\u21d8',
1808         'searr;': '\u2198',
1809         'searrow;': '\u2198',
1810         'sect': '\xa7',
1811         'sect;': '\xa7',
1812         'semi;': ';',
1813         'seswar;': '\u2929',
1814         'setminus;': '\u2216',
1815         'setmn;': '\u2216',
1816         'sext;': '\u2736',
1817         'Sfr;': '\U0001d516',
1818         'sfr;': '\U0001d530',
1819         'sfrown;': '\u2322',
1820         'sharp;': '\u266f',
1821         'SHCHcy;': '\u0429',
1822         'shchcy;': '\u0449',
1823         'SHcy;': '\u0428',
1824         'shcy;': '\u0448',
1825         'ShortDownArrow;': '\u2193',
1826         'ShortLeftArrow;': '\u2190',
1827         'shortmid;': '\u2223',
1828         'shortparallel;': '\u2225',
1829         'ShortRightArrow;': '\u2192',
1830         'ShortUpArrow;': '\u2191',
1831         'shy': '\xad',
1832         'shy;': '\xad',
1833         'Sigma;': '\u03a3',
1834         'sigma;': '\u03c3',
1835         'sigmaf;': '\u03c2',
1836         'sigmav;': '\u03c2',
1837         'sim;': '\u223c',
1838         'simdot;': '\u2a6a',
1839         'sime;': '\u2243',
1840         'simeq;': '\u2243',
1841         'simg;': '\u2a9e',
1842         'simgE;': '\u2aa0',
1843         'siml;': '\u2a9d',
1844         'simlE;': '\u2a9f',
1845         'simne;': '\u2246',
1846         'simplus;': '\u2a24',
1847         'simrarr;': '\u2972',
1848         'slarr;': '\u2190',
1849         'SmallCircle;': '\u2218',
1850         'smallsetminus;': '\u2216',
1851         'smashp;': '\u2a33',
1852         'smeparsl;': '\u29e4',
1853         'smid;': '\u2223',
1854         'smile;': '\u2323',
1855         'smt;': '\u2aaa',
1856         'smte;': '\u2aac',
1857         'smtes;': '\u2aac\ufe00',
1858         'SOFTcy;': '\u042c',
1859         'softcy;': '\u044c',
1860         'sol;': '/',
1861         'solb;': '\u29c4',
1862         'solbar;': '\u233f',
1863         'Sopf;': '\U0001d54a',
1864         'sopf;': '\U0001d564',
1865         'spades;': '\u2660',
1866         'spadesuit;': '\u2660',
1867         'spar;': '\u2225',
1868         'sqcap;': '\u2293',
1869         'sqcaps;': '\u2293\ufe00',
1870         'sqcup;': '\u2294',
1871         'sqcups;': '\u2294\ufe00',
1872         'Sqrt;': '\u221a',
1873         'sqsub;': '\u228f',
1874         'sqsube;': '\u2291',
1875         'sqsubset;': '\u228f',
1876         'sqsubseteq;': '\u2291',
1877         'sqsup;': '\u2290',
1878         'sqsupe;': '\u2292',
1879         'sqsupset;': '\u2290',
1880         'sqsupseteq;': '\u2292',
1881         'squ;': '\u25a1',
1882         'Square;': '\u25a1',
1883         'square;': '\u25a1',
1884         'SquareIntersection;': '\u2293',
1885         'SquareSubset;': '\u228f',
1886         'SquareSubsetEqual;': '\u2291',
1887         'SquareSuperset;': '\u2290',
1888         'SquareSupersetEqual;': '\u2292',
1889         'SquareUnion;': '\u2294',
1890         'squarf;': '\u25aa',
1891         'squf;': '\u25aa',
1892         'srarr;': '\u2192',
1893         'Sscr;': '\U0001d4ae',
1894         'sscr;': '\U0001d4c8',
1895         'ssetmn;': '\u2216',
1896         'ssmile;': '\u2323',
1897         'sstarf;': '\u22c6',
1898         'Star;': '\u22c6',
1899         'star;': '\u2606',
1900         'starf;': '\u2605',
1901         'straightepsilon;': '\u03f5',
1902         'straightphi;': '\u03d5',
1903         'strns;': '\xaf',
1904         'Sub;': '\u22d0',
1905         'sub;': '\u2282',
1906         'subdot;': '\u2abd',
1907         'subE;': '\u2ac5',
1908         'sube;': '\u2286',
1909         'subedot;': '\u2ac3',
1910         'submult;': '\u2ac1',
1911         'subnE;': '\u2acb',
1912         'subne;': '\u228a',
1913         'subplus;': '\u2abf',
1914         'subrarr;': '\u2979',
1915         'Subset;': '\u22d0',
1916         'subset;': '\u2282',
1917         'subseteq;': '\u2286',
1918         'subseteqq;': '\u2ac5',
1919         'SubsetEqual;': '\u2286',
1920         'subsetneq;': '\u228a',
1921         'subsetneqq;': '\u2acb',
1922         'subsim;': '\u2ac7',
1923         'subsub;': '\u2ad5',
1924         'subsup;': '\u2ad3',
1925         'succ;': '\u227b',
1926         'succapprox;': '\u2ab8',
1927         'succcurlyeq;': '\u227d',
1928         'Succeeds;': '\u227b',
1929         'SucceedsEqual;': '\u2ab0',
1930         'SucceedsSlantEqual;': '\u227d',
1931         'SucceedsTilde;': '\u227f',
1932         'succeq;': '\u2ab0',
1933         'succnapprox;': '\u2aba',
1934         'succneqq;': '\u2ab6',
1935         'succnsim;': '\u22e9',
1936         'succsim;': '\u227f',
1937         'SuchThat;': '\u220b',
1938         'Sum;': '\u2211',
1939         'sum;': '\u2211',
1940         'sung;': '\u266a',
1941         'sup1': '\xb9',
1942         'sup1;': '\xb9',
1943         'sup2': '\xb2',
1944         'sup2;': '\xb2',
1945         'sup3': '\xb3',
1946         'sup3;': '\xb3',
1947         'Sup;': '\u22d1',
1948         'sup;': '\u2283',
1949         'supdot;': '\u2abe',
1950         'supdsub;': '\u2ad8',
1951         'supE;': '\u2ac6',
1952         'supe;': '\u2287',
1953         'supedot;': '\u2ac4',
1954         'Superset;': '\u2283',
1955         'SupersetEqual;': '\u2287',
1956         'suphsol;': '\u27c9',
1957         'suphsub;': '\u2ad7',
1958         'suplarr;': '\u297b',
1959         'supmult;': '\u2ac2',
1960         'supnE;': '\u2acc',
1961         'supne;': '\u228b',
1962         'supplus;': '\u2ac0',
1963         'Supset;': '\u22d1',
1964         'supset;': '\u2283',
1965         'supseteq;': '\u2287',
1966         'supseteqq;': '\u2ac6',
1967         'supsetneq;': '\u228b',
1968         'supsetneqq;': '\u2acc',
1969         'supsim;': '\u2ac8',
1970         'supsub;': '\u2ad4',
1971         'supsup;': '\u2ad6',
1972         'swarhk;': '\u2926',
1973         'swArr;': '\u21d9',
1974         'swarr;': '\u2199',
1975         'swarrow;': '\u2199',
1976         'swnwar;': '\u292a',
1977         'szlig': '\xdf',
1978         'szlig;': '\xdf',
1979         'Tab;': '\t',
1980         'target;': '\u2316',
1981         'Tau;': '\u03a4',
1982         'tau;': '\u03c4',
1983         'tbrk;': '\u23b4',
1984         'Tcaron;': '\u0164',
1985         'tcaron;': '\u0165',
1986         'Tcedil;': '\u0162',
1987         'tcedil;': '\u0163',
1988         'Tcy;': '\u0422',
1989         'tcy;': '\u0442',
1990         'tdot;': '\u20db',
1991         'telrec;': '\u2315',
1992         'Tfr;': '\U0001d517',
1993         'tfr;': '\U0001d531',
1994         'there4;': '\u2234',
1995         'Therefore;': '\u2234',
1996         'therefore;': '\u2234',
1997         'Theta;': '\u0398',
1998         'theta;': '\u03b8',
1999         'thetasym;': '\u03d1',
2000         'thetav;': '\u03d1',
2001         'thickapprox;': '\u2248',
2002         'thicksim;': '\u223c',
2003         'ThickSpace;': '\u205f\u200a',
2004         'thinsp;': '\u2009',
2005         'ThinSpace;': '\u2009',
2006         'thkap;': '\u2248',
2007         'thksim;': '\u223c',
2008         'THORN': '\xde',
2009         'thorn': '\xfe',
2010         'THORN;': '\xde',
2011         'thorn;': '\xfe',
2012         'Tilde;': '\u223c',
2013         'tilde;': '\u02dc',
2014         'TildeEqual;': '\u2243',
2015         'TildeFullEqual;': '\u2245',
2016         'TildeTilde;': '\u2248',
2017         'times': '\xd7',
2018         'times;': '\xd7',
2019         'timesb;': '\u22a0',
2020         'timesbar;': '\u2a31',
2021         'timesd;': '\u2a30',
2022         'tint;': '\u222d',
2023         'toea;': '\u2928',
2024         'top;': '\u22a4',
2025         'topbot;': '\u2336',
2026         'topcir;': '\u2af1',
2027         'Topf;': '\U0001d54b',
2028         'topf;': '\U0001d565',
2029         'topfork;': '\u2ada',
2030         'tosa;': '\u2929',
2031         'tprime;': '\u2034',
2032         'TRADE;': '\u2122',
2033         'trade;': '\u2122',
2034         'triangle;': '\u25b5',
2035         'triangledown;': '\u25bf',
2036         'triangleleft;': '\u25c3',
2037         'trianglelefteq;': '\u22b4',
2038         'triangleq;': '\u225c',
2039         'triangleright;': '\u25b9',
2040         'trianglerighteq;': '\u22b5',
2041         'tridot;': '\u25ec',
2042         'trie;': '\u225c',
2043         'triminus;': '\u2a3a',
2044         'TripleDot;': '\u20db',
2045         'triplus;': '\u2a39',
2046         'trisb;': '\u29cd',
2047         'tritime;': '\u2a3b',
2048         'trpezium;': '\u23e2',
2049         'Tscr;': '\U0001d4af',
2050         'tscr;': '\U0001d4c9',
2051         'TScy;': '\u0426',
2052         'tscy;': '\u0446',
2053         'TSHcy;': '\u040b',
2054         'tshcy;': '\u045b',
2055         'Tstrok;': '\u0166',
2056         'tstrok;': '\u0167',
2057         'twixt;': '\u226c',
2058         'twoheadleftarrow;': '\u219e',
2059         'twoheadrightarrow;': '\u21a0',
2060         'Uacute': '\xda',
2061         'uacute': '\xfa',
2062         'Uacute;': '\xda',
2063         'uacute;': '\xfa',
2064         'Uarr;': '\u219f',
2065         'uArr;': '\u21d1',
2066         'uarr;': '\u2191',
2067         'Uarrocir;': '\u2949',
2068         'Ubrcy;': '\u040e',
2069         'ubrcy;': '\u045e',
2070         'Ubreve;': '\u016c',
2071         'ubreve;': '\u016d',
2072         'Ucirc': '\xdb',
2073         'ucirc': '\xfb',
2074         'Ucirc;': '\xdb',
2075         'ucirc;': '\xfb',
2076         'Ucy;': '\u0423',
2077         'ucy;': '\u0443',
2078         'udarr;': '\u21c5',
2079         'Udblac;': '\u0170',
2080         'udblac;': '\u0171',
2081         'udhar;': '\u296e',
2082         'ufisht;': '\u297e',
2083         'Ufr;': '\U0001d518',
2084         'ufr;': '\U0001d532',
2085         'Ugrave': '\xd9',
2086         'ugrave': '\xf9',
2087         'Ugrave;': '\xd9',
2088         'ugrave;': '\xf9',
2089         'uHar;': '\u2963',
2090         'uharl;': '\u21bf',
2091         'uharr;': '\u21be',
2092         'uhblk;': '\u2580',
2093         'ulcorn;': '\u231c',
2094         'ulcorner;': '\u231c',
2095         'ulcrop;': '\u230f',
2096         'ultri;': '\u25f8',
2097         'Umacr;': '\u016a',
2098         'umacr;': '\u016b',
2099         'uml': '\xa8',
2100         'uml;': '\xa8',
2101         'UnderBar;': '_',
2102         'UnderBrace;': '\u23df',
2103         'UnderBracket;': '\u23b5',
2104         'UnderParenthesis;': '\u23dd',
2105         'Union;': '\u22c3',
2106         'UnionPlus;': '\u228e',
2107         'Uogon;': '\u0172',
2108         'uogon;': '\u0173',
2109         'Uopf;': '\U0001d54c',
2110         'uopf;': '\U0001d566',
2111         'UpArrow;': '\u2191',
2112         'Uparrow;': '\u21d1',
2113         'uparrow;': '\u2191',
2114         'UpArrowBar;': '\u2912',
2115         'UpArrowDownArrow;': '\u21c5',
2116         'UpDownArrow;': '\u2195',
2117         'Updownarrow;': '\u21d5',
2118         'updownarrow;': '\u2195',
2119         'UpEquilibrium;': '\u296e',
2120         'upharpoonleft;': '\u21bf',
2121         'upharpoonright;': '\u21be',
2122         'uplus;': '\u228e',
2123         'UpperLeftArrow;': '\u2196',
2124         'UpperRightArrow;': '\u2197',
2125         'Upsi;': '\u03d2',
2126         'upsi;': '\u03c5',
2127         'upsih;': '\u03d2',
2128         'Upsilon;': '\u03a5',
2129         'upsilon;': '\u03c5',
2130         'UpTee;': '\u22a5',
2131         'UpTeeArrow;': '\u21a5',
2132         'upuparrows;': '\u21c8',
2133         'urcorn;': '\u231d',
2134         'urcorner;': '\u231d',
2135         'urcrop;': '\u230e',
2136         'Uring;': '\u016e',
2137         'uring;': '\u016f',
2138         'urtri;': '\u25f9',
2139         'Uscr;': '\U0001d4b0',
2140         'uscr;': '\U0001d4ca',
2141         'utdot;': '\u22f0',
2142         'Utilde;': '\u0168',
2143         'utilde;': '\u0169',
2144         'utri;': '\u25b5',
2145         'utrif;': '\u25b4',
2146         'uuarr;': '\u21c8',
2147         'Uuml': '\xdc',
2148         'uuml': '\xfc',
2149         'Uuml;': '\xdc',
2150         'uuml;': '\xfc',
2151         'uwangle;': '\u29a7',
2152         'vangrt;': '\u299c',
2153         'varepsilon;': '\u03f5',
2154         'varkappa;': '\u03f0',
2155         'varnothing;': '\u2205',
2156         'varphi;': '\u03d5',
2157         'varpi;': '\u03d6',
2158         'varpropto;': '\u221d',
2159         'vArr;': '\u21d5',
2160         'varr;': '\u2195',
2161         'varrho;': '\u03f1',
2162         'varsigma;': '\u03c2',
2163         'varsubsetneq;': '\u228a\ufe00',
2164         'varsubsetneqq;': '\u2acb\ufe00',
2165         'varsupsetneq;': '\u228b\ufe00',
2166         'varsupsetneqq;': '\u2acc\ufe00',
2167         'vartheta;': '\u03d1',
2168         'vartriangleleft;': '\u22b2',
2169         'vartriangleright;': '\u22b3',
2170         'Vbar;': '\u2aeb',
2171         'vBar;': '\u2ae8',
2172         'vBarv;': '\u2ae9',
2173         'Vcy;': '\u0412',
2174         'vcy;': '\u0432',
2175         'VDash;': '\u22ab',
2176         'Vdash;': '\u22a9',
2177         'vDash;': '\u22a8',
2178         'vdash;': '\u22a2',
2179         'Vdashl;': '\u2ae6',
2180         'Vee;': '\u22c1',
2181         'vee;': '\u2228',
2182         'veebar;': '\u22bb',
2183         'veeeq;': '\u225a',
2184         'vellip;': '\u22ee',
2185         'Verbar;': '\u2016',
2186         'verbar;': '|',
2187         'Vert;': '\u2016',
2188         'vert;': '|',
2189         'VerticalBar;': '\u2223',
2190         'VerticalLine;': '|',
2191         'VerticalSeparator;': '\u2758',
2192         'VerticalTilde;': '\u2240',
2193         'VeryThinSpace;': '\u200a',
2194         'Vfr;': '\U0001d519',
2195         'vfr;': '\U0001d533',
2196         'vltri;': '\u22b2',
2197         'vnsub;': '\u2282\u20d2',
2198         'vnsup;': '\u2283\u20d2',
2199         'Vopf;': '\U0001d54d',
2200         'vopf;': '\U0001d567',
2201         'vprop;': '\u221d',
2202         'vrtri;': '\u22b3',
2203         'Vscr;': '\U0001d4b1',
2204         'vscr;': '\U0001d4cb',
2205         'vsubnE;': '\u2acb\ufe00',
2206         'vsubne;': '\u228a\ufe00',
2207         'vsupnE;': '\u2acc\ufe00',
2208         'vsupne;': '\u228b\ufe00',
2209         'Vvdash;': '\u22aa',
2210         'vzigzag;': '\u299a',
2211         'Wcirc;': '\u0174',
2212         'wcirc;': '\u0175',
2213         'wedbar;': '\u2a5f',
2214         'Wedge;': '\u22c0',
2215         'wedge;': '\u2227',
2216         'wedgeq;': '\u2259',
2217         'weierp;': '\u2118',
2218         'Wfr;': '\U0001d51a',
2219         'wfr;': '\U0001d534',
2220         'Wopf;': '\U0001d54e',
2221         'wopf;': '\U0001d568',
2222         'wp;': '\u2118',
2223         'wr;': '\u2240',
2224         'wreath;': '\u2240',
2225         'Wscr;': '\U0001d4b2',
2226         'wscr;': '\U0001d4cc',
2227         'xcap;': '\u22c2',
2228         'xcirc;': '\u25ef',
2229         'xcup;': '\u22c3',
2230         'xdtri;': '\u25bd',
2231         'Xfr;': '\U0001d51b',
2232         'xfr;': '\U0001d535',
2233         'xhArr;': '\u27fa',
2234         'xharr;': '\u27f7',
2235         'Xi;': '\u039e',
2236         'xi;': '\u03be',
2237         'xlArr;': '\u27f8',
2238         'xlarr;': '\u27f5',
2239         'xmap;': '\u27fc',
2240         'xnis;': '\u22fb',
2241         'xodot;': '\u2a00',
2242         'Xopf;': '\U0001d54f',
2243         'xopf;': '\U0001d569',
2244         'xoplus;': '\u2a01',
2245         'xotime;': '\u2a02',
2246         'xrArr;': '\u27f9',
2247         'xrarr;': '\u27f6',
2248         'Xscr;': '\U0001d4b3',
2249         'xscr;': '\U0001d4cd',
2250         'xsqcup;': '\u2a06',
2251         'xuplus;': '\u2a04',
2252         'xutri;': '\u25b3',
2253         'xvee;': '\u22c1',
2254         'xwedge;': '\u22c0',
2255         'Yacute': '\xdd',
2256         'yacute': '\xfd',
2257         'Yacute;': '\xdd',
2258         'yacute;': '\xfd',
2259         'YAcy;': '\u042f',
2260         'yacy;': '\u044f',
2261         'Ycirc;': '\u0176',
2262         'ycirc;': '\u0177',
2263         'Ycy;': '\u042b',
2264         'ycy;': '\u044b',
2265         'yen': '\xa5',
2266         'yen;': '\xa5',
2267         'Yfr;': '\U0001d51c',
2268         'yfr;': '\U0001d536',
2269         'YIcy;': '\u0407',
2270         'yicy;': '\u0457',
2271         'Yopf;': '\U0001d550',
2272         'yopf;': '\U0001d56a',
2273         'Yscr;': '\U0001d4b4',
2274         'yscr;': '\U0001d4ce',
2275         'YUcy;': '\u042e',
2276         'yucy;': '\u044e',
2277         'yuml': '\xff',
2278         'Yuml;': '\u0178',
2279         'yuml;': '\xff',
2280         'Zacute;': '\u0179',
2281         'zacute;': '\u017a',
2282         'Zcaron;': '\u017d',
2283         'zcaron;': '\u017e',
2284         'Zcy;': '\u0417',
2285         'zcy;': '\u0437',
2286         'Zdot;': '\u017b',
2287         'zdot;': '\u017c',
2288         'zeetrf;': '\u2128',
2289         'ZeroWidthSpace;': '\u200b',
2290         'Zeta;': '\u0396',
2291         'zeta;': '\u03b6',
2292         'Zfr;': '\u2128',
2293         'zfr;': '\U0001d537',
2294         'ZHcy;': '\u0416',
2295         'zhcy;': '\u0436',
2296         'zigrarr;': '\u21dd',
2297         'Zopf;': '\u2124',
2298         'zopf;': '\U0001d56b',
2299         'Zscr;': '\U0001d4b5',
2300         'zscr;': '\U0001d4cf',
2301         'zwj;': '\u200d',
2302         'zwnj;': '\u200c',
2303     }
2304
2305 try:
2306     import http.client as compat_http_client
2307 except ImportError:  # Python 2
2308     import httplib as compat_http_client
2309
2310 try:
2311     from urllib.error import HTTPError as compat_HTTPError
2312 except ImportError:  # Python 2
2313     from urllib2 import HTTPError as compat_HTTPError
2314
2315 try:
2316     from urllib.request import urlretrieve as compat_urlretrieve
2317 except ImportError:  # Python 2
2318     from urllib import urlretrieve as compat_urlretrieve
2319
2320 try:
2321     from html.parser import HTMLParser as compat_HTMLParser
2322 except ImportError:  # Python 2
2323     from HTMLParser import HTMLParser as compat_HTMLParser
2324
2325 try:
2326     from subprocess import DEVNULL
2327     compat_subprocess_get_DEVNULL = lambda: DEVNULL
2328 except ImportError:
2329     compat_subprocess_get_DEVNULL = lambda: open(os.path.devnull, 'w')
2330
2331 try:
2332     import http.server as compat_http_server
2333 except ImportError:
2334     import BaseHTTPServer as compat_http_server
2335
2336 try:
2337     compat_str = unicode  # Python 2
2338 except NameError:
2339     compat_str = str
2340
2341 try:
2342     from urllib.parse import unquote_to_bytes as compat_urllib_parse_unquote_to_bytes
2343     from urllib.parse import unquote as compat_urllib_parse_unquote
2344     from urllib.parse import unquote_plus as compat_urllib_parse_unquote_plus
2345 except ImportError:  # Python 2
2346     _asciire = (compat_urllib_parse._asciire if hasattr(compat_urllib_parse, '_asciire')
2347                 else re.compile('([\x00-\x7f]+)'))
2348
2349     # HACK: The following are the correct unquote_to_bytes, unquote and unquote_plus
2350     # implementations from cpython 3.4.3's stdlib. Python 2's version
2351     # is apparently broken (see https://github.com/rg3/youtube-dl/pull/6244)
2352
2353     def compat_urllib_parse_unquote_to_bytes(string):
2354         """unquote_to_bytes('abc%20def') -> b'abc def'."""
2355         # Note: strings are encoded as UTF-8. This is only an issue if it contains
2356         # unescaped non-ASCII characters, which URIs should not.
2357         if not string:
2358             # Is it a string-like object?
2359             string.split
2360             return b''
2361         if isinstance(string, compat_str):
2362             string = string.encode('utf-8')
2363         bits = string.split(b'%')
2364         if len(bits) == 1:
2365             return string
2366         res = [bits[0]]
2367         append = res.append
2368         for item in bits[1:]:
2369             try:
2370                 append(compat_urllib_parse._hextochr[item[:2]])
2371                 append(item[2:])
2372             except KeyError:
2373                 append(b'%')
2374                 append(item)
2375         return b''.join(res)
2376
2377     def compat_urllib_parse_unquote(string, encoding='utf-8', errors='replace'):
2378         """Replace %xx escapes by their single-character equivalent. The optional
2379         encoding and errors parameters specify how to decode percent-encoded
2380         sequences into Unicode characters, as accepted by the bytes.decode()
2381         method.
2382         By default, percent-encoded sequences are decoded with UTF-8, and invalid
2383         sequences are replaced by a placeholder character.
2384
2385         unquote('abc%20def') -> 'abc def'.
2386         """
2387         if '%' not in string:
2388             string.split
2389             return string
2390         if encoding is None:
2391             encoding = 'utf-8'
2392         if errors is None:
2393             errors = 'replace'
2394         bits = _asciire.split(string)
2395         res = [bits[0]]
2396         append = res.append
2397         for i in range(1, len(bits), 2):
2398             append(compat_urllib_parse_unquote_to_bytes(bits[i]).decode(encoding, errors))
2399             append(bits[i + 1])
2400         return ''.join(res)
2401
2402     def compat_urllib_parse_unquote_plus(string, encoding='utf-8', errors='replace'):
2403         """Like unquote(), but also replace plus signs by spaces, as required for
2404         unquoting HTML form values.
2405
2406         unquote_plus('%7e/abc+def') -> '~/abc def'
2407         """
2408         string = string.replace('+', ' ')
2409         return compat_urllib_parse_unquote(string, encoding, errors)
2410
2411 try:
2412     from urllib.parse import urlencode as compat_urllib_parse_urlencode
2413 except ImportError:  # Python 2
2414     # Python 2 will choke in urlencode on mixture of byte and unicode strings.
2415     # Possible solutions are to either port it from python 3 with all
2416     # the friends or manually ensure input query contains only byte strings.
2417     # We will stick with latter thus recursively encoding the whole query.
2418     def compat_urllib_parse_urlencode(query, doseq=0, encoding='utf-8'):
2419         def encode_elem(e):
2420             if isinstance(e, dict):
2421                 e = encode_dict(e)
2422             elif isinstance(e, (list, tuple,)):
2423                 list_e = encode_list(e)
2424                 e = tuple(list_e) if isinstance(e, tuple) else list_e
2425             elif isinstance(e, compat_str):
2426                 e = e.encode(encoding)
2427             return e
2428
2429         def encode_dict(d):
2430             return dict((encode_elem(k), encode_elem(v)) for k, v in d.items())
2431
2432         def encode_list(l):
2433             return [encode_elem(e) for e in l]
2434
2435         return compat_urllib_parse.urlencode(encode_elem(query), doseq=doseq)
2436
2437 try:
2438     from urllib.request import DataHandler as compat_urllib_request_DataHandler
2439 except ImportError:  # Python < 3.4
2440     # Ported from CPython 98774:1733b3bd46db, Lib/urllib/request.py
2441     class compat_urllib_request_DataHandler(compat_urllib_request.BaseHandler):
2442         def data_open(self, req):
2443             # data URLs as specified in RFC 2397.
2444             #
2445             # ignores POSTed data
2446             #
2447             # syntax:
2448             # dataurl   := "data:" [ mediatype ] [ ";base64" ] "," data
2449             # mediatype := [ type "/" subtype ] *( ";" parameter )
2450             # data      := *urlchar
2451             # parameter := attribute "=" value
2452             url = req.get_full_url()
2453
2454             scheme, data = url.split(':', 1)
2455             mediatype, data = data.split(',', 1)
2456
2457             # even base64 encoded data URLs might be quoted so unquote in any case:
2458             data = compat_urllib_parse_unquote_to_bytes(data)
2459             if mediatype.endswith(';base64'):
2460                 data = binascii.a2b_base64(data)
2461                 mediatype = mediatype[:-7]
2462
2463             if not mediatype:
2464                 mediatype = 'text/plain;charset=US-ASCII'
2465
2466             headers = email.message_from_string(
2467                 'Content-type: %s\nContent-length: %d\n' % (mediatype, len(data)))
2468
2469             return compat_urllib_response.addinfourl(io.BytesIO(data), headers, url)
2470
2471 try:
2472     compat_basestring = basestring  # Python 2
2473 except NameError:
2474     compat_basestring = str
2475
2476 try:
2477     compat_chr = unichr  # Python 2
2478 except NameError:
2479     compat_chr = chr
2480
2481 try:
2482     from xml.etree.ElementTree import ParseError as compat_xml_parse_error
2483 except ImportError:  # Python 2.6
2484     from xml.parsers.expat import ExpatError as compat_xml_parse_error
2485
2486
2487 etree = xml.etree.ElementTree
2488
2489
2490 class _TreeBuilder(etree.TreeBuilder):
2491     def doctype(self, name, pubid, system):
2492         pass
2493
2494
2495 if sys.version_info[0] >= 3:
2496     def compat_etree_fromstring(text):
2497         return etree.XML(text, parser=etree.XMLParser(target=_TreeBuilder()))
2498 else:
2499     # python 2.x tries to encode unicode strings with ascii (see the
2500     # XMLParser._fixtext method)
2501     try:
2502         _etree_iter = etree.Element.iter
2503     except AttributeError:  # Python <=2.6
2504         def _etree_iter(root):
2505             for el in root.findall('*'):
2506                 yield el
2507                 for sub in _etree_iter(el):
2508                     yield sub
2509
2510     # on 2.6 XML doesn't have a parser argument, function copied from CPython
2511     # 2.7 source
2512     def _XML(text, parser=None):
2513         if not parser:
2514             parser = etree.XMLParser(target=_TreeBuilder())
2515         parser.feed(text)
2516         return parser.close()
2517
2518     def _element_factory(*args, **kwargs):
2519         el = etree.Element(*args, **kwargs)
2520         for k, v in el.items():
2521             if isinstance(v, bytes):
2522                 el.set(k, v.decode('utf-8'))
2523         return el
2524
2525     def compat_etree_fromstring(text):
2526         doc = _XML(text, parser=etree.XMLParser(target=_TreeBuilder(element_factory=_element_factory)))
2527         for el in _etree_iter(doc):
2528             if el.text is not None and isinstance(el.text, bytes):
2529                 el.text = el.text.decode('utf-8')
2530         return doc
2531
2532 if sys.version_info < (2, 7):
2533     # Here comes the crazy part: In 2.6, if the xpath is a unicode,
2534     # .//node does not match if a node is a direct child of . !
2535     def compat_xpath(xpath):
2536         if isinstance(xpath, compat_str):
2537             xpath = xpath.encode('ascii')
2538         return xpath
2539 else:
2540     compat_xpath = lambda xpath: xpath
2541
2542 try:
2543     from urllib.parse import parse_qs as compat_parse_qs
2544 except ImportError:  # Python 2
2545     # HACK: The following is the correct parse_qs implementation from cpython 3's stdlib.
2546     # Python 2's version is apparently totally broken
2547
2548     def _parse_qsl(qs, keep_blank_values=False, strict_parsing=False,
2549                    encoding='utf-8', errors='replace'):
2550         qs, _coerce_result = qs, compat_str
2551         pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
2552         r = []
2553         for name_value in pairs:
2554             if not name_value and not strict_parsing:
2555                 continue
2556             nv = name_value.split('=', 1)
2557             if len(nv) != 2:
2558                 if strict_parsing:
2559                     raise ValueError('bad query field: %r' % (name_value,))
2560                 # Handle case of a control-name with no equal sign
2561                 if keep_blank_values:
2562                     nv.append('')
2563                 else:
2564                     continue
2565             if len(nv[1]) or keep_blank_values:
2566                 name = nv[0].replace('+', ' ')
2567                 name = compat_urllib_parse_unquote(
2568                     name, encoding=encoding, errors=errors)
2569                 name = _coerce_result(name)
2570                 value = nv[1].replace('+', ' ')
2571                 value = compat_urllib_parse_unquote(
2572                     value, encoding=encoding, errors=errors)
2573                 value = _coerce_result(value)
2574                 r.append((name, value))
2575         return r
2576
2577     def compat_parse_qs(qs, keep_blank_values=False, strict_parsing=False,
2578                         encoding='utf-8', errors='replace'):
2579         parsed_result = {}
2580         pairs = _parse_qsl(qs, keep_blank_values, strict_parsing,
2581                            encoding=encoding, errors=errors)
2582         for name, value in pairs:
2583             if name in parsed_result:
2584                 parsed_result[name].append(value)
2585             else:
2586                 parsed_result[name] = [value]
2587         return parsed_result
2588
2589 try:
2590     from shlex import quote as compat_shlex_quote
2591 except ImportError:  # Python < 3.3
2592     def compat_shlex_quote(s):
2593         if re.match(r'^[-_\w./]+$', s):
2594             return s
2595         else:
2596             return "'" + s.replace("'", "'\"'\"'") + "'"
2597
2598
2599 try:
2600     args = shlex.split('中文')
2601     assert (isinstance(args, list) and
2602             isinstance(args[0], compat_str) and
2603             args[0] == '中文')
2604     compat_shlex_split = shlex.split
2605 except (AssertionError, UnicodeEncodeError):
2606     # Working around shlex issue with unicode strings on some python 2
2607     # versions (see http://bugs.python.org/issue1548891)
2608     def compat_shlex_split(s, comments=False, posix=True):
2609         if isinstance(s, compat_str):
2610             s = s.encode('utf-8')
2611         return list(map(lambda s: s.decode('utf-8'), shlex.split(s, comments, posix)))
2612
2613
2614 def compat_ord(c):
2615     if type(c) is int:
2616         return c
2617     else:
2618         return ord(c)
2619
2620
2621 compat_os_name = os._name if os.name == 'java' else os.name
2622
2623
2624 if sys.version_info >= (3, 0):
2625     compat_getenv = os.getenv
2626     compat_expanduser = os.path.expanduser
2627
2628     def compat_setenv(key, value, env=os.environ):
2629         env[key] = value
2630 else:
2631     # Environment variables should be decoded with filesystem encoding.
2632     # Otherwise it will fail if any non-ASCII characters present (see #3854 #3217 #2918)
2633
2634     def compat_getenv(key, default=None):
2635         from .utils import get_filesystem_encoding
2636         env = os.getenv(key, default)
2637         if env:
2638             env = env.decode(get_filesystem_encoding())
2639         return env
2640
2641     def compat_setenv(key, value, env=os.environ):
2642         def encode(v):
2643             from .utils import get_filesystem_encoding
2644             return v.encode(get_filesystem_encoding()) if isinstance(v, compat_str) else v
2645         env[encode(key)] = encode(value)
2646
2647     # HACK: The default implementations of os.path.expanduser from cpython do not decode
2648     # environment variables with filesystem encoding. We will work around this by
2649     # providing adjusted implementations.
2650     # The following are os.path.expanduser implementations from cpython 2.7.8 stdlib
2651     # for different platforms with correct environment variables decoding.
2652
2653     if compat_os_name == 'posix':
2654         def compat_expanduser(path):
2655             """Expand ~ and ~user constructions.  If user or $HOME is unknown,
2656             do nothing."""
2657             if not path.startswith('~'):
2658                 return path
2659             i = path.find('/', 1)
2660             if i < 0:
2661                 i = len(path)
2662             if i == 1:
2663                 if 'HOME' not in os.environ:
2664                     import pwd
2665                     userhome = pwd.getpwuid(os.getuid()).pw_dir
2666                 else:
2667                     userhome = compat_getenv('HOME')
2668             else:
2669                 import pwd
2670                 try:
2671                     pwent = pwd.getpwnam(path[1:i])
2672                 except KeyError:
2673                     return path
2674                 userhome = pwent.pw_dir
2675             userhome = userhome.rstrip('/')
2676             return (userhome + path[i:]) or '/'
2677     elif compat_os_name == 'nt' or compat_os_name == 'ce':
2678         def compat_expanduser(path):
2679             """Expand ~ and ~user constructs.
2680
2681             If user or $HOME is unknown, do nothing."""
2682             if path[:1] != '~':
2683                 return path
2684             i, n = 1, len(path)
2685             while i < n and path[i] not in '/\\':
2686                 i = i + 1
2687
2688             if 'HOME' in os.environ:
2689                 userhome = compat_getenv('HOME')
2690             elif 'USERPROFILE' in os.environ:
2691                 userhome = compat_getenv('USERPROFILE')
2692             elif 'HOMEPATH' not in os.environ:
2693                 return path
2694             else:
2695                 try:
2696                     drive = compat_getenv('HOMEDRIVE')
2697                 except KeyError:
2698                     drive = ''
2699                 userhome = os.path.join(drive, compat_getenv('HOMEPATH'))
2700
2701             if i != 1:  # ~user
2702                 userhome = os.path.join(os.path.dirname(userhome), path[1:i])
2703
2704             return userhome + path[i:]
2705     else:
2706         compat_expanduser = os.path.expanduser
2707
2708
2709 if sys.version_info < (3, 0):
2710     def compat_print(s):
2711         from .utils import preferredencoding
2712         print(s.encode(preferredencoding(), 'xmlcharrefreplace'))
2713 else:
2714     def compat_print(s):
2715         assert isinstance(s, compat_str)
2716         print(s)
2717
2718
2719 if sys.version_info < (3, 0) and sys.platform == 'win32':
2720     def compat_getpass(prompt, *args, **kwargs):
2721         if isinstance(prompt, compat_str):
2722             from .utils import preferredencoding
2723             prompt = prompt.encode(preferredencoding())
2724         return getpass.getpass(prompt, *args, **kwargs)
2725 else:
2726     compat_getpass = getpass.getpass
2727
2728 try:
2729     compat_input = raw_input
2730 except NameError:  # Python 3
2731     compat_input = input
2732
2733 # Python < 2.6.5 require kwargs to be bytes
2734 try:
2735     def _testfunc(x):
2736         pass
2737     _testfunc(**{'x': 0})
2738 except TypeError:
2739     def compat_kwargs(kwargs):
2740         return dict((bytes(k), v) for k, v in kwargs.items())
2741 else:
2742     compat_kwargs = lambda kwargs: kwargs
2743
2744
2745 if sys.version_info < (2, 7):
2746     def compat_socket_create_connection(address, timeout, source_address=None):
2747         host, port = address
2748         err = None
2749         for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
2750             af, socktype, proto, canonname, sa = res
2751             sock = None
2752             try:
2753                 sock = socket.socket(af, socktype, proto)
2754                 sock.settimeout(timeout)
2755                 if source_address:
2756                     sock.bind(source_address)
2757                 sock.connect(sa)
2758                 return sock
2759             except socket.error as _:
2760                 err = _
2761                 if sock is not None:
2762                     sock.close()
2763         if err is not None:
2764             raise err
2765         else:
2766             raise socket.error('getaddrinfo returns an empty list')
2767 else:
2768     compat_socket_create_connection = socket.create_connection
2769
2770
2771 # Fix https://github.com/rg3/youtube-dl/issues/4223
2772 # See http://bugs.python.org/issue9161 for what is broken
2773 def workaround_optparse_bug9161():
2774     op = optparse.OptionParser()
2775     og = optparse.OptionGroup(op, 'foo')
2776     try:
2777         og.add_option('-t')
2778     except TypeError:
2779         real_add_option = optparse.OptionGroup.add_option
2780
2781         def _compat_add_option(self, *args, **kwargs):
2782             enc = lambda v: (
2783                 v.encode('ascii', 'replace') if isinstance(v, compat_str)
2784                 else v)
2785             bargs = [enc(a) for a in args]
2786             bkwargs = dict(
2787                 (k, enc(v)) for k, v in kwargs.items())
2788             return real_add_option(self, *bargs, **bkwargs)
2789         optparse.OptionGroup.add_option = _compat_add_option
2790
2791
2792 if hasattr(shutil, 'get_terminal_size'):  # Python >= 3.3
2793     compat_get_terminal_size = shutil.get_terminal_size
2794 else:
2795     _terminal_size = collections.namedtuple('terminal_size', ['columns', 'lines'])
2796
2797     def compat_get_terminal_size(fallback=(80, 24)):
2798         columns = compat_getenv('COLUMNS')
2799         if columns:
2800             columns = int(columns)
2801         else:
2802             columns = None
2803         lines = compat_getenv('LINES')
2804         if lines:
2805             lines = int(lines)
2806         else:
2807             lines = None
2808
2809         if columns is None or lines is None or columns <= 0 or lines <= 0:
2810             try:
2811                 sp = subprocess.Popen(
2812                     ['stty', 'size'],
2813                     stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2814                 out, err = sp.communicate()
2815                 _lines, _columns = map(int, out.split())
2816             except Exception:
2817                 _columns, _lines = _terminal_size(*fallback)
2818
2819             if columns is None or columns <= 0:
2820                 columns = _columns
2821             if lines is None or lines <= 0:
2822                 lines = _lines
2823         return _terminal_size(columns, lines)
2824
2825 try:
2826     itertools.count(start=0, step=1)
2827     compat_itertools_count = itertools.count
2828 except TypeError:  # Python 2.6
2829     def compat_itertools_count(start=0, step=1):
2830         n = start
2831         while True:
2832             yield n
2833             n += step
2834
2835 if sys.version_info >= (3, 0):
2836     from tokenize import tokenize as compat_tokenize_tokenize
2837 else:
2838     from tokenize import generate_tokens as compat_tokenize_tokenize
2839
2840
2841 try:
2842     struct.pack('!I', 0)
2843 except TypeError:
2844     # In Python 2.6 and 2.7.x < 2.7.7, struct requires a bytes argument
2845     # See https://bugs.python.org/issue19099
2846     def compat_struct_pack(spec, *args):
2847         if isinstance(spec, compat_str):
2848             spec = spec.encode('ascii')
2849         return struct.pack(spec, *args)
2850
2851     def compat_struct_unpack(spec, *args):
2852         if isinstance(spec, compat_str):
2853             spec = spec.encode('ascii')
2854         return struct.unpack(spec, *args)
2855 else:
2856     compat_struct_pack = struct.pack
2857     compat_struct_unpack = struct.unpack
2858
2859
2860 __all__ = [
2861     'compat_HTMLParser',
2862     'compat_HTTPError',
2863     'compat_basestring',
2864     'compat_chr',
2865     'compat_cookiejar',
2866     'compat_cookies',
2867     'compat_etree_fromstring',
2868     'compat_expanduser',
2869     'compat_get_terminal_size',
2870     'compat_getenv',
2871     'compat_getpass',
2872     'compat_html_entities',
2873     'compat_html_entities_html5',
2874     'compat_http_client',
2875     'compat_http_server',
2876     'compat_input',
2877     'compat_itertools_count',
2878     'compat_kwargs',
2879     'compat_ord',
2880     'compat_os_name',
2881     'compat_parse_qs',
2882     'compat_print',
2883     'compat_setenv',
2884     'compat_shlex_quote',
2885     'compat_shlex_split',
2886     'compat_socket_create_connection',
2887     'compat_str',
2888     'compat_struct_pack',
2889     'compat_struct_unpack',
2890     'compat_subprocess_get_DEVNULL',
2891     'compat_tokenize_tokenize',
2892     'compat_urllib_error',
2893     'compat_urllib_parse',
2894     'compat_urllib_parse_unquote',
2895     'compat_urllib_parse_unquote_plus',
2896     'compat_urllib_parse_unquote_to_bytes',
2897     'compat_urllib_parse_urlencode',
2898     'compat_urllib_parse_urlparse',
2899     'compat_urllib_request',
2900     'compat_urllib_request_DataHandler',
2901     'compat_urllib_response',
2902     'compat_urlparse',
2903     'compat_urlretrieve',
2904     'compat_xml_parse_error',
2905     'compat_xpath',
2906     'workaround_optparse_bug9161',
2907 ]