projects
/
youtube-dl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0d0e282
)
[compat] Add compat_xpath
author
Sergey M․
<dstftw@gmail.com>
Thu, 17 Mar 2016 20:51:38 +0000
(
02:51
+0600)
committer
Sergey M․
<dstftw@gmail.com>
Thu, 17 Mar 2016 20:51:38 +0000
(
02:51
+0600)
youtube_dl/compat.py
patch
|
blob
|
history
diff --git
a/youtube_dl/compat.py
b/youtube_dl/compat.py
index 74702786a76ee612a7f9ec91567752e22e70eda6..dbb91a6ef19ecdc5b1ca396424dda33d8107b2b4 100644
(file)
--- a/
youtube_dl/compat.py
+++ b/
youtube_dl/compat.py
@@
-256,6
+256,16
@@
else:
el.text = el.text.decode('utf-8')
return doc
el.text = el.text.decode('utf-8')
return doc
+if sys.version_info < (2, 7):
+ # Here comes the crazy part: In 2.6, if the xpath is a unicode,
+ # .//node does not match if a node is a direct child of . !
+ def compat_xpath(xpath):
+ if isinstance(xpath, compat_str):
+ xpath = xpath.encode('ascii')
+ return xpath
+else:
+ compat_xpath = lambda xpath: xpath
+
try:
from urllib.parse import parse_qs as compat_parse_qs
except ImportError: # Python 2
try:
from urllib.parse import parse_qs as compat_parse_qs
except ImportError: # Python 2
@@
-585,6
+595,7
@@
__all__ = [
'compat_urlparse',
'compat_urlretrieve',
'compat_xml_parse_error',
'compat_urlparse',
'compat_urlretrieve',
'compat_xml_parse_error',
+ 'compat_xpath',
'shlex_quote',
'subprocess_check_output',
'workaround_optparse_bug9161',
'shlex_quote',
'subprocess_check_output',
'workaround_optparse_bug9161',