Unify coding cookie
[youtube-dl] / youtube_dl / utils.py
index 243d0903412efccde1fa4156cf5511cf93f25ba2..0569d231c66cc4f952449e15131de8fa120439e2 100644 (file)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# coding: utf-8
 
 from __future__ import unicode_literals
 
@@ -124,8 +124,6 @@ DATE_FORMATS = (
     '%d %b %Y',
     '%B %d %Y',
     '%b %d %Y',
-    '%b %d %Y at %H:%M',
-    '%b %d %Y at %H:%M:%S',
     '%b %dst %Y %I:%M',
     '%b %dnd %Y %I:%M',
     '%b %dth %Y %I:%M',
@@ -144,6 +142,8 @@ DATE_FORMATS = (
     '%Y-%m-%dT%H:%M:%S',
     '%Y-%m-%dT%H:%M:%S.%f',
     '%Y-%m-%dT%H:%M',
+    '%b %d %Y at %H:%M',
+    '%b %d %Y at %H:%M:%S',
 )
 
 DATE_FORMATS_DAY_FIRST = list(DATE_FORMATS)
@@ -782,6 +782,7 @@ class XAttrMetadataError(Exception):
     def __init__(self, code=None, msg='Unknown error'):
         super(XAttrMetadataError, self).__init__(msg)
         self.code = code
+        self.msg = msg
 
         # Parsing code and msg
         if (self.code in (errno.ENOSPC, errno.EDQUOT) or
@@ -3161,20 +3162,25 @@ def write_xattr(path, key, value):
         # try the pyxattr module...
         import xattr
 
-        # Unicode arguments are not supported in python-pyxattr until
-        # version 0.5.0
-        # See https://github.com/rg3/youtube-dl/issues/5498
-        pyxattr_required_version = '0.5.0'
-        if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):
-            # TODO: fallback to CLI tools
-            raise XAttrUnavailableError(
-                'python-pyxattr is detected but is too old. '
-                'youtube-dl requires %s or above while your version is %s. '
-                'Falling back to other xattr implementations' % (
-                    pyxattr_required_version, xattr.__version__))
+        if hasattr(xattr, 'set'):  # pyxattr
+            # Unicode arguments are not supported in python-pyxattr until
+            # version 0.5.0
+            # See https://github.com/rg3/youtube-dl/issues/5498
+            pyxattr_required_version = '0.5.0'
+            if version_tuple(xattr.__version__) < version_tuple(pyxattr_required_version):
+                # TODO: fallback to CLI tools
+                raise XAttrUnavailableError(
+                    'python-pyxattr is detected but is too old. '
+                    'youtube-dl requires %s or above while your version is %s. '
+                    'Falling back to other xattr implementations' % (
+                        pyxattr_required_version, xattr.__version__))
+
+            setxattr = xattr.set
+        else:  # xattr
+            setxattr = xattr.setxattr
 
         try:
-            xattr.set(path, key, value)
+            setxattr(path, key, value)
         except EnvironmentError as e:
             raise XAttrMetadataError(e.errno, e.strerror)