Safemotion Lib
Loading...
Searching...
No Matches
Protected Member Functions | Static Protected Attributes | List of all members
fastreid.utils.file_io.PathHandler Class Reference
Inheritance diagram for fastreid.utils.file_io.PathHandler:
fastreid.utils.file_io.NativePathHandler

Protected Member Functions

None _check_kwargs (self, Dict[str, Any] kwargs)
 
List[str] _get_supported_prefixes (self)
 
str _get_local_path (self, str path, **Any kwargs)
 
Union[IO[str], IO[bytes]] _open (self, str path, str mode="r", int buffering=-1, **Any kwargs)
 
bool _copy (self, str src_path, str dst_path, bool overwrite=False, **Any kwargs)
 
bool _exists (self, str path, **Any kwargs)
 
bool _isfile (self, str path, **Any kwargs)
 
bool _isdir (self, str path, **Any kwargs)
 
List[str] _ls (self, str path, **Any kwargs)
 
None _mkdirs (self, str path, **Any kwargs)
 
None _rm (self, str path, **Any kwargs)
 

Static Protected Attributes

bool _strict_kwargs_check = True
 

Detailed Description

PathHandler is a base class that defines common I/O functionality for a URI
protocol. It routes I/O for a generic URI which may look like "protocol://*"
or a canonical filepath "/foo/bar/baz".

Definition at line 40 of file file_io.py.

Member Function Documentation

◆ _check_kwargs()

None fastreid.utils.file_io.PathHandler._check_kwargs ( self,
Dict[str, Any] kwargs )
protected
Checks if the given arguments are empty. Throws a ValueError if strict
kwargs checking is enabled and args are non-empty. If strict kwargs
checking is disabled, only a warning is logged.
Args:
    kwargs (Dict[str, Any])

Definition at line 49 of file file_io.py.

49 def _check_kwargs(self, kwargs: Dict[str, Any]) -> None:
50 """
51 Checks if the given arguments are empty. Throws a ValueError if strict
52 kwargs checking is enabled and args are non-empty. If strict kwargs
53 checking is disabled, only a warning is logged.
54 Args:
55 kwargs (Dict[str, Any])
56 """
57 if self._strict_kwargs_check:
58 if len(kwargs) > 0:
59 raise ValueError("Unused arguments: {}".format(kwargs))
60 else:
61 logger = logging.getLogger(__name__)
62 for k, v in kwargs.items():
63 logger.warning(
64 "[PathManager] {}={} argument ignored".format(k, v)
65 )
66

◆ _copy()

bool fastreid.utils.file_io.PathHandler._copy ( self,
str src_path,
str dst_path,
bool overwrite = False,
**Any kwargs )
protected
Copies a source path to a destination path.
Args:
    src_path (str): A URI supported by this PathHandler
    dst_path (str): A URI supported by this PathHandler
    overwrite (bool): Bool flag for forcing overwrite of existing file
Returns:
    status (bool): True on success

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 107 of file file_io.py.

113 ) -> bool:
114 """
115 Copies a source path to a destination path.
116 Args:
117 src_path (str): A URI supported by this PathHandler
118 dst_path (str): A URI supported by this PathHandler
119 overwrite (bool): Bool flag for forcing overwrite of existing file
120 Returns:
121 status (bool): True on success
122 """
123 raise NotImplementedError()
124

◆ _exists()

bool fastreid.utils.file_io.PathHandler._exists ( self,
str path,
**Any kwargs )
protected
Checks if there is a resource at the given URI.
Args:
    path (str): A URI supported by this PathHandler
Returns:
    bool: true if the path exists

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 125 of file file_io.py.

125 def _exists(self, path: str, **kwargs: Any) -> bool:
126 """
127 Checks if there is a resource at the given URI.
128 Args:
129 path (str): A URI supported by this PathHandler
130 Returns:
131 bool: true if the path exists
132 """
133 raise NotImplementedError()
134

◆ _get_local_path()

str fastreid.utils.file_io.PathHandler._get_local_path ( self,
str path,
**Any kwargs )
protected
Get a filepath which is compatible with native Python I/O such as `open`
and `os.path`.
If URI points to a remote resource, this function may download and cache
the resource to local disk. In this case, this function is meant to be
used with read-only resources.
Args:
    path (str): A URI supported by this PathHandler
Returns:
    local_path (str): a file path which exists on the local file system

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 74 of file file_io.py.

74 def _get_local_path(self, path: str, **kwargs: Any) -> str:
75 """
76 Get a filepath which is compatible with native Python I/O such as `open`
77 and `os.path`.
78 If URI points to a remote resource, this function may download and cache
79 the resource to local disk. In this case, this function is meant to be
80 used with read-only resources.
81 Args:
82 path (str): A URI supported by this PathHandler
83 Returns:
84 local_path (str): a file path which exists on the local file system
85 """
86 raise NotImplementedError()
87

◆ _get_supported_prefixes()

List[str] fastreid.utils.file_io.PathHandler._get_supported_prefixes ( self)
protected
Returns:
    List[str]: the list of URI prefixes this PathHandler can support

