@@ -334,11 +334,8 @@ def discard(self, key):
334334 # This overrides an inapplicable implementation in the superclass.
335335 try :
336336 self .remove (key )
337- except KeyError :
337+ except ( KeyError , FileNotFoundError ) :
338338 pass
339- except OSError as e :
340- if e .errno != errno .ENOENT :
341- raise
342339
343340 def __setitem__ (self , key , message ):
344341 """Replace the keyed message; raise KeyError if it doesn't exist."""
@@ -493,16 +490,12 @@ def _create_tmp(self):
493490 path = os .path .join (self ._path , 'tmp' , uniq )
494491 try :
495492 os .stat (path )
496- except OSError as e :
497- if e .errno == errno .ENOENT :
498- Maildir ._count += 1
499- try :
500- return _create_carefully (path )
501- except OSError as e :
502- if e .errno != errno .EEXIST :
503- raise
504- else :
505- raise
493+ except FileNotFoundError :
494+ Maildir ._count += 1
495+ try :
496+ return _create_carefully (path )
497+ except FileExistsError :
498+ pass
506499
507500 # Fall through to here if stat succeeded or open raised EEXIST.
508501 raise ExternalClashError ('Name clash prevented file creation: %s' %
@@ -700,12 +693,9 @@ def flush(self):
700693 os .chmod (new_file .name , mode )
701694 try :
702695 os .rename (new_file .name , self ._path )
703- except OSError as e :
704- if e .errno == errno .EEXIST :
705- os .remove (self ._path )
706- os .rename (new_file .name , self ._path )
707- else :
708- raise
696+ except FileExistsError :
697+ os .remove (self ._path )
698+ os .rename (new_file .name , self ._path )
709699 self ._file = open (self ._path , 'rb+' )
710700 self ._toc = new_toc
711701 self ._pending = False
@@ -2081,13 +2071,10 @@ def _lock_file(f, dotlock=True):
20812071 else :
20822072 os .rename (pre_lock .name , f .name + '.lock' )
20832073 dotlock_done = True
2084- except OSError as e :
2085- if e .errno == errno .EEXIST :
2086- os .remove (pre_lock .name )
2087- raise ExternalClashError ('dot lock unavailable: %s' %
2088- f .name )
2089- else :
2090- raise
2074+ except FileExistsError :
2075+ os .remove (pre_lock .name )
2076+ raise ExternalClashError ('dot lock unavailable: %s' %
2077+ f .name )
20912078 except :
20922079 if fcntl :
20932080 fcntl .lockf (f , fcntl .LOCK_UN )
0 commit comments