Fix unicode handling in "gmg addmedia".
authorBerker Peksag <berker.peksag@gmail.com>
Mon, 17 Nov 2014 05:11:44 +0000 (07:11 +0200)
committerMatt Molyneaux <moggers87+git@moggers87.co.uk>
Sat, 22 Nov 2014 18:12:19 +0000 (18:12 +0000)
mediagoblin/db/models.py
mediagoblin/gmg_commands/addmedia.py

index 12757eda5fbe0c09b9131ec82d3c3fe1c85beea9..8f722cff456bb420951637b55d97b1cd90c7dc97 100644 (file)
@@ -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__,
index b741b96f9a3080e9dbf8238ba779e52721a0e810..2aa8f96a6fa100b6d747a1a4ac74b2595d6c93f7 100644 (file)
@@ -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),