mirror of
https://github.com/beetbox/beets.git
synced 2025-12-24 01:25:47 +01:00
Decode string with Unicode escape
This commit is contained in:
parent
68089ac8e9
commit
2bf58a61c3
1 changed files with 7 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ from __future__ import absolute_import, division, print_function
|
|||
import difflib
|
||||
import itertools
|
||||
import json
|
||||
import struct
|
||||
import re
|
||||
import requests
|
||||
import unicodedata
|
||||
|
|
@ -77,6 +78,11 @@ USER_AGENT = 'beets/{}'.format(beets.__version__)
|
|||
|
||||
# Utilities.
|
||||
|
||||
def unichar(i):
|
||||
try:
|
||||
return six.unichr(i)
|
||||
except ValueError:
|
||||
return struct.pack('i', i).decode('utf-32')
|
||||
|
||||
def unescape(text):
|
||||
"""Resolve &#xxx; HTML entities (and some others)."""
|
||||
|
|
@ -86,7 +92,7 @@ def unescape(text):
|
|||
|
||||
def replchar(m):
|
||||
num = m.group(1)
|
||||
return six.unichr(int(num))
|
||||
return unichar(int(num))
|
||||
out = re.sub(u"&#(\d+);", replchar, out)
|
||||
return out
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue