File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -236,9 +236,12 @@ def expanduser(path):
236
236
if 'HOME' not in os .environ :
237
237
try :
238
238
import pwd
239
- userhome = pwd .getpwuid (os .getuid ()).pw_dir
240
- except (ImportError , KeyError ):
239
+ except ImportError :
241
240
# pwd module unavailable, return path unchanged
241
+ return path
242
+ try :
243
+ userhome = pwd .getpwuid (os .getuid ()).pw_dir
244
+ except KeyError :
242
245
# bpo-10496: if the current user identifier doesn't exist in the
243
246
# password database, return the path unchanged
244
247
return path
@@ -247,12 +250,15 @@ def expanduser(path):
247
250
else :
248
251
try :
249
252
import pwd
250
- name = path [1 :i ]
251
- if isinstance (name , bytes ):
252
- name = name .decode ('ascii' )
253
- userhome = pwd .getpwnam (name ).pw_dir
254
- except (ImportError , KeyError ):
253
+ except ImportError :
255
254
# pwd module unavailable, return path unchanged
255
+ return path
256
+ name = path [1 :i ]
257
+ if isinstance (name , bytes ):
258
+ name = name .decode ('ascii' )
259
+ try :
260
+ userhome = pwd .getpwnam (name ).pw_dir
261
+ except KeyError :
256
262
# bpo-10496: if the user name from the path doesn't exist in the
257
263
# password database, return the path unchanged
258
264
return path
You can’t perform that action at this time.
0 commit comments