Provides the errno from an Exception object. There are cases that the errno attribute was not set so we pull the errno out of the args but if someone instantiates an Exception without any args you will get a tuple error. So this function abstracts all that behavior to give you a saf
(e: BaseException)
| 159 | |
| 160 | |
| 161 | def errno_from_exception(e: BaseException) -> Optional[int]: |
| 162 | """Provides the errno from an Exception object. |
| 163 | |
| 164 | There are cases that the errno attribute was not set so we pull |
| 165 | the errno out of the args but if someone instantiates an Exception |
| 166 | without any args you will get a tuple error. So this function |
| 167 | abstracts all that behavior to give you a safe way to get the |
| 168 | errno. |
| 169 | """ |
| 170 | |
| 171 | if hasattr(e, "errno"): |
| 172 | return e.errno # type: ignore |
| 173 | elif e.args: |
| 174 | return e.args[0] |
| 175 | else: |
| 176 | return None |
| 177 | |
| 178 | |
| 179 | _alphanum = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") |
no outgoing calls
no test coverage detected