projects
/
youtube-dl
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9603e8a
)
[utils] Add default value for xpath_text
author
Sergey M․
<dstftw@gmail.com>
Sun, 28 Jun 2015 16:56:07 +0000
(22:56 +0600)
committer
Sergey M․
<dstftw@gmail.com>
Sun, 28 Jun 2015 16:56:07 +0000
(22:56 +0600)
youtube_dl/utils.py
patch
|
blob
|
history
diff --git
a/youtube_dl/utils.py
b/youtube_dl/utils.py
index 96490f112ecf69d0bd99fe7fb65720ab1f0f3985..942f76d2452c06a261d75e03cebc999fff02874c 100644
(file)
--- 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']
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)
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 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:
name = xpath if name is None else name
raise ExtractorError('Could not find XML element %s' % name)
else: