mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-23 09:01:43 +00:00
[utils] Add default value for xpath_text
This commit is contained in:
parent
9603e8a7d9
commit
bf42a9906d
@ -62,6 +62,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NO_DEFAULT = object()
|
||||||
|
|
||||||
ENGLISH_MONTH_NAMES = [
|
ENGLISH_MONTH_NAMES = [
|
||||||
'January', 'February', 'March', 'April', 'May', 'June',
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||||||
'July', 'August', 'September', 'October', 'November', 'December']
|
'July', 'August', 'September', 'October', 'November', 'December']
|
||||||
@ -171,13 +173,15 @@ def xpath_with_ns(path, ns_map):
|
|||||||
return '/'.join(replaced)
|
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
|
if sys.version_info < (2, 7): # Crazy 2.6
|
||||||
xpath = xpath.encode('ascii')
|
xpath = xpath.encode('ascii')
|
||||||
|
|
||||||
n = node.find(xpath)
|
n = node.find(xpath)
|
||||||
if n is None or n.text is None:
|
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
|
name = xpath if name is None else name
|
||||||
raise ExtractorError('Could not find XML element %s' % name)
|
raise ExtractorError('Could not find XML element %s' % name)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user