aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dl/compat.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2016-03-18 02:51:38 +0600
committerSergey M․ <dstftw@gmail.com>2016-03-18 02:51:38 +0600
commit57f7e3c62df187457a057be88fca43136f4c507f (patch)
tree0a5319c49e6bfa45d89374d550e06ea14ecb0de4 /youtube_dl/compat.py
parent0d0e282912a7ade43a148518c742557c310a41a3 (diff)
downloadyoutube-dl-57f7e3c62df187457a057be88fca43136f4c507f.zip
youtube-dl-57f7e3c62df187457a057be88fca43136f4c507f.tar.gz
youtube-dl-57f7e3c62df187457a057be88fca43136f4c507f.tar.bz2
[compat] Add compat_xpath
Diffstat (limited to 'youtube_dl/compat.py')
-rw-r--r--youtube_dl/compat.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py
index 7470278..dbb91a6 100644
--- a/youtube_dl/compat.py
+++ b/youtube_dl/compat.py
@@ -256,6 +256,16 @@ else:
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
@@ -585,6 +595,7 @@ __all__ = [
'compat_urlparse',
'compat_urlretrieve',
'compat_xml_parse_error',
+ 'compat_xpath',
'shlex_quote',
'subprocess_check_output',
'workaround_optparse_bug9161',