Skip to content

Commit

Permalink
Filenames can be unicode.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeboers authored and rodrhern committed Jun 14, 2018
1 parent 626e9c6 commit ad07382
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -23,6 +23,7 @@ Fixes:
- Packets retain their refcount after muxing. (#334.)
- `Codec` construction is more robust to find more codecs. (#332 by @adavoudi).
- Refined frame corruption detection. (#291 by @Litterfeldt.)
- Unicode filenames are okay. (#82.)


v0.4.0
Expand Down
5 changes: 3 additions & 2 deletions av/container/core.pxd
Expand Up @@ -16,8 +16,9 @@ cdef class ContainerProxy(object):
cdef seek(self, int stream_index, offset, str whence, bint backward, bint any_frame)
cdef flush_buffers(self)


# Copies from Container.
cdef str name
cdef object name
cdef str metadata_encoding
cdef str metadata_errors

Expand All @@ -41,7 +42,7 @@ cdef class ContainerProxy(object):

cdef class Container(object):

cdef readonly str name
cdef readonly object name
cdef readonly object file

cdef readonly bint writeable
Expand Down
13 changes: 10 additions & 3 deletions av/container/core.pyx
Expand Up @@ -16,6 +16,11 @@ from av.dictionary import Dictionary # not cimport
from av.logging import Capture as LogCapture # not cimport
from av.utils import AVError # not cimport

try:
from os import fsencode
except ImportError:
_fsencoding = sys.getfilesystemencoding()
fsencode = lambda s: s.encode(_fsencoding)



Expand Down Expand Up @@ -75,8 +80,8 @@ cdef class ContainerProxy(object):
self.name = container.name
self.writeable = container.writeable

cdef char *name = self.name

cdef bytes name_obj = fsencode(self.name) if isinstance(self.name, unicode) else self.name
cdef char *name = name_obj

cdef lib.AVOutputFormat *ofmt
if self.writeable:
Expand Down Expand Up @@ -250,7 +255,9 @@ cdef class Container(object):
if isinstance(file_, basestring):
self.name = file_
else:
self.name = str(getattr(file_, 'name', None))
self.name = getattr(file_, 'name', '<none>')
if not isinstance(self.name, basestring):
raise TypeError("File's name attribute must be string-like.")
self.file = file_

if format_name is not None:
Expand Down
2 changes: 1 addition & 1 deletion av/utils.pxd
Expand Up @@ -5,7 +5,7 @@ cimport libav as lib

cdef int stash_exception(exc_info=*)

cpdef int err_check(int res=*, str filename=*) except -1
cpdef int err_check(int res=*, filename=*) except -1



Expand Down
2 changes: 1 addition & 1 deletion av/utils.pyx
Expand Up @@ -62,7 +62,7 @@ cdef int stash_exception(exc_info=None):

cdef int _last_log_count = 0

cpdef int err_check(int res=0, str filename=None) except -1:
cpdef int err_check(int res=0, filename=None) except -1:

global _err_count
global _last_log_count
Expand Down
11 changes: 11 additions & 0 deletions tests/test_container.py
@@ -0,0 +1,11 @@
# coding: utf8

from common import *


class TestContainers(TestCase):

def test_unicode_filename(self):

container = av.open(self.sandboxed(u'¢∞§¶•ªº.mov'), 'w')

0 comments on commit ad07382

Please sign in to comment.