From 9d85dcdf11d3229625d1860a13db44d8d450347c Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Mon, 17 Nov 2014 07:11:44 +0200 Subject: [PATCH] Fix unicode handling in "gmg addmedia". --- mediagoblin/db/models.py | 6 +++++- mediagoblin/gmg_commands/addmedia.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 12757eda..8f722cff 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -489,7 +489,11 @@ class MediaEntry(Base, MediaEntryMixin): return import_component(self.media_type + '.models:BACKREF_NAME') def __repr__(self): - safe_title = self.title.encode('ascii', 'replace') + if six.PY2: + # obj.__repr__() should return a str on Python 2 + safe_title = self.title.encode('utf-8', 'replace') + else: + safe_title = self.title return '<{classname} {id}: {title}>'.format( classname=self.__class__.__name__, diff --git a/mediagoblin/gmg_commands/addmedia.py b/mediagoblin/gmg_commands/addmedia.py index b741b96f..2aa8f96a 100644 --- a/mediagoblin/gmg_commands/addmedia.py +++ b/mediagoblin/gmg_commands/addmedia.py @@ -88,14 +88,15 @@ def addmedia(args): # this is kinda terrible if some_string is None: return None - else: - return six.text_type(some_string) + if six.PY2: + return six.text_type(some_string, 'utf-8') + return some_string try: submit_media( mg_app=app, user=user, - submitted_file=open(abs_filename, 'r'), filename=filename, + submitted_file=open(abs_filename, 'rb'), filename=filename, title=maybe_unicodeify(args.title), description=maybe_unicodeify(args.description), license=maybe_unicodeify(args.license), -- 2.25.1