Skip to content

Commit

Permalink
Fix Python 2 support for unicode file names, fixes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
sbraz committed May 4, 2016
1 parent f6d6c1e commit ec3b541
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pymediainfo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import locale
import json
import sys
from pkg_resources import get_distribution
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -92,6 +93,13 @@ def parse(filename):
# Create a MediaInfo handle
handle = lib.MediaInfo_New()
lib.MediaInfo_Option(handle, "CharSet", "UTF-8")
# Fix for https://github.com/sbraz/pymediainfo/issues/22
# Python 2 does not change LC_CTYPE
# at startup: https://bugs.python.org/issue6203
if (sys.version_info.major < 3 and os.name == "posix"
and not sys.platform == "darwin"
and locale.getlocale() == (None, None)):
locale.setlocale(locale.LC_CTYPE, locale.getdefaultlocale())
lib.MediaInfo_Option(None, "Inform", "XML")
lib.MediaInfo_Option(None, "Complete", "1")
lib.MediaInfo_Open(handle, filename)
Expand Down
2 changes: 0 additions & 2 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ def test_parse_file_with_unicode_tags(self):
"l’aÿ d’âge mûr & cætera !"
)

@unittest.skipIf(sys.version_info.major < 3, "Currently broken "
"see https://github.com/sbraz/pymediainfo/issues/22")
class MediaInfoUnicodeFileNameTest(unittest.TestCase):
def setUp(self):
self.mi = MediaInfo.parse(os.path.join(data_dir, "accentué.txt"))
Expand Down

0 comments on commit ec3b541

Please sign in to comment.