Browse code

Fixes #847 - set a few str as unicode to fix UnicodeDecodeError with python2 when doing a sync remote 2 remote

Florent Viard authored on 2020/03/29 10:45:52
Showing 1 changed files
... ...
@@ -685,7 +685,7 @@ def subcmd_batch_del_iterative(uri_str = None, bucket = None):
685 685
             response = s3.object_batch_delete_uri_strs([uri.compose_uri(bucket, item['Key']) for item in to_delete])
686 686
         deleted_bytes += sum(int(item["Size"]) for item in to_delete)
687 687
         deleted_count += len(to_delete)
688
-        output('\n'.join(u"delete: '%s'" % uri.compose_uri(bucket, p['Key']) for p in to_delete))
688
+        output(u'\n'.join(u"delete: '%s'" % uri.compose_uri(bucket, p['Key']) for p in to_delete))
689 689
 
690 690
     if deleted_count:
691 691
         # display summary data of deleted files
... ...
@@ -717,7 +717,7 @@ def subcmd_batch_del(uri_str = None, bucket = None, remote_list = None):
717 717
             debug(u"Batch delete %d, remaining %d" % (len(to_delete), len(remote_list)))
718 718
             if not cfg.dry_run:
719 719
                 response = s3.object_batch_delete(to_delete)
720
-            output('\n'.join((u"delete: '%s'" % to_delete[p]['object_uri_str']) for p in to_delete))
720
+            output(u'\n'.join((u"delete: '%s'" % to_delete[p]['object_uri_str']) for p in to_delete))
721 721
             to_delete = remote_list[:1000]
722 722
             remote_list = remote_list[1000:]
723 723
 
... ...
@@ -1113,12 +1113,12 @@ def cmd_sync_remote2remote(args):
1113 1113
             extra_headers = copy(cfg.extra_headers)
1114 1114
             try:
1115 1115
                 response = s3.object_copy(src_uri, dst_uri, extra_headers)
1116
-                output("remote copy: '%(src)s' -> '%(dst)s'" % { "src" : src_uri, "dst" : dst_uri })
1116
+                output(u"remote copy: '%s' -> '%s'" % (src_uri, dst_uri))
1117 1117
                 total_nb_files += 1
1118 1118
                 total_size += item.get(u'size', 0)
1119
-            except S3Error as e:
1119
+            except S3Error as exc:
1120 1120
                 ret = EX_PARTIAL
1121
-                error("File '%(src)s' could not be copied: %(e)s" % { "src" : src_uri, "e" : e })
1121
+                error(u"File '%s' could not be copied: %s", src_uri, exc)
1122 1122
                 if cfg.stop_on_error:
1123 1123
                     raise
1124 1124
         return ret, seq, total_nb_files, total_size
... ...
@@ -2084,7 +2084,7 @@ def cmd_multipart(args):
2084 2084
     output(u"Initiated\tPath\tId")
2085 2085
     for mpupload in parseNodes(tree):
2086 2086
         try:
2087
-            output("%s\t%s\t%s" % (mpupload['Initiated'], "s3://" + uri.bucket() + "/" + mpupload['Key'], mpupload['UploadId']))
2087
+            output(u"%s\t%s\t%s" % (mpupload['Initiated'], "s3://" + uri.bucket() + "/" + mpupload['Key'], mpupload['UploadId']))
2088 2088
         except KeyError:
2089 2089
             pass
2090 2090
     return EX_OK
... ...
@@ -2113,7 +2113,7 @@ def cmd_list_multipart(args):
2113 2113
     output(u"LastModified\t\t\tPartNumber\tETag\tSize")
2114 2114
     for mpupload in parseNodes(tree):
2115 2115
         try:
2116
-            output("%s\t%s\t%s\t%s" % (mpupload['LastModified'], mpupload['PartNumber'], mpupload['ETag'], mpupload['Size']))
2116
+            output(u"%s\t%s\t%s\t%s" % (mpupload['LastModified'], mpupload['PartNumber'], mpupload['ETag'], mpupload['Size']))
2117 2117
         except:
2118 2118
             pass
2119 2119
     return EX_OK
... ...
@@ -2143,9 +2143,9 @@ def cmd_accesslog(args):
2143 2143
 
2144 2144
 def cmd_sign(args):
