projects
/
youtube-dl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[utils] Support attributes with no values in get_elements_by_attribute()
[youtube-dl]
/
youtube_dl
/
utils.py
diff --git
a/youtube_dl/utils.py
b/youtube_dl/utils.py
index d79410e58a2ae0965faa291f67b9a6645956c5f0..fdf5e29e7d417b94ba7f83129a8420f93ed31217 100644
(file)
--- a/
youtube_dl/utils.py
+++ b/
youtube_dl/utils.py
@@
-22,7
+22,6
@@
import locale
import math
import operator
import os
import math
import operator
import os
-import pipes
import platform
import random
import re
import platform
import random
import re
@@
-36,6
+35,7
@@
import xml.etree.ElementTree
import zlib
from .compat import (
import zlib
from .compat import (
+ compat_HTMLParseError,
compat_HTMLParser,
compat_basestring,
compat_chr,
compat_HTMLParser,
compat_basestring,
compat_chr,
@@
-365,9
+365,9
@@
def get_elements_by_attribute(attribute, value, html, escape_value=True):
retlist = []
for m in re.finditer(r'''(?xs)
<([a-zA-Z0-9:._-]+)
retlist = []
for m in re.finditer(r'''(?xs)
<([a-zA-Z0-9:._-]+)
- (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'))*?
+ (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'
|
))*?
\s+%s=['"]?%s['"]?
\s+%s=['"]?%s['"]?
- (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'))*?
+ (?:\s+[a-zA-Z0-9:._-]+(?:=[a-zA-Z0-9:._-]*|="[^"]*"|='[^']*'
|
))*?
\s*>
(?P<content>.*?)
</\1>
\s*>
(?P<content>.*?)
</\1>
@@
-409,8
+409,12
@@
def extract_attributes(html_element):
but the cases in the unit test will work for all of 2.6, 2.7, 3.2-3.5.
"""
parser = HTMLAttributeParser()
but the cases in the unit test will work for all of 2.6, 2.7, 3.2-3.5.
"""
parser = HTMLAttributeParser()
- parser.feed(html_element)
- parser.close()
+ try:
+ parser.feed(html_element)
+ parser.close()
+ # Older Python may throw HTMLParseError in case of malformed HTML
+ except compat_HTMLParseError:
+ pass
return parser.attrs
return parser.attrs
@@
-1179,7
+1183,7
@@
def unified_timestamp(date_str, day_first=True):
if date_str is None:
return None
if date_str is None:
return None
- date_str =
date_str.replace(',', ' '
)
+ date_str =
re.sub(r'[,|]', '', date_str
)
pm_delta = 12 if re.search(r'(?i)PM', date_str) else 0
timezone, date_str = extract_timezone(date_str)
pm_delta = 12 if re.search(r'(?i)PM', date_str) else 0
timezone, date_str = extract_timezone(date_str)
@@
-1530,7
+1534,7
@@
def shell_quote(args):
if isinstance(a, bytes):
# We may get a filename encoded with 'encodeFilename'
a = a.decode(encoding)
if isinstance(a, bytes):
# We may get a filename encoded with 'encodeFilename'
a = a.decode(encoding)
- quoted_args.append(
pipes.
quote(a))
+ quoted_args.append(
compat_shlex_
quote(a))
return ' '.join(quoted_args)
return ' '.join(quoted_args)