Browse code

Fixes #1113 - Fixes report_exception wrong error when LANG env var was not set

Florent Viard authored on 2020/06/21 23:01:27
Showing 3 changed files
... ...
@@ -89,12 +89,14 @@ else:
89 89
 
90 90
 config_file = None
91 91
 if os.getenv("HOME"):
92
-    config_file = os.path.join(unicodise(os.getenv("HOME"), encoding), ".s3cfg")
92
+    config_file = os.path.join(unicodise(os.getenv("HOME"), encoding),
93
+                               ".s3cfg")
93 94
 elif os.name == "nt" and os.getenv("USERPROFILE"):
94
-    config_file = os.path.join(unicodise(os.getenv("USERPROFILE"), encoding),
95
-                               os.getenv("APPDATA") and unicodise(os.getenv("APPDATA"), encoding)
96
-                               or 'Application Data',
97
-                               "s3cmd.ini")
95
+    config_file = os.path.join(
96
+        unicodise(os.getenv("USERPROFILE"), encoding),
97
+        os.getenv("APPDATA") and unicodise(os.getenv("APPDATA"), encoding)
98
+        or 'Application Data',
99
+        "s3cmd.ini")
98 100
 
99 101
 
100 102
 ## Unpack testsuite/ directory
... ...
@@ -89,12 +89,14 @@ else:
89 89
 
90 90
 config_file = None
91 91
 if os.getenv("HOME"):
92
-    config_file = os.path.join(unicodise(os.getenv("HOME"), encoding), ".s3cfg")
92
+    config_file = os.path.join(unicodise(os.getenv("HOME"), encoding),
93
+                               ".s3cfg")
93 94
 elif os.name == "nt" and os.getenv("USERPROFILE"):
94
-    config_file = os.path.join(unicodise(os.getenv("USERPROFILE"), encoding),
95
-                               os.getenv("APPDATA") and unicodise(os.getenv("APPDATA"), encoding)
96
-                               or 'Application Data',
97
-                               "s3cmd.ini")
95
+    config_file = os.path.join(
96
+        unicodise(os.getenv("USERPROFILE"), encoding),
97
+        os.getenv("APPDATA") and unicodise(os.getenv("APPDATA"), encoding)
98
+        or 'Application Data',
99
+        "s3cmd.ini")
98 100
 
99 101
 
100 102
 ## Unpack testsuite/ directory
... ...
@@ -2692,12 +2692,15 @@ def main():
2692 2692
 
2693 2693
     config_file = None
2694 2694
     if os.getenv("S3CMD_CONFIG"):
2695
-        config_file = unicodise_s(os.getenv("S3CMD_CONFIG"), autodetected_encoding)
2695
+        config_file = unicodise_s(os.getenv("S3CMD_CONFIG"),
2696
+                                  autodetected_encoding)
2696 2697
     elif os.name == "nt" and os.getenv("USERPROFILE"):
2697
-        config_file = os.path.join(unicodise_s(os.getenv("USERPROFILE"), autodetected_encoding),
2698
-                                   os.getenv("APPDATA") and unicodise_s(os.getenv("APPDATA"), autodetected_encoding)
2699
-                                   or 'Application Data',
2700
-                                   "s3cmd.ini")
2698
+        config_file = os.path.join(
2699
+            unicodise_s(os.getenv("USERPROFILE"), autodetected_encoding),
2700
+            os.getenv("APPDATA")
2701
+               and unicodise_s(os.getenv("APPDATA"), autodetected_encoding)
2702
+               or 'Application Data',
2703
+            "s3cmd.ini")
2701 2704
     else:
2702 2705
         from os.path import expanduser
2703 2706
         config_file = os.path.join(expanduser("~"), ".s3cfg")
... ...
@@ -3100,7 +3103,8 @@ def report_exception(e, msg=u''):
3100 3100
         try:
3101 3101
             s = u' '.join([unicodise(a) for a in sys.argv])
3102 3102
         except NameError:
3103
-            # Error happened before Utils module was yet imported to provide unicodise
3103
+            # Error happened before Utils module was yet imported to provide
3104
+            # unicodise
3104 3105
             try:
3105 3106
                 s = u' '.join([(a) for a in sys.argv])
3106 3107
             except UnicodeDecodeError:
... ...
@@ -3112,16 +3116,23 @@ def report_exception(e, msg=u''):
3112 3112
         try:
3113 3113
             sys.stderr.write(u"Problem: %s: %s\n" % (e_class, e))
3114 3114
         except UnicodeDecodeError:
3115
-            sys.stderr.write(u"Problem: [encoding safe] %r: %r\n" % (e_class, e))
3115
+            sys.stderr.write(u"Problem: [encoding safe] %r: %r\n"
3116
+                             % (e_class, e))
3116 3117
         try:
3117 3118
             sys.stderr.write(u"S3cmd:   %s\n" % PkgInfo.version)
3118 3119
         except NameError:
3119
-            sys.stderr.write(u"S3cmd:   unknown version. Module import problem?\n")
3120
+            sys.stderr.write(u"S3cmd:   unknown version."
3121
+                             "Module import problem?\n")
3120 3122
         sys.stderr.write(u"python:   %s\n" % sys.version)
3121 3123
         try:
3122
-            sys.stderr.write(u"environment LANG=%s\n" % unicodise_s(os.getenv("LANG"), 'ascii'))
3124
+            sys.stderr.write(u"environment LANG=%s\n"
3125
+                             % unicodise_s(os.getenv("LANG", "NOTSET"),
3126
+                                           'ascii'))
3123 3127
         except NameError:
3124
-            sys.stderr.write(u"environment LANG=%s\n" % os.getenv("LANG"))
3128
+            # Error happened before Utils module was yet imported to provide
3129
+            # unicodise
3130
+            sys.stderr.write(u"environment LANG=%s\n"
3131
+                             % os.getenv("LANG", "NOTSET"))
3125 3132
         sys.stderr.write(u"\n")
3126 3133
         if type(tb) == unicode:
3127 3134
             sys.stderr.write(tb)
... ...
@@ -3133,7 +3144,8 @@ def report_exception(e, msg=u''):
3133 3133
             sys.stderr.write("Your sys.path contains these entries:\n")
3134 3134
             for path in sys.path:
3135 3135
                 sys.stderr.write(u"\t%s\n" % path)
3136
-            sys.stderr.write("Now the question is where have the s3cmd modules been installed?\n")
3136
+            sys.stderr.write("Now the question is where have the s3cmd modules"
3137
+                             " been installed?\n")
3137 3138
 
3138 3139
         sys.stderr.write(alert_header % (u"above lines", u""))
3139 3140
 
... ...
@@ -3233,7 +3245,7 @@ The solutions to this are:
3233 3233
         sys.exit(EX_OSERR)
3234 3234
 
3235 3235
     except UnicodeEncodeError as e:
3236
-        lang = unicodise_s(os.getenv("LANG"), 'ascii')
3236
+        lang = unicodise_s(os.getenv("LANG", "NOTSET"), 'ascii')
3237 3237
         msg = """
3238 3238
 You have encountered a UnicodeEncodeError.  Your environment
3239 3239
 variable LANG=%s may not specify a Unicode encoding (e.g. UTF-8).