diff options
author | Sergey M․ <dstftw@gmail.com> | 2015-06-28 22:56:07 +0600 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2015-06-28 22:56:07 +0600 |
commit | bf42a9906d9a066d32f1cc50e1b033e6676744ba (patch) | |
tree | c777b554197fdea2d289d9a1cc64130223d0327f /youtube_dl/utils.py | |
parent | 9603e8a7d998615d3da1af47461ec9c353ec4e7a (diff) |
[utils] Add default value for xpath_text
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 96490f112..942f76d24 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -62,6 +62,8 @@ std_headers = { } +NO_DEFAULT = object() + ENGLISH_MONTH_NAMES = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] @@ -171,13 +173,15 @@ def xpath_with_ns(path, ns_map): return '/'.join(replaced) -def xpath_text(node, xpath, name=None, fatal=False): +def xpath_text(node, xpath, name=None, fatal=False, default=NO_DEFAULT): if sys.version_info < (2, 7): # Crazy 2.6 xpath = xpath.encode('ascii') n = node.find(xpath) if n is None or n.text is None: - if fatal: + if default is not NO_DEFAULT: + return default + elif fatal: name = xpath if name is None else name raise ExtractorError('Could not find XML element %s' % name) else: |