Definition at line 67 of file file_io.py.

67 def _get_supported_prefixes(self) -> List[str]:
68 """
69 Returns:
70 List[str]: the list of URI prefixes this PathHandler can support
71 """
72 raise NotImplementedError()
73

◆ _isdir()

bool fastreid.utils.file_io.PathHandler._isdir ( self,
str path,
**Any kwargs )
protected
Checks if the resource at the given URI is a directory.
Args:
    path (str): A URI supported by this PathHandler
Returns:
    bool: true if the path is a directory

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 145 of file file_io.py.

145 def _isdir(self, path: str, **kwargs: Any) -> bool:
146 """
147 Checks if the resource at the given URI is a directory.
148 Args:
149 path (str): A URI supported by this PathHandler
150 Returns:
151 bool: true if the path is a directory
152 """
153 raise NotImplementedError()
154

◆ _isfile()

bool fastreid.utils.file_io.PathHandler._isfile ( self,
str path,
**Any kwargs )
protected
Checks if the resource at the given URI is a file.
Args:
    path (str): A URI supported by this PathHandler
Returns:
    bool: true if the path is a file

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 135 of file file_io.py.

135 def _isfile(self, path: str, **kwargs: Any) -> bool:
136 """
137 Checks if the resource at the given URI is a file.
138 Args:
139 path (str): A URI supported by this PathHandler
140 Returns:
141 bool: true if the path is a file
142 """
143 raise NotImplementedError()
144

◆ _ls()

List[str] fastreid.utils.file_io.PathHandler._ls ( self,
str path,
**Any kwargs )
protected
List the contents of the directory at the provided URI.
Args:
    path (str): A URI supported by this PathHandler
Returns:
    List[str]: list of contents in given path

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 155 of file file_io.py.

155 def _ls(self, path: str, **kwargs: Any) -> List[str]:
156 """
157 List the contents of the directory at the provided URI.
158 Args:
159 path (str): A URI supported by this PathHandler
160 Returns:
161 List[str]: list of contents in given path
162 """
163 raise NotImplementedError()
164

◆ _mkdirs()

None fastreid.utils.file_io.PathHandler._mkdirs ( self,
str path,
**Any kwargs )
protected
Recursive directory creation function. Like mkdir(), but makes all
intermediate-level directories needed to contain the leaf directory.
Similar to the native `os.makedirs`.
Args:
    path (str): A URI supported by this PathHandler

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 165 of file file_io.py.

165 def _mkdirs(self, path: str, **kwargs: Any) -> None:
166 """
167 Recursive directory creation function. Like mkdir(), but makes all
168 intermediate-level directories needed to contain the leaf directory.
169 Similar to the native `os.makedirs`.
170 Args:
171 path (str): A URI supported by this PathHandler
172 """
173 raise NotImplementedError()
174

◆ _open()

Union[IO[str], IO[bytes]] fastreid.utils.file_io.PathHandler._open ( self,
str path,
str mode = "r",
int buffering = -1,
**Any kwargs )
protected
Open a stream to a URI, similar to the built-in `open`.
Args:
    path (str): A URI supported by this PathHandler
    mode (str): Specifies the mode in which the file is opened. It defaults
        to 'r'.
    buffering (int): An optional integer used to set the buffering policy.
        Pass 0 to switch buffering off and an integer >= 1 to indicate the
        size in bytes of a fixed-size chunk buffer. When no buffering
        argument is given, the default buffering policy depends on the
        underlying I/O implementation.
Returns:
    file: a file-like object.

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 88 of file file_io.py.

90 ) -> Union[IO[str], IO[bytes]]:
91 """
92 Open a stream to a URI, similar to the built-in `open`.
93 Args:
94 path (str): A URI supported by this PathHandler
95 mode (str): Specifies the mode in which the file is opened. It defaults
96 to 'r'.
97 buffering (int): An optional integer used to set the buffering policy.
98 Pass 0 to switch buffering off and an integer >= 1 to indicate the
99 size in bytes of a fixed-size chunk buffer. When no buffering
100 argument is given, the default buffering policy depends on the
101 underlying I/O implementation.
102 Returns:
103 file: a file-like object.
104 """
105 raise NotImplementedError()
106

◆ _rm()

None fastreid.utils.file_io.PathHandler._rm ( self,
str path,
**Any kwargs )
protected
Remove the file (not directory) at the provided URI.
Args:
    path (str): A URI supported by this PathHandler

Reimplemented in fastreid.utils.file_io.NativePathHandler.

Definition at line 175 of file file_io.py.

175 def _rm(self, path: str, **kwargs: Any) -> None:
176 """
177 Remove the file (not directory) at the provided URI.
178 Args:
179 path (str): A URI supported by this PathHandler
180 """
181 raise NotImplementedError()
182
183

Member Data Documentation

◆ _strict_kwargs_check

bool fastreid.utils.file_io.PathHandler._strict_kwargs_check = True
staticprotected

Definition at line 47 of file file_io.py.


The documentation for this class was generated from the following file: