@@ -492,7 +492,7 @@ def listdir(self, path):
492492 if name :
493493 _directory .append (name )
494494
495- if not _directory :
495+ if self . strict and not _directory :
496496 if not self .getinfo (_path ).is_dir :
497497 raise errors .DirectoryExpected (path )
498498
@@ -503,7 +503,7 @@ def makedir(self, path, permissions=None, recreate=False):
503503 _path = self .validatepath (path )
504504 _key = self ._path_to_dir_key (_path )
505505
506- if not self .isdir (dirname (_path )):
506+ if self . strict and not self .isdir (dirname (_path )):
507507 raise errors .ResourceNotFound (path )
508508
509509 try :
@@ -543,23 +543,24 @@ def on_close_create(s3file):
543543 finally :
544544 s3file .raw .close ()
545545
546- try :
547- dir_path = dirname (_path )
548- if dir_path != "/" :
549- _dir_key = self ._path_to_dir_key (dir_path )
550- self ._get_object (dir_path , _dir_key )
551- except errors .ResourceNotFound :
552- raise errors .ResourceNotFound (path )
546+ if self .strict :
547+ try :
548+ dir_path = dirname (_path )
549+ if dir_path != "/" :
550+ _dir_key = self ._path_to_dir_key (dir_path )
551+ self ._get_object (dir_path , _dir_key )
552+ except errors .ResourceNotFound :
553+ raise errors .ResourceNotFound (path )
553554
554- try :
555- info = self ._getinfo (path )
556- except errors .ResourceNotFound :
557- pass
558- else :
559- if _mode .exclusive :
560- raise errors .FileExists (path )
561- if info .is_dir :
562- raise errors .FileExpected (path )
555+ try :
556+ info = self ._getinfo (path )
557+ except errors .ResourceNotFound :
558+ pass
559+ else :
560+ if _mode .exclusive :
561+ raise errors .FileExists (path )
562+ if info .is_dir :
563+ raise errors .FileExpected (path )
563564
564565 s3file = S3File .factory (path , _mode , on_close = on_close_create )
565566 if _mode .appending :
@@ -692,9 +693,10 @@ def scandir(self, path, namespaces=None, page=None):
692693 _s3_key = self ._path_to_dir_key (_path )
693694 prefix_len = len (_s3_key )
694695
695- info = self .getinfo (path )
696- if not info .is_dir :
697- raise errors .DirectoryExpected (path )
696+ if self .strict :
697+ info = self .getinfo (path )
698+ if not info .is_dir :
699+ raise errors .DirectoryExpected (path )
698700
699701 paginator = self .client .get_paginator ("list_objects" )
700702 _paginate = paginator .paginate (
0 commit comments