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:
|
||||
# py 3.4
|
||||
from html import unescape as unescape_html
|
||||
# py 3.4
|
||||
from html import unescape as unescape_html
|
||||
except ImportError:
|
||||
import re
|
||||
from html.entities import entitydefs
|
||||
import re
|
||||
from html.entities import entitydefs
|
||||
|
||||
def unescape_html(string):
|
||||
'''HTML entity decode'''
|
||||
string = re.sub(r'&#[^;]+;', _sharp2uni, string)
|
||||
string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
|
||||
return string
|
||||
def unescape_html(string):
|
||||
'''HTML entity decode'''
|
||||
string = re.sub(r'&#[^;]+;', _sharp2uni, string)
|
||||
string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
|
||||
return string
|
||||
|
||||
def _sharp2uni(m):
|
||||
'''&#...; ==> unicode'''
|
||||
s = m.group(0)[2:].rstrip(';;')
|
||||
if s.startswith('x'):
|
||||
return chr(int('0'+s, 16))
|
||||
else:
|
||||
return chr(int(s))
|
||||
def _sharp2uni(m):
|
||||
'''&#...; ==> unicode'''
|
||||
s = m.group(0)[2:].rstrip(';;')
|
||||
if s.startswith('x'):
|
||||
return chr(int('0'+s, 16))
|
||||
else:
|
||||
return chr(int(s))
|
||||
|
||||
from .fs import legitimize
|
||||
|
||||
def get_filename(htmlstring):
|
||||
return legitimize(unescape_html(htmlstring))
|
||||
return legitimize(unescape_html(htmlstring))
|
||||
|
Loading…
x
Reference in New Issue
Block a user