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 instatiates an Exception without any args you will get a tuple error. So this function abstracts all that behavior to give you a safe
(e)
| 228 | |
| 229 | # from tornado |
| 230 | def errno_from_exception(e): |
| 231 | """Provides the errno from an Exception object. |
| 232 | |
| 233 | There are cases that the errno attribute was not set so we pull |
| 234 | the errno out of the args but if someone instatiates an Exception |
| 235 | without any args you will get a tuple error. So this function |
| 236 | abstracts all that behavior to give you a safe way to get the |
| 237 | errno. |
| 238 | """ |
| 239 | |
| 240 | if hasattr(e, 'errno'): |
| 241 | return e.errno |
| 242 | elif e.args: |
| 243 | return e.args[0] |
| 244 | else: |
| 245 | return None |
| 246 | |
| 247 | |
| 248 | # from tornado |