mirror of
https://github.com/soimort/you-get.git
synced 2025-03-13 03:17:44 +03:00
[util.strings] use 4-space indentation
This commit is contained in:
parent
0cabb980b6
commit
bca2c3eed3
@ -1,25 +1,25 @@
|
|||||||
try:
|
try:
|
||||||
# py 3.4
|
# py 3.4
|
||||||
from html import unescape as unescape_html
|
from html import unescape as unescape_html
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import re
|
import re
|
||||||
from html.entities import entitydefs
|
from html.entities import entitydefs
|
||||||
|
|
||||||
def unescape_html(string):
|
def unescape_html(string):
|
||||||
'''HTML entity decode'''
|
'''HTML entity decode'''
|
||||||
string = re.sub(r'&#[^;]+;', _sharp2uni, string)
|
string = re.sub(r'&#[^;]+;', _sharp2uni, string)
|
||||||
string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
|
string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
|
||||||
return string
|
return string
|
||||||
|
|
||||||
def _sharp2uni(m):
|
def _sharp2uni(m):
|
||||||
'''&#...; ==> unicode'''
|
'''&#...; ==> unicode'''
|
||||||
s = m.group(0)[2:].rstrip(';;')
|
s = m.group(0)[2:].rstrip(';;')
|
||||||
if s.startswith('x'):
|
if s.startswith('x'):
|
||||||
return chr(int('0'+s, 16))
|
return chr(int('0'+s, 16))
|
||||||
else:
|
else:
|
||||||
return chr(int(s))
|
return chr(int(s))
|
||||||
|
|
||||||
from .fs import legitimize
|
from .fs import legitimize
|
||||||
|
|
||||||
def get_filename(htmlstring):
|
def get_filename(htmlstring):
|
||||||
return legitimize(unescape_html(htmlstring))
|
return legitimize(unescape_html(htmlstring))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user