2145 2145
     string_to_sign = args.pop()
2146
-    debug("string-to-sign: %r" % string_to_sign)
2146
+    debug(u"string-to-sign: %r" % string_to_sign)
2147 2147
     signature = Crypto.sign_string_v2(encode_to_s3(string_to_sign))
2148
-    output("Signature: %s" % decode_from_s3(signature))
2148
+    output(u"Signature: %s" % decode_from_s3(signature))
2149 2149
     return EX_OK
2150 2150
 
2151 2151
 def cmd_signurl(args):
... ...
@@ -2214,24 +2214,24 @@ def cmd_fixbucket(args):
2214 2214
                 src = S3Uri("s3://%s/%s" % (culprit.bucket(), key_bin))
2215 2215
                 dst = S3Uri("s3://%s/%s" % (culprit.bucket(), key_new))
2216 2216
                 if cfg.dry_run:
2217
-                    output("[--dry-run] File %r would be renamed to %s" % (key_bin, key_new))
2217
+                    output(u"[--dry-run] File %r would be renamed to %s" % (key_bin, key_new))
2218 2218
                     continue
2219 2219
                 try:
2220 2220
                     resp_move = s3.object_move(src, dst)
2221 2221
                     if resp_move['status'] == 200:
2222
-                        output("File '%r' renamed to '%s'" % (key_bin, key_new))
2222
+                        output(u"File '%r' renamed to '%s'" % (key_bin, key_new))
2223 2223
                         count += 1
2224 2224
                     else:
2225
-                        error("Something went wrong for: %r" % key)
2226
-                        error("Please report the problem to s3tools-bugs@lists.sourceforge.net")
2225
+                        error(u"Something went wrong for: %r" % key)
2226
+                        error(u"Please report the problem to s3tools-bugs@lists.sourceforge.net")
2227 2227
                 except S3Error:
2228
-                    error("Something went wrong for: %r" % key)
2229
-                    error("Please report the problem to s3tools-bugs@lists.sourceforge.net")
2228
+                    error(u"Something went wrong for: %r" % key)
2229
+                    error(u"Please report the problem to s3tools-bugs@lists.sourceforge.net")
2230 2230
 
2231 2231
     if count > 0:
2232
-        warning("Fixed %d files' names. Their ACL were reset to Private." % count)
2233
-        warning("Use 's3cmd setacl --acl-public s3://...' to make")
2234
-        warning("them publicly readable if required.")
2232
+        warning(u"Fixed %d files' names. Their ACL were reset to Private." % count)
2233
+        warning(u"Use 's3cmd setacl --acl-public s3://...' to make")
2234
+        warning(u"them publicly readable if required.")
2235 2235
     return EX_OK
2236 2236
 
2237 2237
 def resolve_list(lst, args):
... ...
@@ -2241,14 +2241,14 @@ def resolve_list(lst, args):
2241 2241
     return retval
2242 2242
 
2243 2243
 def gpg_command(command, passphrase = ""):
2244
-    debug("GPG command: " + " ".join(command))
2244
+    debug(u"GPG command: " + " ".join(command))
2245 2245
     command = [deunicodise(cmd_entry) for cmd_entry in command]
2246 2246
     p = subprocess.Popen(command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
2247 2247
                          close_fds = True)
2248 2248
     p_stdout, p_stderr = p.communicate(deunicodise(passphrase + "\n"))
2249
-    debug("GPG output:")
2249
+    debug(u"GPG output:")
2250 2250
     for line in unicodise(p_stdout).split("\n"):
2251
-        debug("GPG: " + line)
2251
+        debug(u"GPG: " + line)
2252 2252
     p_exitcode = p.wait()
2253 2253
     return p_exitcode
2254 2254
 
... ...
@@ -2397,7 +2397,7 @@ def run_configure(config_file, args):
2397 2397
                         os.unlink(deunicodise(ret_enc[1]))
2398 2398
                         os.unlink(deunicodise(ret_dec[1]))
2399 2399
                         if hash[0] == hash[2] and hash[0] != hash[1]:
2400
-                            output ("Success. Encryption and decryption worked fine :-)")
2400
+                            output(u"Success. Encryption and decryption worked fine :-)")
2401 2401
                         else:
2402 2402
                             raise Exception("Encryption verification error.")
2403 2403