| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent dded882 commit e97c807
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,7 @@ | |||
| 52 | 52 | ||
| 53 | 53 | # Exceptions | |
| 54 | 54 | try: | |
| 55 | - BlockingOSError = builtins.BlockingOSError | ||
| 55 | + BlockingIOError = builtins.BlockingIOError | ||
| 56 | 56 | BrokenPipeError = builtins.BrokenPipeError | |
| 57 | 57 | ChildProcessError = builtins.ChildProcessError | |
| 58 | 58 | ConnectionError = builtins.ConnectionError | |
@@ -68,10 +68,10 @@ | |||
| 68 | 68 | ProcessLookupError = builtins.ProcessLookupError | |
| 69 | 69 | TimeoutError = builtins.TimeoutError | |
| 70 | 70 | except NameError: | |
| 71 | - from future.types.exceptions import * | ||
| 71 | + from future.types.exceptions.pep3151 import * | ||
| 72 | 72 | import future.types.exceptions as fte | |
| 73 | 73 | __all__ += [ | |
| 74 | - 'BlockingOSError', | ||
| 74 | + 'BlockingIOError', | ||
| 75 | 75 | 'BrokenPipeError', | |
| 76 | 76 | 'ChildProcessError', | |
| 77 | 77 | 'ConnectionError', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,28 +1,2 @@ | |||
| 1 | - """ | ||
| 2 | - Exception matching patchwork. | ||
| 3 | - | ||
| 4 | - Libraries are not as fine-grained with exception classes as one would like. By | ||
| 5 | - using exhacktion, you can make create your own exceptions which behave as if | ||
| 6 | - they are superclasses of the ones raised by the library. | ||
| 7 | - | ||
| 8 | - Tread with caution. | ||
| 9 | - """ | ||
| 10 | - | ||
| 11 | 1 | from .pep3151 import * | |
| 12 | - __all__ = [ | ||
| 13 | - 'BlockingOSError', | ||
| 14 | - 'BrokenPipeError', | ||
| 15 | - 'ChildProcessError', | ||
| 16 | - 'ConnectionError', | ||
| 17 | - 'ConnectionAbortedError', | ||
| 18 | - 'ConnectionRefusedError', | ||
| 19 | - 'ConnectionResetError', | ||
| 20 | - 'FileExistsError', | ||
| 21 | - 'FileNotFoundError', | ||
| 22 | - 'InterruptedError', | ||
| 23 | - 'IsADirectoryError', | ||
| 24 | - 'NotADirectoryError', | ||
| 25 | - 'PermissionError', | ||
| 26 | - 'ProcessLookupError', | ||
| 27 | - 'TimeoutError', | ||
| 28 | - ] | ||
| 2 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,10 @@ | |||
| 1 | 1 | """ | |
| 2 | + Libraries are not as fine-grained with exception classes as one would like. By | ||
| 3 | + using this hack, you can make create your own exceptions which behave as if | ||
| 4 | + they are superclasses of the ones raised by the standard library. | ||
| 5 | + | ||
| 6 | + Tread with caution. | ||
| 7 | + | ||
| 2 | 8 | Defines the base `instance_checking_exception` creator. | |
| 3 | 9 | """ | |
| 4 | 10 | ||
@@ -37,19 +43,7 @@ def wrapped(instance_checker): | |||
| 37 | 43 | handling logic. | |
| 38 | 44 | """ | |
| 39 | 45 | class TemporaryClass(base_exception): | |
| 40 | - # def __new__(cls, *args): | ||
| 41 | - # print('TemporaryClass.__new__: args are: {0}'.format(args)) | ||
| 42 | - # if len(args) == 1 and isinstance(args[0], TemporaryClass): | ||
| 43 | - # unwrap_me = args[0] | ||
| 44 | - # err = super(TemporaryClass, cls).__new__(cls) | ||
| 45 | - # for attr in dir(unwrap_me): | ||
| 46 | - # if not attr.startswith('__'): | ||
| 47 | - # setattr(err, attr, getattr(unwrap_me, attr)) | ||
| 48 | - # else: | ||
| 49 | - # return super(base_exception, cls).__new__(cls, *args) | ||
| 50 | - | ||
| 51 | 46 | def __init__(self, *args, **kwargs): | |
| 52 | - # print('TemporaryClass.__init__: args are: {0}'.format(args)) | ||
| 53 | 47 | if len(args) == 1 and isinstance(args[0], TemporaryClass): | |
| 54 | 48 | unwrap_me = args[0] | |
| 55 | 49 | for attr in dir(unwrap_me): | |
@@ -60,35 +54,13 @@ def __init__(self, *args, **kwargs): | |||
| 60 | 54 | ||
| 61 | 55 | class __metaclass__(type): | |
| 62 | 56 | def __instancecheck__(cls, inst): | |
| 63 | - # print('FileNotFoundError.__isinstance__: type(inst) = {0}\ninst = {1}'.format(type(inst), inst)) | ||
| 64 | 57 | return instance_checker(inst) | |
| 65 | 58 | ||
| 66 | 59 | def __subclasscheck__(cls, classinfo): | |
| 67 | - # print('In __subclasscheck__:\n\tcls = {0}\n\tclassinfo = {1}'.format(cls, classinfo)) | ||
| 68 | - # return instance_checker(classinfo) | ||
| 69 | - # This hook is called during the exception handling. | ||
| 70 | - # Unfortunately, we would rather have exception handling call | ||
| 71 | - # __instancecheck__, so we have to do that ourselves. But, | ||
| 72 | - # that's not how it currently is. If you feel like proposing a | ||
| 73 | - # patch for Python, check the function | ||
| 74 | - # `PyErr_GivenExceptionMatches` in `Python/error.c`. | ||
| 75 | 60 | value = sys.exc_info()[1] | |
| 76 | - # if value is None: | ||
| 77 | - # print('Exception value is None!!') | ||
| 78 | - | ||
| 79 | - # Double-check that the exception given actually somewhat | ||
| 80 | - # matches the classinfo we received. If not, people may be using | ||
| 81 | - # `issubclass` directly, which is of course prone to errors, | ||
| 82 | - # or they are raising the exception with `raise ...` | ||
| 83 | - # if value.__class__ != classinfo: | ||
| 84 | - # print('Mismatch!\nvalue: {0}\nvalue.__class__: {1}\nclassinfo: {2}'.format( | ||
| 85 | - # value, value.__class__, classinfo) | ||
| 86 | - # ) | ||
| 87 | 61 | return isinstance(value, cls) | |
| 88 | 62 | ||
| 89 | 63 | TemporaryClass.__name__ = instance_checker.__name__ | |
| 90 | 64 | TemporaryClass.__doc__ = instance_checker.__doc__ | |
| 91 | 65 | return TemporaryClass | |
| 92 | 66 | return wrapped | |
| 93 | - | ||
| 94 | - | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,8 @@ | |||
| 3 | 3 | a lot of under-the-hood magic to make it look like the standard library is | |
| 4 | 4 | actually throwing these more specific versions instead of just OSError, OSError | |
| 5 | 5 | and such. | |
| 6 | + | ||
| 7 | + Based on https://github.com/sjoerdjob/exhacktion. | ||
| 6 | 8 | """ | |
| 7 | 9 | ||
| 8 | 10 | import errno | |
@@ -11,7 +13,7 @@ | |||
| 11 | 13 | ||
| 12 | 14 | ||
| 13 | 15 | @instance_checking_exception(OSError) | |
| 14 | - def BlockingOSError(inst): | ||
| 16 | + def BlockingIOError(inst): | ||
| 15 | 17 | """I/O operation would block.""" | |
| 16 | 18 | errnos = [errno.EAGAIN, errno.EALREADY, errno.EWOULDBLOCK, | |
| 17 | 19 | errno.EINPROGRESS] | |
@@ -106,7 +108,7 @@ def TimeoutError(inst): | |||
| 106 | 108 | return hasattr(inst, 'errno') and inst.errno == errno.ETIMEDOUT | |
| 107 | 109 | ||
| 108 | 110 | __all__ = [ | |
| 109 | - 'BlockingOSError', | ||
| 111 | + 'BlockingIOError', | ||
| 110 | 112 | 'BrokenPipeError', | |
| 111 | 113 | 'ChildProcessError', | |
| 112 | 114 | 'ConnectionError', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments