Skip to content

Commit

Permalink
fix for repr method on files with non-ascii characters
Browse files Browse the repository at this point in the history
  • Loading branch information
quintusdias committed Nov 17, 2014
1 parent 322dead commit 82d15dd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
16 changes: 9 additions & 7 deletions libxmp/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@
efficiently access the XMP in specific file formats. It also includes a
fallback packet scanner that can be used for unknown file formats.
"""
import sys

from . import XMPError, XMPMeta
from .consts import options_mask
from .consts import XMP_CLOSE_NOOPTION
from .consts import XMP_OPEN_OPTIONS
from .consts import XMP_OPEN_NOOPTION
from .consts import XMP_CLOSE_NOOPTION, XMP_OPEN_OPTIONS, XMP_OPEN_NOOPTION
from . import exempi as _cexempi

__all__ = ['XMPFiles']
Expand Down Expand Up @@ -80,13 +79,16 @@ def __init__(self, **kwargs ):


def __repr__(self):
msg = "XMPFiles("
if self._file_path is None:
msg += ")"
msg = "XMPFiles()"
else:
msg += "file_path='{0}')"
msg = msg.format(self._file_path)
if sys.hexversion < 0x03000000 and type(self._file_path) is unicode:
fmt = u"XMPFiles(file_path='{0}')"
else:
fmt = "XMPFiles(file_path='{0}')"
msg = fmt.format(self._file_path)
return msg

def __del__(self):
"""
Free up the memory associated with the XMP file instance.
Expand Down
18 changes: 18 additions & 0 deletions test/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ def test_print_bom(self):
repr(xmp)
self.assertTrue(True)

def test_repr_on_latin1_filename(self):
"""
should be able to echo a filename with latin1 characters
See issue#36
"""
srcfile = pkg_resources.resource_filename(__name__,
"samples/BlueSquare.jpg")
latin1_name = u"éà*çc! teeest!!.jpg"

dest = os.path.join(self.tempdir, latin1_name)
shutil.copyfile(srcfile, dest)
xmpf = XMPFiles()
xmpf.open_file(file_path=dest)
# If we don't error out when the __repr__ method is invoked, then
# we're gold.
xmpf
self.assertTrue(True)

def test_init_del(self):
xmpfile = XMPFiles()
Expand Down

0 comments on commit 82d15dd

Please sign in to comment.